Sign in to follow this  

Collision Resolving issue 2D

This topic is 2333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i finally think im finally ready for rigid body dynamics now that i have a point of intersection.
I'm really excited to get started on programming my very first physics simulation.


Right now collisions look like this:
[media]http://www.youtube.com/watch?v=hs8J-a9DUEk[/media]

As you can see i can find the point of intersection for edges vs points but for edge vs edge the function i use to get point of intersection returns an ambiguous point (im not sure if the video shows that but just trust me it does).

So anyway i was reading this guys [url="http://chrishecker.com/Rigid_Body_Dynamics"]Article (PART 3)[/url] on collision detection and it turns out that i need to have a center of gravity for each shape and a vector that points from the center of gravity to the point of intersection and somehow you can get a normal. The thing is, i dont even understand where the normal comes from.

The diagram in the article looks much like this:

[img]http://www.myphysicslab.com/images/collision_4.gif[/img]
Can someone explain to me how i get the normal?
I'm self taught and dont fully grasp the math used in these papers..

Also i'm not using matrix math to rotate the polygons because im having trouble applying matrix math to programming.
I've decided im going to rotate shapes the retarded way by storing a copy of the shape and individually change the angle of each vertex.
using:
x=distance*cos(angle + newangle) + center.X
y=distance*sin(angle + newangle)+center.Y



***********************************UPDATE***************************************
Ok I have a new problem/

For a while now , i've been updating positions of shapes by scaling my velocity vector down by a certain magnitude and then adding the vector that i scaled down with the translation vector, updating my position.
This seemed to give me decent sliding effects and the appearance of arcade physics.

to give you a better idea of how I update positions here's an example of an update function:

[code]
void UpdatePositions(){
Vector2D velocity = getCurrentVelocity() ;
Vector2D TranslationVector = getTranslationVector();//<- Vector that translates all the points that belong to the shape
Velocity *= 0.9;//<-Scaling the magnitude of the velocity vector down every frame
TranslationVector +=Velocity; //<-Updating position of polygon based on velocity vector
}
[/code]

Up until my recent project to implement a rigid body system, this seemed to work fairly well for arcade physics.
Recently ,I've learnt that i should use something called "integration".
I looked it up on Wikipedia and youtube for more information and i was completely blown away at how difficult it looked to use integration with ANYTHING.

I have no experience with calculus and absolutely no experience with integration.
In order to add rotation to polygons, Do i NEED to learn things like:
-> verlet intergration
->Runge Kutta intergration
->euler Intergration
(sorry if i spelled them wrong)

the only tools i have (regarding math skills) to tackle this is everything I learnt in grade 11 advanced functions.
I've also taught myself vector operations but those arent too difficult to understand.

An example of how objects should rotate when im finished:
[media]http://www.youtube.com/watch?v=LnvtZn2agmA[/media]

Share this post


Link to post
Share on other sites
It's not clear if you know what a normal is: [url="http://en.wikipedia.org/wiki/Surface_normal"]http://en.wikipedia.org/wiki/Surface_normal[/url]

In figure 1 of the article you referred to, he clearly shows the normal as the vector n. He also mentions in the article that you just take the normal to the edge for the edge for edge-point collisions, facing object A as a convention.

Calculating normals to a line segment: [url="http://stackoverflow.com/questions/1243614/how-do-i-calculate-the-normal-vector-of-a-line-segment"]http://stackoverflow.com/questions/1243614/how-do-i-calculate-the-normal-vector-of-a-line-segment[/url]

Share this post


Link to post
Share on other sites
[quote name='ehsanul' timestamp='1311535457' post='4839703']
It's not clear if you know what a normal is: [url="http://en.wikipedia.org/wiki/Surface_normal"]http://en.wikipedia..../Surface_normal[/url]

In figure 1 of the article you referred to, he clearly shows the normal as the vector n. He also mentions in the article that you just take the normal to the edge for the edge for edge-point collisions, facing object A as a convention.

Calculating normals to a line segment: [url="http://stackoverflow.com/questions/1243614/how-do-i-calculate-the-normal-vector-of-a-line-segment"]http://stackoverflow...-a-line-segment[/url]
[/quote]

If i didn't know what a normal is i wouldn't even be able to preform sat collision and i would be here asking about that,however, that's not the case.
And i also know that if i found the normal of the edge in Figure1 I would get a vector with the same direction of vector N.


So let me reiterate my Question.
Notice in the picture i've posted.
[img]http://www.myphysicslab.com/images/collision_4.gif[/img]
Can i find vector N with Rap and Rbp?
What do i have to do with vectors Rap and Rbp to get Vector N?
The only vector operations I understand are : dot product, left normal, right normal, normalizing ,addding/subtracting, scaling
*EDIT*
Okay so it turns out i basically had vector N all along.
I saw that i could use the Minimum Translational Distance Vector as the normal.
I drew all vectors on the screen and it matches this image so i guess im doing it right.
I think i can now calculate torque.

Share this post


Link to post
Share on other sites
[quote name='thecoast47' timestamp='1311537314' post='4839709']
So let me reiterate my Question.
Notice in the picture i've posted.
[img]http://www.myphysicslab.com/images/collision_4.gif[/img]
Can i find vector N with Rap and Rbp?
What do i have to do with vectors Rap and Rbp to get Vector N?


The only vector operations I understand are : dot product, left normal, right normal, normalizing ,addding/subtracting, scaling
[/quote]

I'm pretty sure you can't use Rap and Rbp to get the normal, since I can think of ways to transform body A, and thus Rap without affecting n: rotate body A about P. n should be unaffected, but your Rap changes. Or elongate body A in either width or height with P fixed. You can see that Rap changes again, with n unaffected. This works for body B and Rbp too. Finally, if you translate body B lengthwise, Rbp changes but n must remain the same.

Hence, there really is no relation between those two vectors and the normal, except that you need them all to model the physics.

To get n, you need to use the slope of the colliding edge, as I mentioned in my last post. Is there any problem with doing it that way?

EDIT: saw your edit. The vector for the minimum translation distance should work fine.

Share this post


Link to post
Share on other sites
Ok I have a new problem/

For a while now , i've been updating positions of shapes by scaling my velocity vector down by a certain magnitude and then adding the vector that i scaled down with the translation vector, updating my position.
This seemed to give me decent sliding effects and the appearance of arcade physics.

to give you a better idea of how I update positions here's an example of an update function:

[code]
void UpdatePositions(){
Vector2D velocity = getCurrentVelocity() ;
Vector2D TranslationVector = getTranslationVector();//<- Vector that translates all the points that belong to the shape
Velocity *= 0.9;//<-Scaling the magnitude of the velocity vector down every frame
TranslationVector +=Velocity; //<-Updating position of polygon based on velocity vector
}
[/code]

Up until my recent project to implement a rigid body system, this seemed to work fairly well for arcade physics.
Recently ,I've learnt that i should use something called "integration".
I looked it up on Wikipedia and youtube for more information and i was completely blown away at how difficult it looked to use integration with ANYTHING.

I have no experience with calculus and absolutely no experience with integration.
In order to add rotation to polygons, Do i NEED to learn things like:
-> verlet intergration
->Runge Kutta intergration
->euler Intergration
(sorry if i spelled them wrong)

the only tools i have (regarding math skills) to tackle this is everything I learnt in grade 11 advanced functions.
I've also taught myself vector operations but those arent too difficult to understand.

An example of how objects should rotate when im finished:
[media]http://www.youtube.com/watch?v=LnvtZn2agmA[/media]

Share this post


Link to post
Share on other sites
A good knowledge of calculus is absolutely necessary to understand anything but the most basic steps and operations you're doing right now. I would suggest cracking open a textbook on single-variable calculus and get reading. Then you can begin to understand concepts like force, acceleration, and velocity on a mathematical level.

As simply as I can put it, calculus introduces two new concepts that work on functions: derivatives and integration. A derivative describes a rate of change, while an integral describes a total accumulated change. The derivative and the integral are then sort-of opposites of one another. Hence, velocity, which is the derivative of position with respect to time, can be used to find the position by integrating velocity with respect to time. All of the integration techniques you have described are numerical techniques for approximating integrals. Once you learn a bit of calculus it will become clearer why there are different methods, and why you would need to use different methods in the first place.

Share this post


Link to post
Share on other sites

This topic is 2333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this