mapOnMesh: Map coordinates onto a target mesh surface (nearest mesh...

View source: R/surf_c2vMap.R

mapOnMeshR Documentation

Map coordinates onto a target mesh surface (nearest mesh vertex)

Description

For a given set of arbitrary coordinates, it returns the closest mesh vertices. This function is similar to the closemeshKD function provided by the Morpho package, but it's simpler and runs much faster (ca. 5-10x)

Usage

mapOnMesh(coords, mesh)

Arguments

coords

a data.frame-like object with 3D coordinates (1 per row). Only the first three columns will be used.

mesh

a target mesh3d object

Value

A data.frame object with target vertices extracted from mesh$vb and rownames set to the original vertex IDs

Note

The output may differ from input landmarks already mapped to the mesh surface because this function returns the closest mesh vertex, not the closest point on the mesh surface (e.g. shortest distance to a mesh face)

Examples

library(Morpho)
data(demoFlake1)
alignedMesh<-pcAlign(demoFlake1$mesh)
# Note that the first coordinate is "inside" the object
coords<-data.frame(x=c(0,10,-3), y=c(0,10,3), z=c(5,10,10))
targets<-mapOnMesh(coords, alignedMesh)

require(rgl)
shade3d(alignedMesh, col="green")
points3d(coords, col="blue")
points3d(targets, col="red")

cornelmpop/Lithics3D documentation built on Feb. 10, 2024, 11:54 p.m.