sl.intersect | R Documentation |
Diagnose if and where line segments intersect, either within one set of line segments or across two sets, where the sets can be single or multiple concatenated line segments, including polygons.
sl.intersect(lon1,lat1,lon2=NULL,lat2=NULL,close1=FALSE,close2=FALSE,use.dist=TRUE,dist1=NULL,dist2=NULL,distmat=NULL,return.on.firsthit=FALSE)
lon1 |
a numeric vector of length |
lat1 |
a numeric vector of length |
lon2 |
an optional numeric vector of length |
lat2 |
an optional numeric vector of length |
close1 |
a logical value specifying whether or not to consider the first set as a polygon, that is, to connect the last and first points. Default is |
close2 |
a logical value specifying whether or not to consider the second set as a polygon, that is, to connect the last and first points. Default is |
use.dist |
a logical value specifying whether or not to use segment lengths and point distances to exclude segments for which no intersection is possible a priori based on the criterion |
dist1 |
a numeric vector of length |
dist2 |
a numeric vector of length |
distmat |
an optional numeric |
return.on.firsthit |
a logical value specifying whether or not to abort the function and return only the first intersection as soon as it occurs. Default is |
This function uses sl.line.line.intersect
to diagnose intersection points between pairs of line segments. However, if use.dist=TRUE
(default), before invoking sl.line.line.intersect
, the segment lengths and point distances are used to exclude segments for which no intersection is possible a priori based on the criterion (first segment length + second segment length) / 2 <= min(point distance))
. This may speed up the algorithm considerably, in particular when distances are already available and provided as input. In contrast, if return.on.firsthit
and no distances are available beforehand, use.dist=FALSE
can be faster.
This functions considers only those line segments that constitute the shortest great-circle connection between two consecutive points. To obtain great-circle intersection points located on the longer great-circle of either segment, and/or x-y-z coordinates of intersection points directly, consider using sl.line.line.intersect
or sl.line.polygon.intersect
.
A list with the following elements:
anylines.intersect |
a logical value indicating whether any pair of line segments intersects. |
lines.intersect |
a numeric |
lon |
a numeric vector of length |
lat |
a numeric vector of length |
Helge Goessling
sl.line.line.intersect
, sl.line.polygon.intersect
lon1 = c(0,0,10,10)
lat1 = c(0,10,0,10)
lon2 = seq(3,11,2)
lat2 = c(5,0,1,2,5)
plot(lon1,lat1,xlim=c(0,11),ylim=c(0,10),type="b",xlab="longitude",ylab="latitude")
lines(lon2,lat2,type="b",col="red")
res = sl.intersect(lon1,lat1,lon2,lat2)
str(res)
## Should return:
## List of 4
## $ anylines.intersect: logi TRUE
## $ lines.intersect : int [1, 1:2] 2 3
## $ lon : num 8.35
## $ lat : num 1.68
points(res$lon,res$lat,col="blue")
res.close2 = sl.intersect(lon1,lat1,lon2,lat2,close2=TRUE)
str(res.close2)
## Should return:
## List of 4
## $ anylines.intersect: logi TRUE
## $ lines.intersect : int [1:4, 1:2] 2 2 3 3 3 5 4 5
## $ lon : num [1:4] 8.35 5.05 10 10
## $ lat : num [1:4] 1.68 5.01 3.5 5.01
lines(lon2[c(1,length(lon2))],lat2[c(1,length(lon2))],col="red",lty=2)
points(res.close2$lon,res.close2$lat,col="blue",pch=4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.