点到直线距离和投影

直接借用wikipedia的内容,用投影理解点到直线距离公式。

Vectorpoint-to-line.svg

Let P be the point with coordinates (x0, y0) and let the given line have equation ax + by + c = 0. Also, let Q = (x1, y1) be any point on this line and n the vector (a, b) starting at point Q. The vector n is perpendicular to the line, and the distance d from point P to the line is equal to the length of the orthogonal projection of \overrightarrow{QP} on n. The length of this projection is given by:
$d = \frac{|\overrightarrow{QP} \cdot \mathbf{n}|}{| \mathbf{n}|}$.
Now,
$\overrightarrow{QP} = (x_0 – x_1, y_0 – y_1)$, so $\overrightarrow{QP} \cdot \mathbf{n} = a(x_0 – x_1) + b(y_0 – y_1)$ and $| \mathbf{n} | = \sqrt{a^2 + b^2}$,
thus
$d = \frac{|a(x_0 – x_1) + b(y_0 – y_1)|}{\sqrt{a^2 + b^2}}$.
Since Q is a point on the line,$ c = -ax_1 – by_1$, and so
$d = \frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}$.

投影

一个向量AB在另一个向量CD上的投影的长度d,$d = \frac{|\overrightarrow{AB} \cdot \overrightarrow{CD}|}{| \mathbf{CD}|}$。这个公式很容易理解,$\frac{\mathbf{CD}}{| \mathbf{CD}|}$是单位向量。拿一个比较容易理解的例子,假如向量CD是一条水平的向量,即平行于x轴,那么,这个它的单位向量就是$(1,0)$,若用AB与之计算点积,那么得到的结果就是AB在x轴上的长度

发表评论

电子邮件地址不会被公开。 必填项已用*标注