0

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]

Amir
  • 39
  • 1
  • 7
  • Can't open the link. Do you need something like triangulation() and triplot()? – Kornel Jan 31 '15 at 06:50
  • Thanks for your interest https://www.researchgate.net/post/Plot_a_triagnle_in_three_dimension_by_using_matlab – Amir Jan 31 '15 at 07:22
  • @Amir, you should precise that your `v1`, `v2` and `v3` represent _coordinates_ of points (and not vectors in the mathematical term). The fact that you call them "vector" (which is correct as a Matlab term) but also named them `v...` can be confusing if someone reads you too literally. – Hoki Jan 31 '15 at 11:45

1 Answers1

3

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:

enter image description here


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)

enter image description here

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:

enter image description here

mehmet
  • 1,631
  • 16
  • 21
  • Thanks for your respond. Is it possible to make x and y axis as depicted like in first figure ? – Amir Jan 31 '15 at 11:58
  • @Amir - I don't think so, because this is the way how matlab plots. However, the best thing that you could plots axis on the same figure additionally, would be my naive suggestion. See my edit. – mehmet Jan 31 '15 at 12:31