Show 7 more comments. You look at the sign of the determinant of x2-x1 x3-x1 y2-y1 y3-y1 It will be positive for points on one side, and negative on the other and zero for points on the line itself. Expanding on this answer, In case people don't know what the cross product looks like. Victor Nicollet Victor Nicollet My answer does not assign a "direction" to the line through AB. My answer assumes "left" is the -x direction of the corrdinate system.
The accepted answer chose to define a vector AB, and define left using cross product. The original question does not specify what is meant by "left".
NOTE: If you use this approach rather than the cross-product one that was approved as answer , be aware of a pitfall as the line approaches horizontal.
Math errors increase, and hits infinity if exactly horizontal. The solution is to use whichever axis has the greater delta between the two points. Or maybe smaller delta.. Also exactly what I was looking for. Very simple and to the point. Thank you! Fail: Slope calculation invalid for vertical lines. This answer has several problems. Vertical lines cause a divide by zero. Worse, it fails because it does not worry about whether the slope of the line is positive or negative.
Definitely not a failure for forgetting one test case but thanks for the kind words. The slope is the variable m; I do check when it is positive or negative. Al Globus Al Globus 75 1 1 silver badge 1 1 bronze badge. I wanted to provide with a solution inspired by physics. John Alexiou John Alexiou Here's a version, again using the cross product logic, written in Clojure.
So with the above code, this invocation also produces the result of true : is-left? Purplejacket Purplejacket 1, 2 2 gold badges 19 19 silver badges 37 37 bronze badges. Thanks :. Mohamed Mohamed 11 1 1 bronze badge. Sounds like "bounding box" test, when a rectangle is aligned with both axes.
For example, take a rectangle, and rotate it 45 degrees, so that you have a diamond. There is no such thing as a "top-left point" in that diamond. The leftmost point is neither topmost or bottom most. And of course, 4 points can form even stranger shapes. For example, 3 points could be far off in one direction, and the 4th point in another direction. Keep trying!
If 0, its on the line. The other geometry significances of i and j not related to this solution are: i , j are the scalars for T in a new coordinate system where v,u are the new axes and Q is the new origin; i , j can be seen as pulling force for P,R , respectively. The larger i , the farther T is away from R larger pull from P.
DevilWhite DevilWhite 53 5 5 bronze badges. Tsiros P. Tsiros 11 2 2 bronze badges. Sign up or log in Sign up using Google. I: When P and Q are on opposite sides:. Let us assumed that the points P and Q are on opposite sides of the straight line. The coordinate of the point R which divides the line joining P and Q internally in the ratio m : n are. Let us assumed that the points P and Q are on same side of the straight line.
Now join P and Q. Now assume that the straight line, produced intersects at R. The coordinate of the point R which divides the line joining P and Q externally in the ratio m : n are.
You can determine which side of a line a point is on by converting the line to hyperplane form implicitly or explicitly and then computing the perpendicular pseudo distance from the point to the hyperplane. Thanks guys, it worked great! I used the first technique. Quote: I used the first technique.
Just for the record, the techniques are exactly the same, just written differently. Here's how to get from my version to ToohrVyk's version: diff. Aside from being arranged differently, that is. Also, what do you mean by 'no corrections needed'? Daerax Actually 'simple geometry' is much harder than algebra to do right. Quote: you use dot product , i use simple geometry, there is a difference. Your method performs a dot product as well.
In any case, the only difference I can see between your method and the other proposed solutions is a conceptual one in other words, it's just an alternate way of expressing the same solution. Or am I missing something? This topic is closed to new replies. Nagle So what's going on with the "Metaverse"?
0コメント