Draw a 3D tetrahedron
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Rik
le 29 Mai 2020
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
le 29 Mai 2020
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
Réponses (1)
Bjorn Gustavsson
le 29 Mai 2020
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
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!