How to get distance from point to line with distinction between side of line?

Posted by tesselode on Game Development See other posts from Game Development or by tesselode
Published on 2012-09-14T02:12:56Z Indexed on 2012/09/14 15:50 UTC
Read the original article Hit count: 211

I'm making a 2d racing game. I'm taking the nice standard approach of having a set of points defining the center of the track and detecting whether the car is off the track by detecting its distance from the nearest point. The nicest way I've found of doing this is using the formula:

d = |Am + Bn + C| / sqrt(A^2 + B^2)

Unfortunately, to have proper collision resolution, I need to know which side of the line the car is hitting, but I can't do that with this formula because it only returns positive numbers.

So my question is: is there a formula that will give me positive or negative numbers based on which side of the line the point is on? Can I just get rid of the absolute value in the formula or do I need to do something else?

© Game Development or respective owner

Related posts about collision-detection

Related posts about math