How to tell whether a point is to the right or left side of a line given by point and angle

StackOverflow https://stackoverflow.com/questions/23369221

  •  12-07-2023
  •  | 
  •  

سؤال

My Question is very similar to this one: How to tell whether a point is to the right or left side of a line.

They got a line defined between two points A,B and a third point Z that should be tested.

I got a line defined by a point P and angle a and the third point Z that should be tested. Obviously i could compute the third point from the angle and P and use their solution, but i hope there is a better/faster way.

Example Picture

Z and Z' should register as "above", Z'' should register as "below" the line.

Background: I'm programming C++ with OpenCV and currently am trying to make sense of the relation between detected rotated Rectangles.

هل كانت مفيدة؟

المحلول

You have two vectors - direction vector D=(sin(a),cos(a)) and PZ. If their cross product is positive, then Z lies in left semiplane, otherwise - in right semiplane. What semiplane is considered as 'above' - depends on cos(a) sign.

Result = cos(a) * (sin(a) * PZ.Y - cos(a) * PZ.X) > 0
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top