Learn R Programming

pcds (version 0.1.2)

int.2lines: The point of intersection of two lines

Description

Returns the intersection of two lines, first line passing through points p1 and q1 and second line passing through points p2 and q2. The points are chosen so that lines are well defined.

Usage

int.2lines(p1, q1, p2, q2)

Arguments

p1, q1

2D points that determine the first straight line (i.e., through which the first straight line passes).

p2, q2

2D points that determine the second straight line (i.e., through which the second straight line passes).

Value

The coordinates of the point of intersection of the two lines, first passing through points p1 and q1 and second passing through points p2 and q2.

See Also

int.circ.line and dp2l

Examples

Run this code
# NOT RUN {
A<-c(-1.22,-2.33); B<-c(2.55,3.75); C<-c(0,6); D<-c(3,-2)

ip<-int.2lines(A,B,C,D)
ip
pts<-rbind(A,B,C,D,ip)
xr<-range(pts)
xf<-abs(xr[2]-xr[1])*.1 #how far to go at the lower and upper ends in the x-coordinate
x<-seq(xr[1]-xf,xr[2]+xf,l=20)  #try also l=100
lnAB<-Line(A,B,x)
lnCD<-Line(C,D,x)

y1<-lnAB$y
y2<-lnCD$y
Xlim<-range(x,pts)
Ylim<-range(y1,y2,pts)
xd<-Xlim[2]-Xlim[1]
yd<-Ylim[2]-Ylim[1]
pf<-c(xd,-yd)*.025

#plot of the line joining A and B
plot(rbind(A,B,C,D),pch=1,xlab="x",ylab="y",xlim=Xlim+xd*c(-.05,.05),ylim=Ylim+yd*c(-.05,.05))
lines(x,y1,lty=1,col=1)
lines(x,y2,lty=1,col=2)
text(rbind(A+pf,B+pf),c("A","B"))
text(rbind(C+pf,D+pf),c("C","D"))
text(rbind(ip+pf),c("intersection\n point"))

int.2lines(c(1,2),c(1,3),C,D)

# }

Run the code above in your browser using DataLab