How can I find the general form equation of a line from two points?

前端 未结 5 2081
野的像风
野的像风 2021-02-02 09:48

Given the input:

double x1,y1,x2,y2;

How can I find the general form equation (double a,b,c where ax + b

5条回答
  •  甜味超标
    2021-02-02 10:09

    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.

提交回复
热议问题