suppressPackageStartupMessages({
  library(magrittr)
})
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

mesh3d adaptations

The threed package adapts/extends the mesh3d format to include the following:

Transforming mesh3d objects

# 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.mesh3d

The 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:

obj <- threed::mesh3dobj$cube

as.data.frame(obj)


coolbutuseless/threed documentation built on May 5, 2019, 7:08 a.m.