#### one point
d <- rdistaz(12, 23, -32, -65)
d
#### many random target points
org <- c(80.222, -100.940)
targ <- cbind(runif(10, 10, 50), runif(10, 20, 100))
rdistaz(org[1], org[2], targ[,1], targ[,2])
############ if origin and target are identical
##### the distance is zero, but the az and baz are not defined
rdistaz(80.222, -100.940, 80.222, -100.940)
######################## set one of the targets equal to the origin
targ[7,1] <- org[1]
targ[7,2] <- org[2]
rdistaz(org[1], org[2], targ[,1], targ[,2])
#### put in erroneous latitude data
targ[3,1] <- -91.3
rdistaz(org[1], org[2], targ[,1], targ[,2])
###########
### New York and Chapel Hill
NY =list(lat=40.6698, lon=286.0562)
CH = list(lat=35.92761, lon=280.9594)
## h = GEOmap::distaz(CH$lat, CH$lon, NY$lat, NY$lon)
h = rdistaz(CH$lat, CH$lon, NY$lat, NY$lon)
####### get great circle ray path
RAY = GEOmap::getgreatarc(CH$lat, CH$lon, NY$lat, NY$lon, 100)
#### get great circle through north pole
Nor1 = GEOmap::getgreatarc(CH$lat, CH$lon, 90, CH$lon, 100)
PROJ = GEOmap::setPROJ(2, CH$lat, CH$lon)
RAY.XY = GEOmap::GLOB.XY(RAY$lat, RAY$lon, PROJ)
Nor1.XY = GEOmap::GLOB.XY(Nor1$lat, Nor1$lon, PROJ)
VEE1 = c(Nor1.XY$x[2]-Nor1.XY$x[1], Nor1.XY$y[2]-Nor1.XY$y[1])
VEE2 = c(RAY.XY$x[2]-RAY.XY$x[1], RAY.XY$y[2]-RAY.XY$y[1] )
VEE1 = VEE1/sqrt(sum(VEE1^2) )
VEE2 = VEE2/sqrt(sum(VEE2^2) )
###### get angle from north:
ANG = acos( sum(VEE1*VEE2) ) *180/pi
#### compare with h
print(paste(h$az, ANG, h$az-ANG) )
Run the code above in your browser using DataLab