Draw a 3D tetrahedron

17 次查看(过去 30 天)
Adam Roudi
Adam Roudi 2020-5-29
Hi
I'm new to Matlab.
how do I draw a tetrahedron?
The 4 corner points are given.
p1(0 0 0)
p2(0 1 1)
p3(1 0 1)
p4(1 1 0)
can anyone help?
  4 个评论
Rik
Rik 2020-5-29
If you only want the points:
x = [0 0 1 1 0 1 0 1];
y = [0 1 0 1 0 0 1 1];
z = [0 1 1 0 0 1 1 0];
plot3(x,y,z,'*')
axis([-0.5 1.5 -0.5 1.5 -0.5 1.5])
Bjorn Gustavsson
Bjorn Gustavsson 2020-5-29
You can spice up Rik's idea by using the scatter3 function:
scatter3(x(1:4),y(1:4),z(1:4),34,1:4,'filled'),colorbar
That way you get the points coloured in order.
Then if you want to plot the triangular surfaces you can use fill3 to do that, for example the triangle with the three first points in the corners:
fill3(x(1:3),y(1:3),z(1:3),'r')
Then you'll have to do the same for the remaining triangles.
HTH

请先登录,再进行评论。

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2020-5-29
Have a look at the help and documentation of plot3. That function should give you what you need. The tedious thing you need to take into account when plotting the exges of a solid is that you need to make sure to plot each edge. This should get you started:
p1 = [0 0 0];
p2 = [0 1 1];
plot3([p1(1),p2(1)],[p1(2),p2(2)],[p1(3),p2(3)],'r.-')
hold on
HTH

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by