- (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); }