Connecting different sets of 3D points

I have two sets of 3D points over time and I want to include a line between the each of the coresponding two points at each time value. For example:
A_3Dpts= [-0.91, 0.53, 0.32; -.88, .51, .3; -.84, .43, .16]
B_3Dpts= [-0.909, 0.51, 0.321; -.8, .59, .34; -.8, .4, .1]
I've tried using plot3() but only seem to be able to connect the points from the same 3D XYZ points instead of the two seperate groups.
I'll include an image of what I'm hoping to accomplish.

 Réponse acceptée

I assume the rows are the (x,y,z) coordinates,
If so, try this —
A_3Dpts= [-0.91, 0.53, 0.32; -.88, .51, .3; -.84, .43, .16]
A_3Dpts = 3×3
-0.9100 0.5300 0.3200 -0.8800 0.5100 0.3000 -0.8400 0.4300 0.1600
B_3Dpts= [-0.909, 0.51, 0.321; -.8, .59, .34; -.8, .4, .1]
B_3Dpts = 3×3
-0.9090 0.5100 0.3210 -0.8000 0.5900 0.3400 -0.8000 0.4000 0.1000
figure
hold on
for k = 1:size(A_3Dpts,1)
plot3([A_3Dpts(k,1);B_3Dpts(k,1)], [A_3Dpts(k,2);B_3Dpts(k,2)], [A_3Dpts(k,3);B_3Dpts(k,3)], '-k')
scatter3(A_3Dpts(k,1), A_3Dpts(k,2), A_3Dpts(k,3), 50, 'r', 'filled')
scatter3(B_3Dpts(k,1), B_3Dpts(k,2), B_3Dpts(k,3),50, 'g', 'filled')
end
hold off
grid on
view(-30,30)
If the columns are, then switch the subscripts, from (k,1) to (1,k) and so for the others.
.

2 commentaires

Robert
Robert le 9 Nov 2023
Thank you!! this is exactly what I need.
Star Strider
Star Strider le 10 Nov 2023
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by