diag2edge | R Documentation |
Computes the edge of a square from its diagonal.
diag2edge(cordseg)
cordseg |
The diagonal coordinates. This can be a vector c(x1,y1,x2,y2), a 2 x 2 matrix or a data.frame (each line a coordinate) |
The first point coordinates are the left top of the diagonal. The other coordinates computed are the other
top of the square edge. Can be used e.g. to pass a square edge to pave
in order
to compute a sampling grid.
A 2x2 matrix of points coordinates
pave
# diagonal sloping up
coord<-matrix(c(20,20,90,90),nr=2,byrow=TRUE)
plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1)
lines(coord,lty=2)
# square edge
lines(diag2edge(coord),col="red")
# diagonal sloping down
coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE)
plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1)
lines(coord,lty=2)
# square edge
lines(diag2edge(coord),col="red")
# diagonal vertical
coord<-matrix(c(20,90,20,20),nr=2,byrow=TRUE)
plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1)
lines(coord,lty=2)
# square edge
lines(diag2edge(coord),col="red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.