简体   繁体   中英

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. 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.

在此处输入图片说明

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:

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,

% 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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