l2sIntersect: Line/sphere intersection points

View source: R/geom_l2sIntersect.R

l2sIntersectR Documentation

Line/sphere intersection points

Description

Computes the intersection points of a line and a sphere

Usage

l2sIntersect(l, s)

Arguments

l

A 2x3 matrix-like object with coordinates defining a line, one per row.

s

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

Value

A list containing coordinates of intersection points, or NA if the line does not intersect the sphere. If the line is tangent to the sphere, both points will be identical.

TODO

Fix the description of the return

Note

Formula taken from Fell, Harriet (2011) CS4300 class notes as accessed at http://www.ccs.neu.edu/home/fell/CS4300/Lectures/Ray-TracingFormulas.pdf

Author(s)

Cornel M. Pop

Examples

library(rgl)
l = matrix(c(0.3,2.5,3,2,5,5), nrow=2, byrow=TRUE)
s = c(2,2,2,3)
res <- l2sIntersect(l, s)
spheres3d(s[1], s[2], s[3], radius=s[4], color="blue", alpha=0.4)
points3d(res, color="red")
lines3d(l, color="black", lwd=3)

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