答案 0 :(得分:2)
该部分的整个长度是
dAB = sqrt( (x2-x1).^2 + (y2-y1).^2 + (z2-z1).^2 );
现在,使用dAB
,dAC
和dBD
之间的比例来获取其余坐标:
x3 = x1 + (dAC./dAB)*(x2-x1);
y3 = y1 + (dAC./dAB)*(y2-y1);
z3 = z1 + (dAC./dAB)*(z2-z1);
类似地
x4 = x1 + ((dAB-dBD)./dAB)*(x2-x1);
y4 = y1 + ((dAB-dBD)./dAB)*(y2-y1);
z4 = z1 + ((dAB-dBD)./dAB)*(z2-z1);
验证:
figure;
plot3([x1 x3 x4 x2].',...
[y1 y3 y4 y2].',...
[z1 z3 z4 z2].',...
'-*',...
'LineWidth', 1.5);
距离
sqrt( (x1-x3).^2 + (y1-y3).^2 + (z1-z3).^2 ) - dAC
sqrt( (x2-x4).^2 + (y2-y4).^2 + (z1-z3).^2 ) - dBD
用更多MATLABby表示法,
% Coordinates of A (x1) and B (X2)
X1 = [x1 y1 z1].';
X2 = [x2 y2 z2].';
% distance between A and B
dX12 = X2 - X1;
dAB = norm(dX12);
% Coordinates of C (X3) and D (X4)
X3 = X1 + dAC/dAB * dX12;
X4 = X1 + (dAB-dBD)/dAB * dX12;
% Plot to verify
Y = [X1 X3 X4 X2].';
plot3(Y(:,1), Y(:,2), Y(:,3),...
'r-*',...
'LineWidth', 1.5);
% Distances to verify
ddAC = norm(X1 - X3) - dAC
ddBD = norm(X2 - X4) - dBD