Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Billards ball collision detection
Index -> Programming, C++ -> C++ Tutorials
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nvictor




PostPosted: Sat Apr 07, 2007 10:08 am   Post subject: Billards ball collision detection

Hello,

I want to learn more about collision detection. I found no C++ help around. Everything seems to be in Turing. What I basically want is a collision detection function for two billiard balls.

Do you have any idea? I'll also be searching on google in the meantime. thanks a lot in advance.
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Sat Apr 07, 2007 10:28 am   Post subject: RE:Billards ball collision detection

The idea isn't really to get a collision function in C++. It's to understand C++, and understand physics, and then write your own function (or, for more complicated situations, get a collision detection library).

So what exactly do you need help with?
nvictor




PostPosted: Sat Apr 07, 2007 10:41 am   Post subject: RE:Billards ball collision detection

Thanks for replying Mazer. You are right it's the physics part the problem. Not C++. Do you know any article?
Mazer




PostPosted: Sat Apr 07, 2007 10:52 am   Post subject: RE:Billards ball collision detection

If it's something like two balls, checking for a collision is pretty much as simple as seeing if the distance between their centers is less than the sum of their radii.

If you're making an actual billiards game you'll want to look into things like momentum. Not to sound like a condescending prick, but how old are you? These things are usually covered in grade 12 physics, but if you want to learn them now that's really awesome.

Unfortunately, I'm very bad at physics. Googling would be your best bet, short of someone more knowledgeable coming along.
nvictor




PostPosted: Sat Apr 07, 2007 10:56 am   Post subject: RE:Billards ball collision detection

I'm 20 and in College. I also have a question, where do you live? I have never come across momentum in my life, maybe french name it otherwise. I came from a french system. So momemtum you say?
md




PostPosted: Sat Apr 07, 2007 11:22 am   Post subject: RE:Billards ball collision detection

Also it may be worth reading the turing examples anyways. If you know C++ Turing shouldn't be that difficult to figure out, and the math is the same.

teh physics equations you really need are F = m * a and p = m * v

F == force
m == mass
a == acceleration
p == momentum
v == velocity

Incidentally everything there except mass should be a vector quantity; so you may wish to read up on them too.
nvictor




PostPosted: Sat Apr 07, 2007 11:27 am   Post subject: RE:Billards ball collision detection

From what you've written, it seems as the momentum is a sort of anti derivative of the force...
klopyrev




PostPosted: Sat Apr 07, 2007 11:31 am   Post subject: Re: Billards ball collision detection

Ah... I remember my physics unit on Collisions. You should research some things such as Elastic collision, inelastic collisions. Generally, for a billiard game, you should model a perfectly elastic collision. If I remember correctly, these are the two equations you need: m1v1 + m2v2 = m1`v1` + m2`v2` and m1v1^2 + m2v2^2 = m1`v1`^2 + m2`v2`^2. Sorry they are written in such a bad form. Just check on google and you'll find them. Also, there is a much simpler form for collisions in which v2 = 0. Good luck!!!

KL
Sponsor
Sponsor
Sponsor
sponsor
klopyrev




PostPosted: Sat Apr 07, 2007 11:32 am   Post subject: Re: Billards ball collision detection

And yes, momentum is the anti-derivative of force. F = dp/dt.

KL
nvictor




PostPosted: Sat Apr 07, 2007 12:17 pm   Post subject: RE:Billards ball collision detection

Thanks again Klopyrev. By the way all you all using Turing?
md




PostPosted: Sat Apr 07, 2007 4:02 pm   Post subject: RE:Billards ball collision detection

I am not *using* anything. I simply pointed out the proper math. As in the majority of cases the math/physics/algorithm is not at all dependent on the language you are using.

[edit] Incidentally this is the C++ help forum, so if you are looking for help with turing you really shouldn't have psoted here.
nvictor




PostPosted: Sat Apr 07, 2007 4:10 pm   Post subject: RE:Billards ball collision detection

md, you mis-read my question. sorry for that.
MihaiG




PostPosted: Sat Apr 07, 2007 5:17 pm   Post subject: Re: Billards ball collision detection

he was saying that he was looking for physics tutorials for C++ and only found them in Turing so he assumed, we all used Turing md.
If you want very simple bouncing of walls heres how i would explain it.
Motion is divided into x and y motion.
when you hit a vertical wall your x motion isnt changed only your y motion is changed so you would just multiply your y velocity by -1
something like this in pseudo code
Quote:

if collisio.ywall then
yvelocity = yvelocity *-1
end if

hmm seems this is the best i can explain it,
zylum




PostPosted: Sat Apr 07, 2007 9:46 pm   Post subject: RE:Billards ball collision detection

may i suggest my perfect circular collision detection tutorial i know the example code is in turing but i think i explain most of the math pretty well. though i haven't gotten to collision reactoin yet.
matt271




PostPosted: Wed Apr 08, 2009 2:46 pm   Post subject: RE:Billards ball collision detection

u might find this interesting

http://compsci.ca/v3/viewtopic.php?t=20679

i explained it, in what i think is a pretty simple way.
i have a code example but its in java
the code is soooooooo simple it is prob 99% the same as u would use in c++
just math and assignments
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: