Given the input:
double x1,y1,x2,y2;
How can I find the general form equation (double a,b,c where ax + by + c = 0) ?
Note: I want to be able to do this computationally. So the equivalent for slope-intercept form would be something like:
double dx, dy; double m, b; dx = x2 - x1; dy = y2 - y1; m = dy/dx; b = y1;
Obviously, this is very simple, but I haven't been able to find the solution for the general equation form (which is more useful since it can do vertical lines). I already looked in my linear algebra book and two books on computational geometry (both too advanced to explain this).
General form of a line The general form ax+by+c=0 is one of the many different forms you can write linear functions in. Other ones include the slope intercept form y=mx+b or slope-point form. We can convert the linear function among different forms.
The general equation of a straight line is y = mx + c, where m is the gradient, and y = c is the value where the line cuts the y-axis. This number c is called the intercept on the y-axis. The equation of a straight line with gradient m and intercept c on the y-axis is y = mx + c.
If you start from the equation y-y1 = (y2-y1)/(x2-x1) * (x-x1)
(which is the equation of the line defined by two points), through some manipulation you can get (y1-y2) * x + (x2-x1) * y + (x1-x2)*y1 + (y2-y1)*x1 = 0
, and you can recognize that:
a = y1-y2
,b = x2-x1
,c = (x1-x2)*y1 + (y2-y1)*x1
.Get the tangent by subtracting the two points (x2-x1, y2-y1)
. Normalize it and rotate by 90 degrees to get the normal vector (a,b)
. Take the dot product with one of the points to get the constant, c
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With