【学习笔记】Matlab中求点到直线的距离

点到直线

假设直线L1: A x + B y + C = 0 Ax+By+C=0 Ax+By+C=0,直线外一点 ( x 0 , y 0 ) (x_0,y_0) (x0,y0),点到直线的垂直距离为 d d d

d = ∣ A x 0 + B y 0 + C ∣ A 2 + B 2 d=\frac{\lvert Ax_0+By_0+C \rvert}{\sqrt{A^2+B^2}} d=A2+B2 Ax0+By0+C

用Matlab计算

需要注意坐标的表示方式

// 当坐标为行向量
p0 = [3,6]
p1 = [3,4]
p2 = [5,6]
d = abs(det([p2-p1;p0-p1])/norm(p2-p1))%d=1.1414

// 当坐标为列向量
p0 = [3;6]
p1 = [3;4]
p2 = [5;6]
d = abs(det([p2-p1,p0-p1])/norm(p2-p1))%d=1.414

// 当坐标为三维空间坐标
p0 = [3;6;4]
p1 = [3;4;3]
p2 = [5;6;5]
d = norm(cross(p2-p1,p0-p1)/norm(p2-p1)%d=1.414

直线间夹角

L1: A 1 x + B 1 y + C 1 = 0 A_1x+B_1y+C_1=0 A1x+B1y+C1=0
L2: A 2 x + B 2 y + C 2 = 0 A_2x+B_2y+C_2=0 A2x+B2y+C2=0
cos ⁡ θ = ∣ A 1 A 2 + B 1 B 2 ∣ A 1 2 + B 1 2 ⋅ A 2 2 + B 2 2 \cos \theta=\frac{\lvert A_1A_2+B_1B_2 \rvert}{\sqrt{A_1^2+B_1^2} \cdot \sqrt{A_2^2+B_2^2}} cosθ=A12+B12 A22+B22 A1A2+B1B2, θ ∈ [ 0 , π 2 ] \theta \in[0,\frac{\pi}{2}] θ[0,2π]

你可能感兴趣的:(编程实践,matlab,学习,线性代数)