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

8 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

KSSV
KSSV il 25 Gen 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)

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by