How to generate random points in a 3d line, if two end points are known??

9 vues (au cours des 30 derniers jours)
Shiv Karpoor
Shiv Karpoor le 25 Jan 2022
Commenté : Shiv Karpoor le 25 Jan 2022
Hello MATLAB Community,
I am working on a project and I am having a small problem, where I have to generate random points between two known points in 3D space.
for example : point A = [ 0, 0, 405] and point B = [ 4.5, -5.5, 480], I need to generate say 50 - 100 random points in-between point A & B.
Can anyone please help me with any suggestions.
Thank you in advance!!
I really appreciate your help.
Kind regards,
Shiv

Réponse acceptée

KSSV
KSSV le 25 Jan 2022
A = [ 0, 0, 405] ;
B = [ 4.5, -5.5, 480] ;
AB = B-A ; % vector
t = sort(rand(1,100)) ; % random points
% Parametric equation of line in 3D
P = A'+t.*AB' ;
% plot
figure
hold on
plot3(A(1),A(2),A(3),'*r')
plot3(B(1),B(2),B(3),'*r')
plot3(P(1,:),P(2,:),P(3,:),'.-b')
view(3)

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by