e2sIntersect: Mesh edge / sphere intersection

View source: R/surf_edgeIntersects.R

e2sIntersectR Documentation

Mesh edge / sphere intersection

Description

[Experimental]

Computes the intersection coordinates of mesh edges (i.e., the sides of the triangles that form the triangular mesh) and a sphere for cases where edge ends are on opposite sides of the sphere's surface (i.e., one end is within the sphere, the other end is outside of it). In this implementation no intersections are returned for edges that cut across the sphere.

Usage

e2sIntersect(e_ids, s, mpts, medges)

Arguments

e_ids

A vector containing mesh edge IDs, corresponding to the row names of the Rvcg::vcgGetEdge output when run with "unique" set to TRUE).

s

A vector of length 4 (center.x, center.y, center.z, radius) defining a sphere

mpts

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. May be identical to the e_ids parameter, or the latter may be subset.

Value

A data.frame with intersection coordinates (x,y,z), one per row, for all input edges; the row names correspond to input edge ids.

Author(s)

Cornel M. Pop

Examples

data(demoSphere) # Use the included demoSphere object for this example
t_edges <- Rvcg::vcgGetEdge(demoSphere, unique = TRUE)
t_sphere <- c(0.5, 0.5, 0.5, 1) # Offset by 0.5 from demoSphere's center

# Compute intersections (if any) with all edges of the demoSphere:
res <- e2sIntersect(rownames(t_edges),
                    t_sphere,
                    t(demoSphere$vb), # transpose vertex coordinates
                    t_edges)
## Not run: 
library(rgl)
wire3d(demoSphere, col = "black")
spheres3d(t_sphere[1:3], col = "green", alpha = 0.5)
points3d(res, col = "red")

# Close the 3D window:
close3d()

## End(Not run)


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