Creating orthogonal 3D vector and find coordinates of intersection with a second vector.

2 views (last 30 days)
I thought my problem should be easy to solve, but I’m working on it for a couple of days now and I can’t figure it out. The answers that I find online are sometimes close but they never solve my problem.
I have 4 coordinates defining 2 trajectories in a 3D space (xyzpre and xyzpost). First I want to find the orthogonal vector to the first trajectory (xyzpre) and then I want the coordinates of the intersecting point between the orthogonal vector and the second trajectory. (The orthogonal vector has to start at the end point of the first trajectory and then intersect with the second trajectory)
As you can see in my MATLAB code I tried to draw the orthogonal vector, but I don’t know how I can get him point towards the second trajectory and let them intersect. For visualization see the code below, it should work immediately.
All suggestions are very welcome!
%% coordinates
xpre=[-49.10,4.91]; ypre=[-212.21,-216.72]; zpre=[-103.42,-98.09]; xyzpre=[-49.10,4.91;-212.21,-216.72;-103.42,-98.09];
xpost=[-49.68,3.11]; ypost=[-208.06,-217.45]; zpost=[-103.61,-96.45]; xyzpost=[-49.68,3.11;-208.06,-217.45;-103.61,-96.45];
%% vectors and orthogonal lines
vector1=[xyzpre(1,2)-xyzpre(1,1) xyzpre(2,2)-xyzpre(2,1) xyzpre(3,2)-xyzpre(3,1)]; vector2=[xyzpost(1,2)-xyzpost(1,1) xyzpost(2,2)-xyzpost(2,1) xyzpost(3,2)-xyzpost(3,1)]; c=cross(vector1,vector2);
V1=[vector1' vector2'] % Each column of V is one of our vectors W1 = orth(V1) % Find an orthonormal basis for the same space
line1=xyzpre(:,2)+W1(:,1) line2=xyzpre(:,2)+ [0.9851 -0.1280 0.1151]'
%% visualize, draw trajectories
xline=[xyzpre(1,2) line1(1)]; yline=[xyzpre(2,2) line1(2)]; zline=[xyzpre(3,2) line1(3)];
xline2=[xyzpre(1,2) line2(1)]; yline2=[xyzpre(2,2) line2(2)]; zline2=[xyzpre(3,2) line2(3)];
plot3(xpre,ypre,zpre,'LineWidth',1.5,'Color','g'); % pre traj. hold on plot3(xpre(1),ypre(1),zpre(1),'Marker','o'); % pre entry line(xpost,ypost,zpost,'LineWidth',1.5,'Color','r'); % post traj. plot3(xpost(1),ypost(1),zpost(1),'Marker','o'); % post entry line(xline,yline,zline,'Marker','o'); % post entry line(xline2,yline2,zline2,'Marker','o'); % post entry grid on

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!