0

I'm trying to come up with a function that takes two points that are used to form a line, a reference point, and a point, and outputs True if the point is on the line formed, or is

a point that is known to on the outside part of the line, and point that needs determining if it is on the outside or inside half the area divided by the line formed. In this case, on the line counts as outside.

This is similar to this question, but the desired side could have a positive or a negative cross-product, so a somewhat different approach is required. I've already tried a few times to get it to work with cross products and at this point I'm just looking for something that'll work for sure.

Edit: Inside/outside is used simply due to the nature of the problem, seemed better than "side a" and "side b" or the "left side" and "right side". In this case, the "inside" points will be ignored, while the "outside" points will remain.

Here is an example using both sides of the line:

enter image description here

While they are squares, each represents a "point". The red squares are the two that make up the line. There is then a green and a blue point. The green point is inside for the blue point, and the blue point is inside to the These represent the outside points. The blue circles represent the points that are considered outside. The blue circled points are considered outside points in reference to the blue point, while the green circled points are considered outside points to the green point.

Community
  • 1
  • 1
Nuclearman
  • 5,029
  • 1
  • 19
  • 35
  • Two points are at the same side if they are both on the positive side OR both on the negative side. – John Dvorak Dec 05 '12 at 13:38
  • Nitpicking, but a line doesn't have an inside or outside. Can you rephrase the question to be more clear, possibly with some ASCII art? (left and right of the line also don't work, since a horizontal line doesn't have left or right. And does the line stop at its two points, or continues to infinity?) –  Dec 05 '12 at 13:48
  • I *think* the OP wants to tell whether or not two points (the 'point' and the 'reference point') are on the same side of the line or not. But if that's the case then the linked-to question would work - just check if both are to the left or both are to the right. Alternatively check for an intersection of the original line and the line that would join the two points (http://stackoverflow.com/questions/3838329/how-can-i-check-if-two-segments-intersect) – Stuart Dec 05 '12 at 13:55

1 Answers1

0

You can still use cross products. If A and B are the points defining the line, R is your reference point, and P is your test point, then form the two cross products ABxAR and ABxAP. The dot product of these two vectors will be positive if the points lie on the same side of the line and negative if they do not.

bogatron
  • 18,639
  • 6
  • 53
  • 47