Can anyone show me an efficient way to get a 3-D plot of the tetrahedron formed by the following four points in 3-space:
(1,4,-1), (2,0,0), (-1,-4,3), (4,5,7) ?
I would like each surface to have a different color.
Sure.
pts:= [[1,4,-1], [2,0,0], [-1,-4,3], [4,5,7]]; triples:= combinat[choose](pts, 3); colours:= [seq(colour=COLOUR(RGB,op(j)), j=_COLORRGB)]; plots[display](zip(plots[polygonplot3d], triples, colours), scaling=constrained);
Here’s a proc to draw any tetrahedron with any four colors.
DrawTetrahedron:= proc(Pts,Colors) local it,k; it:= combstruct[iterstructs](Combination(Pts), size= 3); RETURN (plots[display] ([seq (plots[display] (PLOT3D(POLYGONS(combstruct[nextstruct](it))) ,color= Colors[k] ) ,k= 1..4 ) ], args[3..nargs] ) ) end: DrawTetrahedron ([[1,4,-1],[2,0,0],[-1,-4,3],[4,5,7]] ,[red,green,blue,yellow] ,axes= boxed );
This works:
> with(combinat): > vertices:=[[1,4,-1], [2,0,0], [-1,-4,3], [4,5,7]]; vertices := [[1, 4, -1], [2, 0, 0], [-1, -4, 3], [4, 5, 7]] > faces:=choose(vertices,3); faces := [[[1, 4, -1], [2, 0, 0], [-1, -4, 3]], [[1, 4, -1], [2, 0, 0], [4, 5, 7]], [[1, 4, -1], [-1, -4, 3], [4, 5, 7]], [[2, 0, 0], [-1, -4, 3], [4, 5, 7]]] > PLOT3D(POLYGONS(op(faces)));
... but it was lucky you wanted a tetrahedron, since all triples of vertices are the faces.
I wish there were some way to plug our own co-ordinates into plotpolyhedra().
with(plots):with(plottools): a:=[1,4,-1]: b:=[2,0,0]: c:=[-1,-4,3]: d:=[4,5,7]: side1:=polygon([a,b,c],color=green): side2:=polygon([a,b,d],color=red): side3:=polygon([a,c,d],color=blue): side4:=polygon([b,c,d],color=gold): display([side1,side2,side3,side4]);
You may use gtetrahedron() of the geom3d package:
restart; with(geom3d): Warning, the name polar has been redefined point(P1,1,4,-1),point(P2,2,0,0),point(P3,-1,-4,3),point(P4,4,5,7); P1, P2, P3, P4 gtetrahedron(T,[P1,P2,P3,P4]); T draw(T,axes=BOXED,scaling=UNCONSTRAINED,labels=[x,y,z]);