Skip to content

Instantly share code, notes, and snippets.

@se5a
Created August 9, 2016 06:44
Show Gist options
  • Save se5a/a0858e45146a7a08dc7f026c612297a4 to your computer and use it in GitHub Desktop.
Save se5a/a0858e45146a7a08dc7f026c612297a4 to your computer and use it in GitHub Desktop.
angle from centre point of an ellipse to an orbiting body.
private float GetStartArcAngle()
{
_focalDistance = (float)_orbitDB.Eccentricity * _orbitElipseWidth /2;
//since the _focalDistance is only an X component we dont' bother calculating the Y part of the matrix
double focalX = (_focalDistance * Math.Cos(_rotation * Math.PI / 180)); // - 0 * Math.Sin(_rotation * Math.PI / 180));
double focalY = (_focalDistance * Math.Sin(_rotation * Math.PI / 180)); // + 0 * Math.Cos(_rotation * Math.PI / 180));
//addt the body posistion
Vector4 offsetPoint = new Vector4(focalX, focalY, 0, 0) + _bodyPositionDB.RelativePosition;
//find the angle to the offset point
float angle = (float)(Math.Atan2(offsetPoint.Y, offsetPoint.X) * 180 / Math.PI);
//subtract the _rotation, since this angle needs to be ralitive to the elipse, and the elipse gets _rotated
angle -= _rotation;
//and finaly, normalise it useing modulo arrithmatic.
angle = angle % 360;
if (angle < 0)
angle += 360;
return angle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment