edgesOnPlane: Identify plane-intersecting mesh edges

View source: R/surf_edgeIntersects.R

edgesOnPlaneR Documentation

Identify plane-intersecting mesh edges

Description

[Experimental]

Identifies mesh edges that intersect a given plane. Note that no intersection points are computed by this function - use Morpho::meshPlaneIntersect() for that purpose.

Usage

edgesOnPlane(p, mpts, medges)

Arguments

p

A 3x3 matrix-like object with x, y, and z coordinates (one per row) defining a plane.

mpts

An Nx4 matrix-like object corresponding to the transposed mesh vertex coordinates (t(mesh$vb), where mesh is a mesh3d object).

medges

An Nx4 data.frame corresponding to the output of Rvcg::vcgGetEdge⁠(mesh, unique=T)⁠, where mesh is a mesh3d object.

Value

A vector of row IDs for edges (from medges) that intersect the input plane.

Author(s)

Cornel M. Pop

See Also

Morpho::meshPlaneIntersect

Examples

# Use the included demoSphere for this example:
data(demoSphere)
mesh <- demoSphere

# Prepare data required by the function:
p <- data.frame(x = c(0, 1, 1), y = c(0, 1, 0), z = c(0, 0.5, 0.5))
mvb <- t(mesh$vb)
medges <- Rvcg::vcgGetEdge(mesh)

# Identify edges intersected by the plane (i.e., edges of interest, or eoi):
eoi <- edgesOnPlane(p, mvb, medges)

# Get coordinates for both edge ends:
vb1 <- mvb[medges[eoi, 1], 1:3] # edge end 1
vb2 <- mvb[medges[eoi, 2], 1:3] # edge end 2

# Visualize:
## Not run: 
# Show the wireframe of demoSphere and the three coordinates defining the
# plane
library(rgl)
wire3d(demoSphere, col = "green", alpha = 0.5)
points3d(p, col = "red")

# Compute plane coefficients from the three coordinate and plot the plane
res <- planeCoefs(p)
planes3d(res[1], res[2], res[3], res[4], col="yellow")

# Show the edges that cross the plane:
for (i in seq_along(eoi)) {
lines3d(rbind(vb1[i, ], vb2[i, ]), lwd = 2, col = "blue")
}

# Close the 3D window:
close3d()

## End(Not run)


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