perpline {pcds} | R Documentation |
The line passing through a point and perpendicular to the line segment joining two points
Description
An object of class "Lines"
.
Returns the equation, slope, intercept
,
and y
-coordinates of the line crossing
the point p
and perpendicular to the line
passing through the points a
and b
with x
-coordinates are provided in vector
x
.
Usage
perpline(p, a, b, x)
Arguments
p |
A 2D point at which the perpendicular line to line segment
joining |
a , b |
2D points that determine the line segment (the line will be perpendicular to this line segment). |
x |
A scalar or a |
Value
A list
with the elements
desc |
Description of the line
passing through point |
mtitle |
The |
points |
The input points |
x |
The input vector, can be a scalar or a |
y |
The output |
slope |
Slope of the line passing through point |
intercept |
Intercept of the line passing through point |
equation |
Equation of the line passing through point |
Author(s)
Elvan Ceyhan
See Also
Examples
A<-c(1.1,1.2); B<-c(2.3,3.4); p<-c(.51,2.5)
perpline(p,A,B,.45)
pts<-rbind(A,B,p)
xr<-range(pts[,1])
xf<-(xr[2]-xr[1])*.25
#how far to go at the lower and upper ends in the x-coordinate
x<-seq(xr[1]-xf,xr[2]+xf,l=5) #try also l=10, 20, or 100
plnAB<-perpline(p,A,B,x)
plnAB
summary(plnAB)
plot(plnAB,asp=1)
y<-plnAB$y
Xlim<-range(x,pts[,1])
if (!is.na(y[1])) {Ylim<-range(y,pts[,2])} else {Ylim<-range(pts[,2])}
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
pf<-c(xd,-yd)*.025
plot(A,asp=1,pch=".",xlab="",ylab="",
main="Line Crossing p and Perpendicular to AB",
xlim=Xlim+xd*c(-.5,.5),ylim=Ylim+yd*c(-.05,.05))
points(pts)
txt.str<-c("A","B","p")
text(pts+rbind(pf,pf,pf),txt.str)
segments(A[1],A[2],B[1],B[2],lty=2)
if (!is.na(y[1])) {lines(x,y,type="l",lty=1,
xlim=Xlim,ylim=Ylim)} else {abline(v=p[1])}
tx<-p[1]+abs(xf-p[1])/2;
if (!is.na(y[1])) {ty<-perpline(p,A,B,tx)$y} else {ty=p[2]}
text(tx,ty,"line perpendicular to AB\n and crossing p")