View source: R/geom_l2sIntersect.R
l2sIntersect | R Documentation |
Computes the intersection points of a line and a sphere
l2sIntersect(l, s)
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. |
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.
Fix the description of the return
Formula taken from Fell, Harriet (2011) CS4300 class notes as accessed at http://www.ccs.neu.edu/home/fell/CS4300/Lectures/Ray-TracingFormulas.pdf
Cornel M. Pop
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.