Did I get the trig right?
May 13, 2007 6:49 PM   Subscribe

Does my documentation accompanying this JavaScript function as implemented on this page of my site demonstrate an adequate understanding of the use of trigonometric functions therein?

I cribbed the code from an unofficial Google Maps API example site and modified it heavily for my own purposes, but it's been so long since I've studied or used trigonometric functions that actually figuring out how the damned thing works has been a hellish struggle.

My normal social circle was not equipped to help me; even my elder sister's college education in mathematics, having been dulled by teaching basic algebra to seventh-graders for years on end, was able to provide only a modicum of assistance.

So, did I get it right?
posted by The Confessor to Computers & Internet (1 answer total)
 
Looks right to me, though IANAT (I am not a trigonometer).

Also, another more intuitive way of deriving the same formulas you got is to remember that sin(theta) and cos(theta) are defined as the x and y coordinates, respectively, of the point on a circle of radius 1 that intersects with a line coming out of the origin at angle theta, and all you're doing is scaling and recentering that point.

<PEDANTRY TYPE="extreme">
This may or may not be helpful to you, but the way I think of it is: first you compute sin and cos, which give you the x and y coordinate of the point you want, supposing that where you started on the map is the origin and whatever your radius is counts as exactly one unit. Now, you've got the right answer at this point, but you've got it in some very inconvenient units --- rather than having latitudes and longitudes (which you can think of as a number of km north and east from (0°0'N, ,0°0'W), you've got it it in terms of a number of radius-distances away from your starting point. But no matter: since sin(theta) told you that the point you're after was (say) .7877 radius distances east of your starting point, you can convert radius distances to km distances just by multiplying by the length of the radius in km: .7877*r. [If you want to be really crystal clear about why this works, consider that sin(theta) told us that the x coordinate was .7877 radius-distances east of the origin, and we know that there are h kilometers per radius distance, so .7877 radius-distances * r km/radius-distance = .7877 * r.]

Now since the latitude/longitude system doesn't work in km, we have to adjust this again by multiplying by another constant that represents kilometers per degree latitude (I'm assuming this is your latConv number [well, its inverse]). So now we know that .7877*r*latConv [or more generally sin(theta)*r*latConv] is the number of degrees away our target point's latitude is from our start point. Since we know how many degrees away the start point is from 0°0'W, we just add that in and we know the latitude of our target point. Now do the same thing for longitude, and you're done! Yay!

And note that those formulas come out to what you've got there in code.
</PEDANTRY>
posted by jacobm at 7:52 PM on May 13, 2007


« Older What is the best style/brand knee-brace for ACL?   |   What's Up With My Flu/Cold? Newer »
This thread is closed to new comments.