Learn R Programming

zonohedra (version 0.6-0)

zonohedron-as.mesh3d: convert the boundary of a zonohedron to an rgl::mesh3d object

Description

mesh3d is an S3-class object defined in package rgl. Polygons in the 3D mesh can be either triangles or quadrilaterals, or both. In the case of a zonohedron, only quadrilaterals are used. The function as.mesh3d.zonohedron() is derived from rgl::as.mesh3d().

After a mesh3d object is constructed, it can be plotted by rgl::dot3d(), rgl::wire3d() or rgl::shade3d(). rgl::addNormals() can be used to add normal vectors to the vertices of the mesh. An object can be exported to a text file using rgl::writeOBJ(), but the vertices are not shared. There are many more methods in rgl.

Usage

# S3 method for zonohedron
as.mesh3d( x, fcolor=NULL, falpha=1, codes=FALSE, ... )

Value

The function returns an object of class c( "mesh3d", "shape3d" ). It is a list with items vb, ib, material, and meshColor. vb is a 4xV double-precision matrix, where V is the number of vertices; the 4th row is all 1s. ib is an 4xQ integer matrix with indexes into vb, where Q is the number of quadrilaterals.

material is a list with items color and alpha. color is a character vector of length Q, and alpha is set to falpha. meshColor is set to "faces".

If codes=TRUE, then a NxV raw matrix of vertex codes is added to the returned list. See above for details on this matrix. WARNING: Use codes=TRUE with caution, since the matrix of codes can be large.

Arguments

x

a zonohedron object as returned by the constructor zonohedron()

fcolor

A vector of colors to use when drawing the facets. The 1st color is used for parallelograms, the next color for hexagons, etc. For facets with more edges than colors available, the last color is used. If fcol is NULL, it is set to c( 'blue', 'red', 'yellow', 'green', 'orange', 'purple' ).

falpha

opacity of the facets

codes

if TRUE then an NxV raw matrix of vertex codes is added to the returned list. All values in the matrix are 0 or 1. N is the number of simplified generators of x, and V is the number of vertices. These codes in the columns of the matrix correspond to the vertices of the cube \([0,1]^N\) that map to the vertices of x.

...

not used

Details

On the boundary of the zonohedron, a parallelogram facet with 2 generators and 4 edges is turned into a single quadrilateral in the mesh. A hexagon facet with 3 generators and 6 edges is divided into 2 quadrilaterals. A zonogon facet with \(m\) generators is divided into \(m{-}1\) quadrilaterals.

Let \(V\) be the #(vertices), \(E\) be the #(edges), and \(Q\) be the #(quadrilaterals). Since an edge belongs to exactly 2 quadrilaterals, it easily follows that \(E = 4Q/2 = 2Q\). The boundary of the zonohedron is homeomorphic to the 2-sphere \(S^2\) whose Euler characteristic is 2. Therefore \(V - E + Q = 2 \implies V = Q + 2\).

The function rgl::as.mesh3d.default() has a tolerance argument used to determine whether two or more vertices should be merged. We avoid that tolerance by using the fact, as pointed out by Heckbert, that each vertex of a zonohedron has a unique "binary code", whose length is the number of simplified generators. In this function the binary code storage is implemented in C++ using std::map< std::vector<unsigned char>, int >.

References

Paul Heckbert. An Efficient Algorithm for Generating Zonohedra. 3-D Technical Memo 11. 24 February 1985. Computer Graphics Lab. New York Institute of Technology

See Also

zonohedron(), rgl::as.mesh3d(), rgl::shade3d(), rgl::writeOBJ()

Examples

Run this code
#  view a zonohedron using rgl::shade3d()
zono12 = zonohedron( classics.genlist[[12]] )
mesh   = rgl::as.mesh3d( zono12 )
rgl::shade3d( mesh, back='culled' )


cube = zonohedron( classics.genlist[[ 'C' ]] )
mesh = rgl::as.mesh3d( cube )
class( mesh ) = "list"   # we bypass print.mesh3d() and see the contents of the mesh
mesh

##  $vb
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
##  [1,]    0    0    1    1    1    1    0    0
##  [2,]    0    1    1    0    1    0    0    1
##  [3,]    0    0    0    0    1    1    1    1
##  [4,]    1    1    1    1    1    1    1    1
##  
##  $ib
##       [,1] [,2] [,3] [,4] [,5] [,6]
##  [1,]    1    4    1    8    5    6
##  [2,]    2    6    7    7    3    4
##  [3,]    3    7    8    6    2    3
##  [4,]    4    1    2    5    8    5
##  
##  $material
##  $material$color
##  [1] "blue" "blue" "blue" "blue" "blue" "blue"
##  
##  $material$alpha
##  [1] 1
##  
##  $meshColor
##  [1] "faces"

Run the code above in your browser using DataLab