## ---- echo=FALSE, include=FALSE----------------------------------------------- library(knitr) opts_chunk$set(fig.width = 5, fig.height = 5, fig.cap='', collapse = TRUE) ## ---- geo3-------------------------------------------------------------------- library(geosphere) LA <- c(-118.40, 33.95) NY <- c(-73.78, 40.63) data(wrld) plot(wrld, type='l') gc <- greatCircle(LA, NY) lines(gc, lwd=2, col='blue') gci <- gcIntermediate(LA, NY) lines(gci, lwd=4, col='green') points(rbind(LA, NY), col='red', pch=20, cex=2) mp <- midPoint(LA, NY) onGreatCircle(LA,NY, rbind(mp,c(0,0))) points(mp, pch='*', cex=3, col='orange') greatCircleBearing(LA, brng=270, n=10) ## ---- geo7-------------------------------------------------------------------- ml <- gcMaxLat(LA, NY) lat0 <- gcLat(LA, NY, lon=0) lon0 <- gcLon(LA, NY, lat=0) plot(wrld, type='l') lines(gc, lwd=2, col='blue') points(ml, col='red', pch=20, cex=2) points(cbind(0, lat0), pch=20, cex=2, col='yellow') points(t(rbind(lon0, 0)), pch=20, cex=2, col='green' ) f <- function(lon){gcLat(LA, NY, lon)} opt <- optimize(f, interval=c(-180, 180), maximum=TRUE) points(opt$maximum, opt$objective, pch=20, cex=2, col='dark green' ) anti <- antipode(c(opt$maximum, opt$objective)) points(anti, pch=20, cex=2, col='dark blue' ) ## ---- geo9-------------------------------------------------------------------- SF <- c(-122.44, 37.74) AM <- c(4.75, 52.31) gc2 <- greatCircle(AM, SF) plot(wrld, type='l') lines(gc, lwd=2, col='blue') lines(gc2, lwd=2, col='green') int <- gcIntersect(LA, NY, SF, AM) int antipodal(int[,1:2], int[,3:4]) points(rbind(int[,1:2], int[,3:4]), col='red', pch=20, cex=2) bearing1 <- bearing(LA, NY) bearing2 <- bearing(SF, AM) bearing1 bearing2 gcIntersectBearing(LA, bearing1, SF, bearing2)