p2pIntersect: Solver for 3-plane intersections

View source: R/geom_p2pIntersect.R

p2pIntersectR Documentation

Solver for 3-plane intersections

Description

Computes point or lines of intersections between 3 planes. Handles all cases, including parallel planes.

Usage

p2pIntersect(c.m)

Arguments

c.m

Matrix of coefficients for the plane equations, one per row.

Value

A 1x3 or nx8 dataframe containing point of intersection or line(s) of intersection, the latter given as line equation coefficients (vector form, one per row) as well as IDs of the intersecting planes in input order. If all planes are parallel, the return is NA.

TODO

a) Implement unit tests and b) consider generalizing calls to p2p.multiLine only.

Author(s)

Cornel M. Pop

Examples

# Point intersection:
c.m = rbind(c(1, 1, -2, 5), c(1, -2, -1, -1), c(2, -3, 1, -10))
res = p2pIntersect(c.m)
## Not run: 
points3d(rbind(c(-10,-10,-10), c(10,10,10)))
points3d(rbind(res, res), size=10, col="red") # Draw point of intersection
planes3d(c.m[,1], c.m[,2], c.m[,3], c.m[,4], col="green") # Render the intersecting planes

## End(Not run)

# Single line intersection:
c.m = rbind(c(2, -1, 1, 3), c(2, 1, 1, 2), c(-4, 2, -2, -6)) 
res = p2pIntersect(c.m) # Use first two planes
## Not run: 
p1 = unlist(res[,1:3]) # First point defining the intersection line
p2 = unlist(res[,1:3] - res[,4:6]*0.1) # Second point defining the intersection line
library(rgl)
points3d(rbind(c(-5,-5,-5), c(5,5,5)))
lines3d(rbind(p1, p2), lwd=5, col="red") # Draw the line
planes3d(c.m[,1], c.m[,2], c.m[,3], c.m[,4], col="green") # Render the intersecting planes

## End(Not run)

# Multi-line intersection
c.m = rbind(c(1, -3, 2, 7), c(4, 1, -1, 5), c(6, -5, 3, -1))
res = p2pIntersect(c.m)
## Not run: 
p1 = res[,1:3] # First point defining the intersection lines
p2 = res[,1:3] - res[,4:6]*0.1 # Second point defining the intersection line
library(rgl)
points3d(rbind(c(-10,-10,-10), c(10,10,10)))
lines3d(rbind(p1[1,], p2[1,]), lwd=5, col="red") # Draw the 1st intersection
lines3d(rbind(p1[2,], p2[2,]), lwd=5, col="blue") # Draw the 2nd intersection
lines3d(rbind(p1[3,], p2[3,]), lwd=5, col="purple") # Draw the 3rd intersection
planes3d(c.m[,1], c.m[,2], c.m[,3], c.m[,4], col="green") # Render the intersecting planes

## End(Not run)

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