简体   繁体   English

已知线上的点的坐标

[英]The coordinates of the point which is on a known line

I need to know the coordinates of C and D but I couldn't get them. 我需要知道CD的坐标,但无法获取。 I know it's a very basic math question but I couldn't code it. 我知道这是一个非常基本的数学问题,但我无法编写代码。

The coordinates of A and B are known and dAC and dBD are known. AB的坐标是已知的, dACdBD是已知的。

在此处输入图片说明

The entire length of the section is 该部分的整个长度为

dAB = sqrt( (x2-x1).^2 + (y2-y1).^2 + (z2-z1).^2 );

Now, use the proportions between dAB , dAC and dBD to get the rest of the coordinates: 现在,使用dABdACdBD之间的比例来获取其余坐标:

x3 = x1 + (dAC./dAB)*(x2-x1);
y3 = y1 + (dAC./dAB)*(y2-y1);
z3 = z1 + (dAC./dAB)*(z2-z1);

Similarly 相似地

x4 = x1 + ((dAB-dBD)./dAB)*(x2-x1);
y4 = y1 + ((dAB-dBD)./dAB)*(y2-y1);
z4 = z1 + ((dAB-dBD)./dAB)*(z2-z1);

To verify: 核实:

figure;
plot3([x1 x3 x4 x2].',...
      [y1 y3 y4 y2].',...
      [z1 z3 z4 z2].',...
      '-*',...
      'LineWidth', 1.5);

And the distances 和距离

sqrt( (x1-x3).^2 + (y1-y3).^2 + (z1-z3).^2 ) - dAC
sqrt( (x2-x4).^2 + (y2-y4).^2 + (z1-z3).^2 ) - dBD

In a more MATLABby notation, 在更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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM