How to find the coordinate of a point perpendicular to 3D line with desired scalar distance?
3 views (last 30 days)
Show older comments
Hi Community!
I need advices about how to generate code for shifting mid-point of 3D line by pre-known distance perpendicularly.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/684038/image.jpeg)
I know the coordinate of points 1, 2 and 3. (3rd point is mid-point between points 1 and 2.) My main objective is to find the coordinate of point 4 which is located on perpendicular 3d line. I have also preknown distance parameter (d) as a scalar value.
Thanks for helping.
Mesut
3 Comments
Answers (1)
Nipun
on 4 Jun 2024
Edited: Nipun
on 4 Jun 2024
Hi Mesut,
I understand that you intend to know a way to calculate the coordinates of "point 4" such that line formed by points 3,4 is perpendicular to line by points 1,2 and the distance between point 4 and point 3 is "d".
Since the complete geometry is 3D, there is a complete circular cross-section where "point 4" lies, with radius "d" and centre point 3.
Given the coordinates points 1,2,3 and parameter "d", I recommend using the "cross" function in MATLAB to get a vector perpendicular to point 3 as follows:
% Coordinates of P1 and P2
P1 = [x1, y1, z1];
P2 = [x2, y2, z2];
% Calculate midpoint P3
P3 = (P1 + P2) / 2;
% Calculate a direction vector perpendicular to the line P1P2
% Assuming the line is not vertical; otherwise, change the vector [0, 0, 1] accordingly
direction_vector = cross(P2 - P1, [0, 0, 1]);
direction_vector = direction_vector / norm(direction_vector); % Normalize
% Calculate P4
d = %your_known_distance;
P4 = P3 + d * direction_vector;
% Display the result
disp('Coordinates of P4:');
disp(P4);
This method will yield one vector of the many possible that lie on the required circle. Changing the vector "[0 0 1]" vector will yield a different vector.
Refer to the following MathWorks documentation for more information on "cross" function (vector cross product) in MATLAB: https://www.mathworks.com/help/matlab/ref/cross.html
Hope this helps.
Regards,
Nipun
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!