The general form of a line equation is given as . Given two points and , we can compute coefficients , , and as follows. First, compute the slope as rise over run . Second, plug this value and one of the points into the point-slope form, given by , and gather all terms on the lefthand side:
Finally, we can see that , , and .
Equivalence to Orient2D
It is useful to observe that the general form of a line equation can be used as an orientation predicate. Namely, given a third point , plugging the point into the line equation and observing the sign of the result will tell you if the point is to the left (negative sign), on (zero), or to the right (positive sign) of the oriented line through and .
This implies an algebraic equivalence to the usual Orient2D predicate:
We can see this by plugging the third point into , using the values for , , and we computed above:
The following demo shows three points and highlights the third point in red when it is to the left, black when it is on, and green when it is to the right of the line through the other two points.
Pingback: Computing the Intersection of Two Lines | Clinton Freeman
Pingback: Finding the largest area axis-parallel square with a known center in a polygon | Clinton Freeman