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

조회 수: 9 (최근 30일)
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

채택된 답변

KSSV
KSSV 2022년 1월 25일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by