View source: R/orthogonalProjectionToLine.R
orthogonalProjectionToLine | R Documentation |
Given a 2D or 3D input point p
and a 2D or 3D line, this function finds a point on the line at a minimum distance from point p
. This is equivalent to the orthogonal projection of point p
onto the line.
orthogonalProjectionToLine(p, l1 = NULL, l2 = NULL)
p |
a vector of a single point or a matrix of multiple points |
l1 |
a vector describing a point on a line or a list with line constants |
l2 |
if |
If p
is a vector, the function returns a point as a vector of the same dimension. If p
is a matrix, each row is treated as a point and the orthogonal projection is returned for each. These points are returned as a matrix (of the same dimension), each row being the orthogonal projection of the corresponding row in p
.
The line input can be defined using one of three standard ways: two points on the line, 'm' and 'b' constants (slope and y-intercept) and direction numbers 'abc' (a vector parallel to a line through the origin). If l1
is a vector, this is taken as one point on the line and l2
must be a second point on the line. If l1
is a list, the named objects must correspond to one of these three line definitions. Two points on the line are defined as l1$l1
and l1$l2
. 'm' and 'b' are defined as l1$m
and l1$b
. And the direction numbers 'abc' are defined as l1$a
, l1$b
and l1$c
.
a vector if p
is a vector and a matrix if p
is a matrix. The returned vector or matrix will be of the same dimensions as p
.
Aaron Olsen
http://paulbourke.net/geometry/pointlineplane/
distancePointToLine
## POINT INPUT: 2D VECTOR ## LINE INPUT: l1, l2 ## LINE THROUGH THE ORIGIN WITH SLOPE OF ONE orthogonalProjectionToLine(p=c(0, 5), l1=c(0, 0), l2=c(3, 3)) ## POINT INPUT: 2D VECTOR ## LINE INPUT: LIST WITH l1, l2 orthogonalProjectionToLine(p=c(0, 5), l1=list(l1=c(0, 0), l2=c(3, 3))) ## POINT INPUT: 2D VECTOR ## LINE INPUT: LIST WITH m, b ## LINE WITH Y-INTERCEPT AT ONE AND SLOPE OF ONE orthogonalProjectionToLine(p=c(0, 5), l1=list(m=1, b=0)) ## POINT INPUT: 2D VECTOR ## LINE INPUT: LIST WITH VECTOR PARALLEL TO LINE THROUGH THE ORIGIN ## LINE THROUGH THE ORIGIN WITH SLOPE OF ONE orthogonalProjectionToLine(p=c(0, 5), l1=list(a=1, b=-1, c=0)) ## POINT INPUT: 2D VECTOR ## LINE INPUT: SAME AS PREVIOUS BUT WITH Z-AXIS COMPONENT orthogonalProjectionToLine(p=c(0, 5), l1=list(a=1, b=-1, c=1)) ## POINT INPUT: 3D VECTOR ## LINE INPUT: l1, l2 orthogonalProjectionToLine(p=c(0, 5, 0), l1=list(l1=c(0, 0, 0), l2=c(3, 3, 3))) ## POINT INPUT: 2D MATRIX ## LINE INPUT: l1, l2 p <- matrix(c(0,5, 0,10), nrow=2, byrow=TRUE) orthogonalProjectionToLine(p=p, l1=list(l1=c(0, 0), l2=c(3, 3))) ## POINT INPUT: 3D MATRIX ## LINE INPUT: l1, l2 p <- matrix(c(0,5,0, 0,10,0), nrow=2, byrow=TRUE) orthogonalProjectionToLine(p=p, l1=list(l1=c(0, 0, 0), l2=c(3, 3, 3)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.