Figring out where missing parenthesis goes in Trigonometric functions formula

trinker

ggplot2orBust
#1
I trying to figure out a bounding box (locations within a square mile of a center point) on a globe. This is more complicated than the traditional Cartesian 2-D system. I found a site that claims to have it figured out and they're smarter than me so we'll trust it (be test the solution when I finish). I'm trying to implement this solution using R.

In one of the formulas they seem to be missing a bracket but give an equivalent formula. I figure smart math back ground people will be able to:

1. Determine where the missing bracket goes based on the equivalent formula
2. Determine if the equivalent formula is indeed equivalent
3. Determine if the writer actually knows what they're talking about

Here's the link: http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates#SphereRadius

The missing parenthesis appears be in equation (8):

Δlon = arccos( ( cos(r) - sin(latT) · sin(lat) ) / ( cos(latT) · cos(lat) )
= arcsin(sin(r)/cos(lat)) = 1.1202
I think they're saying these two are equivalent:

arccos( ( cos(r) - sin(latT) · sin(lat) ) / ( cos(latT) · cos(lat) )
and
arcsin(sin(r)/cos(lat))
Is that true?
==================

Is the following indeed missing a parenthesis? If so where does it go?
arccos( ( cos(r) - sin(latT) · sin(lat) ) / ( cos(latT) · cos(lat) )
I also emailed the author but thought I'd pose here too. I'll let you know if they provide any direction.

TR
 

Dason

Ambassador to the humans
#2
Code:
r <- .1570
lat <- 1.3963
lon <- -.6981

latT <- asin(sin(lat)/cos(r))

# Add paren at the end
acos((cos(r) - sin(latT)*sin(lat))/(cos(latT)*cos(lat)))
# Add paren before division
acos((cos(r) - sin(latT)*sin(lat)))/(cos(latT)*cos(lat))

# One should equal
asin(sin(r)/cos(lat))
# which should give 1.1202

# So the correct version is 
acos((cos(r) - sin(latT)*sin(lat))/(cos(latT)*cos(lat)))
 

trinker

ggplot2orBust
#4
For anyone who cares here this is as a function:

Code:
bounding_box <- function(lat, lon, dist) {

    ## Helper functions
    ang_rad <- function(miles) miles/3958.756
    `%+/-%` <- function(x, margin){x + c(-1, +1)*margin}
    deg2rad <- function(x) x/(180/pi)
    rad2deg <- function(x) x*(180/pi)
    lat_range <- function(latr, r) rad2deg(latr %+/-% r)
    lon_range <- function(lonr, dlon) rad2deg(lonr %+/-% dlon)
       
    r <- ang_rad(dist)
    latr <- deg2rad(lat)
    lonr <- deg2rad(lon)
    dlon <- asin(sin(r)/cos(latr))

    m <- matrix(c(lon_range(lonr = lonr, dlon = dlon), 
        lat_range(latr=latr, r=r)), nrow=2, byrow = TRUE)

    dimnames(m) <- list(c("lng", "lat"), c("min", "max"))
    m
}

bounding_box(42.96318, -78.85885, 1)
Note that it takes distance in miles and gives in regular (what I call regular lon and lat coordinates).