intersect2lines {pcds} | R Documentation |
The point of intersection of two lines defined by two pairs of points
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
intersect2lines(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
.
Author(s)
Elvan Ceyhan
See Also
intersect.line.circle
and dist.point2line
Examples
A<-c(-1.22,-2.33); B<-c(2.55,3.75); C<-c(0,6); D<-c(3,-2)
ip<-intersect2lines(A,B,C,D)
ip
pts<-rbind(A,B,C,D,ip)
xr<-range(pts[,1])
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=5) #try also l=10, 20, or 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",
main="Point of Intersection of Two Lines",
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"))
[Package pcds version 0.1.8 Index]