matlab向量问题If P1 is (1,2,3) and P2 is (-4,0,5),find(a) The vector equation of the line P1P2(b) The shortest distance between the line P1P2 and point P3(7,-1,2)
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 14:33:51
matlab向量问题If P1 is (1,2,3) and P2 is (-4,0,5),find(a) The vector equation of the line P1P2(b) The shortest distance between the line P1P2 and point P3(7,-1,2)
matlab向量问题
If P1 is (1,2,3) and P2 is (-4,0,5),find
(a) The vector equation of the line P1P2
(b) The shortest distance between the line P1P2 and point P3(7,-1,2)
matlab向量问题If P1 is (1,2,3) and P2 is (-4,0,5),find(a) The vector equation of the line P1P2(b) The shortest distance between the line P1P2 and point P3(7,-1,2)
方程:
x=-5*t+1
y=-2*t+2
z=2*t+3
最短距离:5.0513
参考程序:
clc
p1=[1,2,3];
p2=[-4,0,5];
p3=[7 -1 2];
dp=p2-p1;
%直线的方程:
syms t
f=dp'*t+p1';
disp('方程:')
f
t=linspace(-1,2.1,4);
f1=-5*t+1;
f2=-2*t+2;
f3=2*t+3;
plot3(f1,f2,f3);hold on;
plot3(1,2,3,'r.','markersize',20);hold on;
plot3(-4,0,5,'r.','markersize',20);hold on;
plot3(7,-1,2,'b.','markersize',20);hold on;
text(1+.5,2,3,'P1');
text(-4+.5,0,5.5,'P2');
text(7+.5,-1,2,'P3');
p1p2=p1-p2;
p2p3=p2-p3;
st=acos(dot(p1p2,p2p3)/(norm(p1p2)*norm(p2p3)));
z=sin(st)*norm(p2p3); %最短距离
disp(['最短距离:' num2str(z)])