View source: R/surf_edgeIntersects.R
edgesOnPlane | R Documentation |
Identifies mesh edges that intersect a given plane. Note that no
intersection points are computed by this function - use
Morpho::meshPlaneIntersect()
for that purpose.
edgesOnPlane(p, mpts, medges)
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 ( |
medges |
An Nx4 data.frame corresponding to the output of
Rvcg::vcgGetEdge |
A vector of row IDs for edges (from medges
) that intersect the
input plane.
Cornel M. Pop
Morpho::meshPlaneIntersect
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.