Created
July 8, 2011 02:58
-
-
Save aaronpk/1071024 to your computer and use it in GitHub Desktop.
yay trig!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var G = google.maps.geometry.spherical; | |
| var A = placeMarker.getPosition(); | |
| var B = event.latLng; | |
| var radians = function(degrees) { return degrees * (Math.PI/180); }; | |
| // Compute the angle from A to B | |
| var beta = G.computeHeading(A, B); | |
| // The angle of the second triangle is 45 degrees plus the previous angle | |
| var gamma = 45 + beta; | |
| // The radius of the circle is cos(gamma) * distance from A to B | |
| var x = G.computeDistanceBetween(A, B); | |
| radius = Math.cos(radians(gamma)) * x; | |
| placeMarkerHandle.setPosition(G.computeOffset(A, radius, -45)); | |
| for(var i=0; i<2; i++) { | |
| circles[i].circle.setRadius(radius - (i*3)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment