perpline: The line passing through a point and perpendicular to the...

View source: R/AuxGeometry.R

perplineR 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 and b crosses.

a, b

2D points that determine the line segment (the line will be perpendicular to this line segment).

x

A scalar or a vector of scalars representing the x-coordinates of the line perpendicular to line joining a and b and crossing p.

Value

A list with the elements

desc

Description of the line passing through point p and perpendicular to line joining a and b

mtitle

The "main" title for the plot of the line passing through point p and perpendicular to line joining a and b

points

The input points a and b (stacked row-wise, i.e., row 1 is point a and row 2 is point b). Line passing through point p is perpendicular to line joining a and b

x

The input vector, can be a scalar or a vector of scalars, which constitute the x-coordinates of the point(s) of interest on the line passing through point p and perpendicular to line joining a and b

y

The output vector which constitutes the y-coordinates of the point(s) of interest on the line passing through point p and perpendicular to line joining a and b. If x is a scalar, then y will be a scalar and if x is a vector of scalars, then y will be a vector of scalars.

slope

Slope of the line passing through point p and perpendicular to line joining a and b

intercept

Intercept of the line passing through point p and perpendicular to line joining a and b

equation

Equation of the line passing through point p and perpendicular to line joining a and b

Author(s)

Elvan Ceyhan

See Also

slope, Line, and paraline

Examples

## Not run: 
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")

## End(Not run)


elvanceyhan/pcds documentation built on June 29, 2023, 8:12 a.m.