suppressPackageStartupMessages({ library(magrittr) }) knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The threed package adapts/extends the mesh3d format to include the following:
primitivetype of point and line
(in addtion to the standard triangle and quad)il. This is a 2 x n matrix giving
the indices of the vertex of each end of the line segment.ip. This is a 1 x n matrix giving
the index of the vertex of the point.properties data.frame can be included in the object. The number of
rows in this data.frame must equal the total number of elements in the object.transform_matrix is a 4x4 transformation matrix. If missing or NULL, then it
is treated as the identity matrix.mesh3d objectsscale_by(obj, c(x, y, z))translate_by(obj, c(x, y, z))rotate_by(obj, angle, c(x, y, z))mesh3d object now includes an extra transform_matrix element which
keeps track of the transforms applied to this object.actualize_transformation on the object.# A 2x2x2 cube centred at the origin threed::mesh3dobj$cube # Transforming the cube only updates the `transform_matrix` of the object threed::mesh3dobj$cube %>% threed::translate_by(c(x=0, y=1, z=1)) # Actualizing the transformation updates the vertices threed::mesh3dobj$cube %>% threed::translate_by(c(x=0, y=1, z=1)) %>% actualize_transformation()
as.data.frame.mesh3dThe as.data.frame.mesh3d function will convert a mesh3d object into a
very verbose data.frame.
This function first calls threed::actualize_transformation() to apply any
outstanding transformations to the vertices.
The resulting data.frame can then be used to plot the 3d points, lines and polygons
in ggplot2. It has the following columns by default:
element_id - element indexelement_type - an integer from 1 to 4 indicating whether the element is a point, line, triangle or quadvorder - vertex ordering within elementx,y,z - coorindates of vertexvertex - global index of this vertexvnx,vny,vnz - unit vector in direction of vertex normalfnx,fny,fnz - unit vector in direction of face normalfcx,fcy,fcz - coordinates of centroid of elementzorder - zorder is used to control ggplot draw order. For polygons it is based upon fcz. For lines it is the smaller of the z coordinates. For points, it is the z coordinate of the pointzorder_var - The value used to determine zorderhidden - by assuming the camera faces along the negative z-axis, any triangle or quad face which has a face normal which also points along the negative z-axis faces away from the camera and is hidden. Boolean value.obj <- threed::mesh3dobj$cube as.data.frame(obj)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.