Determine which side of a line a point is

Started by
13 comments, last by Cousken 12 years, 9 months ago
a simple problem.

let a line (L) defined by two points
(Ax,Ay) and (Bx,By)

and two vertical lines on A and B

and a point (Mx,My).

when the point M is between the vertical lines?
Advertisement
Hello!
Sorry for reviving and old thread. I used the method described here and it works prefectly, but i am trying to undestand the use of dot product here. I have defined my lines with a point and a direction, so half of the math is already done in before hand. My case is as is:


Vector2f myFirstPoint = new Vector2f(100,100);
Vector2f myDirection = new Vector2f(1,0);

public boolean inside(Vector2f aPosition) {
final Vector2f lineToPosition = new Vector2f(aPosition);
lineToPosition.sub(myFirstPoint);

float dotProduct = (myDirection.x) * (lineToPosition.y) - (myDirection.y) * (lineToPosition.x);
if (dotProduct > 0) {
return false;
}
return true;
}


As you can see the only differance here from the original post by ToohrVyk is that i have (Bx - Ax) and (By - Ay) caluclated before hand in the form of myDirection. (Cy - Ay) and (Cx - Ax)are calculated with the sub() method which stands for substact. But the mathematical definition of dot product isn't as the form used here. According to Wikipedia:

c329bf86e747d74f55ed2e17c36fd83f.png

According to this what the formula here calculates is not a dot product. I would really appriciate if someone helped me to undestand how dot product is used here, perhaps how the forumla is derived from it?

Thanks everyone who already contributed here for making my life easier :)
It's called the perp-dot (perpendicular-dot) product; which is the exterior product in 2 dimensions. It has many properties which the cross product has in 3D; for instance | x perpdot y | = |x||y|sin theta for instance (like in 3D | x cross y | = |x||y|sin theta.

in 2D each vector (vx ; vy) has 2 perpendicular vectors (-vy ; vx), (vy ; -vx) for which we normally choose (-vy ; vx) to be the principal perpendicular, and then the perp-dot product between vectors u,v is perp(u) dot v = u.x * v.y - u.y * v.x
It is the dot product between the vector perpendicular to the direction and the difference between the points. If (x, y) is a vector, (-y, x) is perpendicular to it (it's the vector rotated by 90°). It works because the projection of one vector v along the direction of another vector d is defined to be (dot(d, v)/dot(d, d))d, but since we are only interested if the projection of the difference vector has the same direction of the perpendicular vector we have chosen, it is enough to determine the sign of the dot product between these two vectors.

Thank you both very much, that made things much clearer!

This topic is closed to new replies.

Advertisement