Skip to contents

For each triangle of a mesh, computes the average of the values associated with its three vertices. This is useful for going from a per-vertex value to a per-face value (for example, to use meshColor = "faces" in rgl::shade3d() starting from a quantity defined at the vertices).

Usage

vb2tri(x, s)

Arguments

x

triangular mesh (mesh3d object with an it component, see rgl::mesh3d()).

s

vector of values associated with the vertices of x (same length as the number of columns of x$vb).

Value

Numeric vector with one value per triangle (column of x$it), equal to the average of the values of s at its vertices.

See also

Examples

library(rgl)
open3d()
z_tri <- vb2tri(volcanom, volcanom$vb[3, ])
shade3d(volcanom, col = scolor(z_tri, col = terrain.colors(128)))