MATLAB: Line of arbitrary length through 2 points in 3-D

3d3d plot3d plotslinepoints

Hello,
I'm looking for a method of finding – and plotting – a line through two points. I already know how to plot a line segment:
x = [x1 x2];
y = [y1 y2];
z = [z1 z2];
plot3(x,y,z)
But this gives a line segment connecting the two points. How can I both plot and be able to extract the equation for a line of arbitrary length that includes two points in 3-D?
Thanks a lot,
Nick

Best Answer

You cannot create a line with arbitrary length. You have to decide for a specific start- and end-point.
nx = x2 - x1;
ny = y2 - y1;
nz = z2 - z1;
len = 1000;
xx = [x1 - len*nx, x2 + len*nx];
yy = [y1 - len*ny, y2 + len*ny];
zz = [z1 - len*nz, z2 + len*nz];
H = plot3(xx, yy, zz);
set(H, 'XLimInclude', 'off', 'YLimInclude', 'off', 'ZLimInclude', 'off');
The XLimInclude feature is not documented, see Undocumented: liminclude
Related Question