Preventing a point from intersecting a Line.

BlitzMax Forums/BlitzMax Programming/Preventing a point from intersecting a Line.

daaan(Posted 2006) [#1]
How could I prevent a point from crossing through a line? Are there any reasonable methods?

Thanks.


AlexO(Posted 2006) [#2]
yes. you can calculate the distance of a point to a line, or make sure the point never crosses over to the otherside of the line. To do that you determine which side the point is on and never let it pass. The actual math is this:
let v be your line (x,y). Now make a perpendicular version of it called vt (-y,x). Take the dot product of vt and your point p. if it is the dot product is greater than 0 then it is to the left of your line. If it is negative then it is to the right of your line. If it is 0 then it is right on your line.

Left and Right are relative to which way the line is pointing. So just take the first calculation and save it. Once the sign of the dot product changes you know that the point has crossed over.


Oddball(Posted 2006) [#3]
I'd use one of the many LineIntersect functions in the code archives with one line being your test line and the other being a line from the points old position to it's new position. If the lines intersect then the line was crossed. Also these functions return the point at which the lines cross.

Yet Another Line Intersect Function
Concave/convex polygon collisions and other useful functions.
Lines_Intersect()

There's probably a couple more too if you have a search.