MATLAB: I have two 3d points, A(1,0,0) and B(0,1,0). And I connect these two points as a line AB. How to divide this line into 10 equally segments and get their coordinates

divide a line

Hello,
I have two 3d points, A(1,0,0) and B(0,1,0). And I connect these two points as a line AB. How to divide this line into 10 equally segments and get their coordinates?
Many thanks!

Best Answer

This is one way
A = [1,0,0];
B = [0,1,0];
n = 10;
X = [A; B];
t = linspace(0, 1, n+1);
points = interp1([0 1], X, t)
Result
>> points
points =
1.0000 0 0
0.9000 0.1000 0
0.8000 0.2000 0
0.7000 0.3000 0
0.6000 0.4000 0
0.5000 0.5000 0
0.4000 0.6000 0
0.3000 0.7000 0
0.2000 0.8000 0
0.1000 0.9000 0
0 1.0000 0