I would like to draw different triangles by using MATLAB shown in the figure below. Suppose that I have 3 vectors V1=[1 1 1]
, V2=[-1 1 1]
, v3=[-2 -2 -2]
.
How can I draw triangle with these vectors in 3D?
![enter image description here][1]
I would like to draw different triangles by using MATLAB shown in the figure below. Suppose that I have 3 vectors V1=[1 1 1]
, V2=[-1 1 1]
, v3=[-2 -2 -2]
.
How can I draw triangle with these vectors in 3D?
![enter image description here][1]
You can use plot3()
like this:
v1=[1 1 1]; v2=[-1 1 1]; v3=[-2 -2 -2];
triangle = [v1(:), v2(:), v3(:), v1(:)];
plot3(triangle(1, :), triangle(2, :), triangle(3, :))
xlabel('x'); ylabel('y'); zlabel('z');
This is the output:
Edit:
This is in order to plot axis:
val = 5; %// Max value of axis
axX = [0 0 0; val 0 0];
axY = [0 0 0; 0 val 0];
axZ = [0 0 0; 0 0 val];
plot3(axX(:, 1), axX(:, 2), axX(:, 3), 'k');
plot3(axY(:, 1), axY(:, 2), axY(:, 3), 'k');
plot3(axZ(:, 1), axZ(:, 2), axZ(:, 3), 'k');
text(val, 0, 0, 'x')
text(0, val, 0, 'y')
text(0, 0, val, 'z')
view(3)
In addition you can make the plot look like your reference image, adding these commands to above code:
set(gca,'xtick',[], 'xcolor', 'w')
set(gca,'ytick',[], 'ycolor', 'w', 'YDir','reverse')
set(gca,'ztick',[], 'zcolor', 'w')
view(45, 30)
This is the result: