Created
March 29, 2011 08:55
-
-
Save stan1y/892028 to your computer and use it in GitHub Desktop.
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
| - (StellarPosition) getOribitOf:(StellarObject*)target; | |
| { | |
| //find intersection of line (position.x, position.y)..(target.x, target.y) | |
| //with circle around (target.x, target.y) with radius 'orbitRadius' | |
| //current angle to target | |
| double angleRadians = [self angleTo:[target position]]; | |
| //get point with angle on circle with R=orbitRadius, center (target.x, target.y) | |
| double pointX = [target position].x + orbitRadius * cos(angleRadians); | |
| double pointY = [target position].y - orbitRadius * sin(angleRadians); | |
| StellarPosition intersection = { pointX, pointY }; | |
| return intersection; | |
| } | |
| - (double) angleTo:(StellarPosition)pos | |
| { | |
| double a = pos.x - position.x; | |
| double b = pos.y - position.y; | |
| //the cot(angle) = a/b -> angle = acot(a/b) = Pi - atan(b/a) | |
| return Pi - atan(b / a); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment