Matlab求解点到直线距离

点到直线的距离公式推导:
Matlab求解点到直线距离_第1张图片
Matlab程序:

syms x y z
A=[1,3,5]; %假定三点坐标
B=[2,4,6];
C=[7,8,9];
D=[ones(4,1),[[x,y,z];A;B;C]];%由空间解析几何的内容知道D的行列式等于零就是平面方程。
detd=det(D);
disp(strcat(‘平面方程为:’,char(detd),’=0’))

%下面的图像只当能解出显式z时才画的出来:

z=solve(detd,z);%这是解出来的
plot3(1,3,5,’‘,2,4,7,’‘,1,5,6,’*’)
hold on
ezmesh(z)
Matlab求解点到直线距离_第2张图片

关于如何提取其中的参数:
用命令 coeffs(d)

COEFFS Coefficients of a multivariate polynomial.
C = COEFFS(P) returns the coefficients of the polynomial P with
respect to all the indeterminates of P.
C = COEFFS(P,X) returns the coefficients of the polynomial P with
respect to X.
[C,T] = COEFFS(P,…) also returns an expression sequence of the
terms of P. There is a one-to-one correspondence between the
coefficients and the terms of P.

Examples:

syms x
t = 2 + (3 + 4*log(x))^2 - 5*log(x);
coeffs(expand(t)) = [ 11, 19, 16]

syms a b c x
y = a + b*sin(x) + c*sin(2*x)
coeffs(y,sin(x)) = [a + c*sin(2*x), b]
coeffs(expand(y),sin(x)) = [a, b + 2*c*cos(x)]

syms x y
z = 3*x^2*y^2 + 5*x*y^3
coeffs(z) = [5, 3]
coeffs(z,x) = [5*y^3, 3*y^2]
[c,t] = coeffs(z,y)
returns c = [5*x, 3*x^2], t = [y^3, y^2]

coeffs(d)

ans = [ 4, -2, 1, 3]

参考博客:http://www.cnblogs.com/graphics/archive/2010/07/10/1774809.html

你可能感兴趣的:(Matlab求解点到直线距离)