•      Sign In
• Create Account

# Line-point collision error

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1k0lpA  Members   -  Reputation: 127

Like
0Likes
Like

Posted 05 September 2012 - 02:16 PM

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:

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)

Sponsor:

### #2Faelenor  Members   -  Reputation: 381

Like
0Likes
Like

Posted 06 September 2012 - 07:12 AM

I think that instead of cheating, you should debug your algorithm to make it work in every cases.

### #3k0lpA  Members   -  Reputation: 127

Like
0Likes
Like

Posted 06 September 2012 - 11:09 AM

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

### #4Faelenor  Members   -  Reputation: 381

Like
0Likes
Like

Posted 07 September 2012 - 06:19 AM

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/

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS