R/line2plane.r

Defines functions line2plane

Documented in line2plane

#' get intersection between a line and a plane
#'
#' get intersection between a line and a plane
#' @param ptLine vector of length 3: point on line
#' @param ptDir  vector of length 3: direction vector of line
#' @param planeNorm vector of length 3: plane normal vector
#' @param planePt vector of length 3: point on plane
#' @return hit point
#' @note in case you only have three points on a plane (named \code{pt1, pt2, pt3} you can get the plane's normal by calling \code{crossProduct(pt1-pt2,pt1-pt3)}.
#' @export
line2plane <- function(ptLine,ptDir, planePt, planeNorm) {
    d <- crossprod(planeNorm,planePt)
    t1 <- c((d-crossprod(planeNorm,ptLine))/crossprod(planeNorm,ptDir))
    out <- ptLine+t1*ptDir
    if (!length(out))
        stop("plane and line are collinear")
    return(out)
}

Try the Morpho package in your browser

Any scripts or data that you put into this service are public.

Morpho documentation built on June 22, 2024, 7:19 p.m.