al-eax
al-eax

Reputation: 732

How to draw a 3D line in octave/matlab

I would like to draw a simple line between 2 Points in a 3D space using octave.

I have tried to use plot3 with two 3D vectors:

vec1 = [0 0 0]
vec2 = [100 100 100]
hold on;
plot3(vec1,vec2,"-");

But this did not work for me.

I found no pure octave code to draw a line between two points/vectors.

Could u help me?

Upvotes: 6

Views: 5459

Answers (2)

Lamid
Lamid

Reputation: 21

For point A (xa, ya, za) and point B (xb, yb, zb) Line A to B:

vectorx=[xa xb]
vectory=[ya yb]
vectorz=[za zb]
plot3(vectorx,vectory,vectorz)

Upvotes: 2

Luis Mendo
Luis Mendo

Reputation: 112659

In Matlab you call plot3 with three vectors (or matrices), each specifying the x, y and z coordinates respectively. So:

plot3([vec1(1) vec2(1)], [vec1(2) vec2(2)], [vec1(3) vec2(3)], '-')

Upvotes: 8

Related Questions