Advertisement

Line-point collision error

Started by September 05, 2012 08:16 PM
2 comments, last by Faelenor 12 years, 5 months ago
Im trying to make a little physics engine in vb2010, the goal is to have rectangles which collide,slide and rotate 'realistically'

i've got a ploblem with the collisions, here is how I do it:
lineb.png
for each edge of rectangle1(the small one), I make a vector with the velocity of the rectangle and check every line on rectangle2 and get the closest intersection point, I then do the same with the edges of rectangle2 and the lines of rectangle1, and keep the closest line/point

so basically, the red square represents the first edge that will collide with the object and the green square represent the point on the line where it will collide

the blue line is the velocity of the small rectangle
the red line represents the collision reaction, the distance the red square need to travel to touch the other rectangle
the pale green represents where the object should slide
the dark green represents the colliding line

now here is the problem: after the action is taken and the 2 rectangles collide, the edge is ON the line and that makes my line/point algorithm fail on some occasions (like when the rectangle is at a certain angle)

my first thougth was to 'push' the rectangle just a bit towards the colliding line's normal so that it is over the line instead of directly on it, it worked great, but the problem came back when I added gravity, if I use a very very low gravity the rectangle will go down so slow that it will eventually go trought the line ( i guess it moves so slowly that it can get very close to the line, enough so that my intersection algorithm fails like when the point is directly on the line)
I think that instead of cheating, you should debug your algorithm to make it work in every cases.
Advertisement
haha, good point, cheating is bad
but I think the problem is not that my algorithm is bad, I think its because of the 'unreliability' of floating point values

I think its because of the 'unreliability' of floating point values


Then, it means that your algorithm is not good enough! Floating points are sometimes tricky, but when used correctly, they should never be unreliable. I would suggest you to read this series of article about floating points, it's really instructive:

http://www.altdevblogaday.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/

This topic is closed to new replies.

Advertisement