1

I have a line and point (2D).

Ok, using Paul Bourke formula I can get the distance of ortogonal projection of point to the line.

( Also I can know if the solution is or not inside the segment of line. )

OK, But I'd like to know if the point is at right or left side relative to the line direction.

I can get the angle between line and ortogonal line using Math.acos (crossproduct/moduleProduct) but crossproduct is zero so I can't use it...

Any idea ? Have to use trigonometric approach or maybe is there a trick using vector data ? Th. in advance,

civiltomain
  • 1,136
  • 1
  • 9
  • 27
  • possible duplicate of [Finder what point is to the left of a line/point after spinning it](http://stackoverflow.com/questions/27478243/finder-what-point-is-to-the-left-of-a-line-point-after-spinning-it) – Spektre May 26 '15 at 17:56
  • Shouldn't you be using dot product, not cross product? – Kevin May 26 '15 at 18:05

1 Answers1

2

You can calculate 2d vectors cross product and look at its sign.
Given two vectors v1 and v2 you can calculate 2d cross product as (v1.X*v2.Y) - (v1.Y*v2.X)
If you have point (x, y) and line (x0, y0)-(x1, y1) then ((x-x0)*(y1-y0)) - ((y-y0)*(x1-x0)) is 2d vector cross product. It will be negative if the point is in the left hemiplane.

Serikov
  • 1,159
  • 8
  • 15