Three‐Dimensional Graphics Primitives

One of the most powerful aspects of graphics in the Wolfram System is the availability of threedimensional as well as twodimensional graphics primitives. By combining threedimensional graphics primitives, you can represent and render threedimensional objects in the Wolfram System.

 Point[{x,y,z}] point with coordinates x, y, z Line[{{x1,y1,z1},{x2,y2,z2},…}] line through the points {x1,y1,z1}, {x2,y2,z2}, … Polygon[{{x1,y1,z1},{x2,y2,z2},…}] filled polygon with the specified list of corners Cuboid[{xmin,ymin,zmin},{xmax,ymax,zmax}] cuboid Arrow[{pt1,pt2}] arrow pointing from pt1 to pt2 Text[expr,{x,y,z}] text at position {x,y,z} (see "Graphics Primitives for Text")

Threedimensional graphics elements.

Every time you evaluate rcoord, it generates a random coordinate in three dimensions.
 In[1]:=
This generates a list of 20 random points in threedimensional space.
 In[2]:=
Here is a plot of the points.
 In[3]:=
 Out[3]=
This gives a plot showing a line through 10 random points in three dimensions.
 In[4]:=
 Out[4]=

If you give a list of graphics elements in two dimensions, the Wolfram System simply draws each element in turn, with later elements obscuring earlier ones. In three dimensions, however, the Wolfram System collects together all the graphics elements you specify, then displays them as threedimensional objects, with the ones in front in threedimensional space obscuring those behind.

Every time you evaluate rantri, it generates a random triangle in threedimensional space.
 In[5]:=
This draws a single random triangle.
 In[6]:=
 Out[6]=
This draws a collection of 5 random triangles. The triangles in front obscure those behind.
 In[7]:=
 Out[7]=

By creating an appropriate list of polygons, you can build up any threedimensional object in the Wolfram System. Thus, for example, all the surfaces produced by ParametricPlot3D are represented essentially as lists of polygons.

 Point[{pt1,pt2,…}] a multipoint consisting of points at pt1, pt2, … Line[{line1,line2,…}] a multiline consisting of lines line1, line2, … Polygon[{poly1,poly2,…}] a multipolygon consisting of polygons poly1, poly2, …

Primitives which can take multiple elements.

As with the two-dimensional primitives, some three-dimensional graphics primitives have multi-coordinate forms, which are a more efficient representation. When dealing with a very large number of primitives, using these multi-coordinate forms where possible can both reduce the memory footprint of the resulting graphic and make it render much more quickly.

rantricoords defines merely the coordinates of a random triangle.
 In[8]:=
Using the multi-coordinate form of Polygon, this efficiently represents a very large number of triangles.
 In[9]:=
 Out[9]=

The Wolfram System allows polygons in three dimensions to have any number of vertices in any configuration. Depending upon the locations of the vertices, the resulting polygons may be non-coplanar or nonconvex. When rendering non-coplanar polygons, the Wolfram System will break the polygon into triangles, which are planar by definition, before rendering it.

The non-coplanar polygon is broken up into triangles. The interior edge joining the triangles is not outlined like the outer edges of the Polygon primitive.
 In[10]:=
 Out[10]=
Self-intersecting nonconvex polygons are filled according to an evenodd rule that alternates between filling and not filling at each crossing.
 In[11]:=
 Out[11]=
 Cone[{{x1,y1,z1},{x2,y2,z2}}] a cone with a base radius of 1 centered around {x1,y1,z1} with the point at {x2,y2,z2} Cone[{{x1,y1,z1},{x2,y2,z2}},r] a cone with a base radius of r Cuboid[{x,y,z}] a unit cube with opposite corners having coordinates {x,y,z} and {x+1,y+1,z+1} Cuboid[{xmin,ymin,zmin},{xmax,ymax,zmax}] a cuboid (rectangular parallelepiped) with opposite corners having the specified coordinates Cylinder[{{x1,y1,z1},{x2,y2,z2}}] a cylinder of radius 1 with endpoints at {x1,y1,z1} and {x2,y2,z2} Cylinder[{{x1,y1,z1},{x2,y2,z2}},r] a cylinder of radius r Sphere[{x,y,z}] a unit sphere centered at {x,y,z} Sphere[{x,y,z},r] a sphere of radius r Tube[{{x1,y1,z1},{x2,y2,z2},…}] a tube connecting the specified points Tube[{{x1,y1,z1},{x2,y2,z2},…},r] a tube of radius r

Cuboid graphics elements.

This draws a number of random unit cubes and spheres in threedimensional space.
 In[12]:=
 Out[12]=

Even though Cone, Cylinder, Sphere, and Tube produce high-quality renderings, their usage is scalable. A single image can contain thousands of these primitives. When rendering so many primitives, you can increase the efficiency of rendering by using special options to change the number of points used by default to render Cone, Cylinder, Sphere, and Tube. The "ConePoints" Method option to Graphics3D is used to reduce the rendering quality of each individual cone. Cylinder, sphere, and tube quality can be similarly adjusted using "CylinderPoints", "SpherePoints", and "TubePoints", respectively.

Because the cylinders are so small, the number of points used to render them can be reduced with almost no perceptible change.
 In[13]:=
 Out[13]=