如何从两点找到直线的一般形式方程式? [英] How can I find the general form equation of a line from two points?

查看:107
本文介绍了如何从两点找到直线的一般形式方程式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入:

double x1,y1,x2,y2;

如何找到一般形式的方程式(双a,b,c,其中ax + by + c = 0)?

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).

推荐答案

如果从等式y-y1 = (y2-y1)/(x2-x1) * (x-x1)(这是由两点定义的直线的等式)开始,则可以通过一些操作得到(y1-y2) * x + (x2-x1) * y + (x1-x2)*y1 + (y2-y1)*x1 = 0,并且您可以认识到:

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.
  • a = y1-y2,
  • b = x2-x1,
  • c = (x1-x2)*y1 + (y2-y1)*x1.

这篇关于如何从两点找到直线的一般形式方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆