Computer Science Canada circular collision |
Author: | Saad85 [ Mon Dec 26, 2005 12:39 am ] |
Post subject: | circular collision |
sorry if its come up before, but how would i go about creating a program that mimics circular collision/angular collision? |
Author: | Tony [ Mon Dec 26, 2005 2:22 am ] |
Post subject: | |
You start by reading the [Turing Tutorials], in order of Turing Walkthrough |
Author: | Albrecd [ Mon Dec 26, 2005 8:28 am ] |
Post subject: | |
Use Trig functions (sin, cosin, etc.) |
Author: | Cervantes [ Mon Dec 26, 2005 3:45 pm ] | ||
Post subject: | |||
A collision occurs between two circles if the distance between their centres is less than or equal to the sum of their radii. To determine the distance between their centres, use Math.Distance.
Math.Distance requires Turing v4.0.5 or newer. If you don't have this, you'll have to make your own distance function, which is very easy. As for the motion of the circles after collision, you should examine this source code, by thoughtful. |
Author: | Martin [ Mon Dec 26, 2005 7:22 pm ] |
Post subject: | |
BUT to make things interesting, notice that if they're moving fast enough just checking their distance apart every frame won't be good enough - they'll pass right through each other. |
Author: | Tony [ Mon Dec 26, 2005 8:30 pm ] |
Post subject: | |
Martin -- I don't remember how you ended up fixing that issue. Do you remember where the thread was? |
Author: | Martin [ Mon Dec 26, 2005 8:44 pm ] |
Post subject: | |
http://www.compsci.ca/v2/viewtopic.php?t=9706 I don't have the source anymore, unfortunately. I think I'll rewrite it this weekend though. |
Author: | Saad85 [ Mon Dec 26, 2005 10:45 pm ] | ||
Post subject: | |||
k, obviously i wasn't clear enough. i know how to tell if they've collided, how do i make 2 circles bounce off each other as they would in real life (instead of just reversing x and y velocities) this is my attempt at it.. it didnt go too well so dont bother analysing my code in detail. the basic idea is to store the previous frame's coordinates and use that to find angle of incidence, which i then use to find the next frame's coordinates. this i then use to find velocities. my code is obviously flawed in more ways than 1 so i wont bother going into detail about it.
if anyone would help me out with this, it would be appreciated |
Author: | Saad85 [ Mon Dec 26, 2005 10:51 pm ] |
Post subject: | |
sorry for double post, but where it says c2vx:=(c2x-c2nx)/15 c2vy:=(c2y-c2ny)/15 i did not (at first) include the /15 in there but for some reason the balls start going REALLY fast if its not in there so i just did it to slow them down (couldnt find the problem) |
Author: | [Gandalf] [ Mon Dec 26, 2005 11:43 pm ] |
Post subject: | |
Re-read Cervantes' last post, with an emphasis on the ending. |
Author: | Martin [ Tue Dec 27, 2005 12:40 am ] |
Post subject: | |
For the actual collisions - http://en.wikipedia.org/wiki/Elastic_collision |
Author: | MysticVegeta [ Tue Dec 27, 2005 11:24 am ] |
Post subject: | |
Guys your are excluding Andy completely from this topic! What about the whatdotcolor collision, not everyone has 4.0.5 |
Author: | md [ Tue Dec 27, 2005 11:58 am ] |
Post subject: | |
why would you use whatdotcolor when the mathematical way is so much better? Especially when you don't need 4.05 (at least I'm fairly certain you don't... math functions are present in all version IIRC; though perhaps not vector stuff). |
Author: | Cervantes [ Tue Dec 27, 2005 10:20 pm ] |
Post subject: | |
Agreed. whatdotcolour is assuredly not the way to go. Turing v4.0.5 has the Math.Distance function which is useful to this, though ideally you would heed Martin's comments and do some more advanced math. Regardless, Turing v4.0.5 is not necessary for the mathematical approach. |
Author: | MysticVegeta [ Wed Dec 28, 2005 3:23 pm ] |
Post subject: | |
what about versions 4.0.5 less, they dont have Math.Distance... |
Author: | Saad85 [ Wed Dec 28, 2005 8:57 pm ] |
Post subject: | |
you just use the distance formula d=sqrt((x1-x2)**2+(y1-y2)**2) its just a variation of pythagorus' theorum |