Skip to content

Commit

Permalink
fix true anomaly for 0 inclination and 0 eccentricity
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Stephens committed Jul 20, 2015
1 parent c514e87 commit 9067878
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/orbit.js
Expand Up @@ -82,8 +82,19 @@ Orbit.prototype.argumentOfPeriapsis = function argumentOfPeriapsis() {
};

Orbit.prototype.trueAnomaly = function trueAnomaly() {
var e = this.eccentricity();
var u = toDeg(Math.acos(Math.min(1, e.dot(this.r) / (e.norm() * this.r.norm()))));
var e = this.eccentricity(),
eNorm = parseFloat(e.norm().toFixed(5)),
n = this.nodeLine(),
nNorm = parseFloat(e.norm().toFixed(5)),
l, u;

if (eNorm === 0 && nNorm === 0) {
u = toDeg(Math.acos(Math.min(1, this.r.elements[0] / this.r.norm())));
} else {
l = (eNorm === 0) ? n : e;
u = toDeg(Math.acos(Math.min(1, l.dot(this.r) / (l.norm() * this.r.norm()))));
}

return this.r.dot(this.v) < 0 ? (360 - u) : u;
};

Expand Down

0 comments on commit 9067878

Please sign in to comment.