Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute sun and moon positions #677

Merged
merged 23 commits into from
Apr 27, 2013
Merged

Compute sun and moon positions #677

merged 23 commits into from
Apr 27, 2013

Conversation

hpinkos
Copy link
Contributor

@hpinkos hpinkos commented Apr 22, 2013

Resolves: #391 #337

Ported parts of Simon1994PlanetaryPositions, KeplarianElements and ModifiedKeplarianElements from components to compute the sun and moon positions. Updated UniformState to use the new sun and moon positions.

var translation = computeSimonEarthMoonBarycenter(date);
var axesTransformation = Quaternion.IDENTITY;
var translated = result.subtract(translation);
translated.rotate(axesTransformation, result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just skip this, because rotating a vector by identity results in the same vector.

var trueAnomaly = meanAnomalyToTrueAnomaly(meanLongitude - longitudeOfPerigee, eccentricity);
var type = chooseOrbit(eccentricity, 0.0);
if (type === 'Hyperbolic' && Math.abs(CesiumMath.NegativePiToPi(trueAnomaly)) >= Math.acos(- 1.0 / eccentricity)) {
throw new DeveloperError('invalid trueAnomaly.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to include the full exception message from Components: "The true anomaly of the hyperbolic orbit lies outside of the bounds of the hyperbola." Yeah, I don't really know what that means, either. Also it shouldn't ever happen for the Simon model. But there's no reason not to throw the better error message if you're going to check for it.

if (type === 'Hyperbolic' && Math.abs(CesiumMath.NegativePiToPi(trueAnomaly)) >= Math.acos(- 1.0 / eccentricity)) {
throw new DeveloperError('invalid trueAnomaly.');
}
var perifocalToEquatorial = perifocalToCartesianMatrix(argumentOfPeriapsis, inclination, rightAscensionOfAscendingNode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to say it, but there's an allocation here that needs to be changed to use a result parameter.

throw new DeveloperError('Kepler equation did not converge');
//TODO: Port 'DoubleFunctionExplorer' from STK components
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. Kepler's equation is going to converge for the reasonable orbits of the Earth-moon barycenter and the Moon. At least it better! Since we'll probably never do it, let's change this TODO to just a regular explanation comment: "STK Components uses a numerical method to find the eccentric anomaly in the case that Kepler's equation does not converge. We don't expect that to ever be necessary for the reasonable orbits used here." We try to avoid TODOs in master (though there are some), instead preferring GitHub issues for thing we might actually do, and comments of explanation for things we probably won't.

* Gets a point describing the motion of the Earth. This point uses the Moon point and
* the 1992 mu value (ratio between Moon and Earth masses) in Table 2 of the paper in order
* to determine the position of the Earth relative to the Earth-Moon barycenter.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Earth-centered inertial frame" here, too.

@hpinkos
Copy link
Contributor Author

hpinkos commented Apr 25, 2013

@kring anything else? Your diff comments above got off by a few lines, but I think I caught everything you mentioned.

* @return {Cartesian3} The result of the rotation
*
*/
Cartesian3.prototype.rotate = function(quaternion, result) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this, too, since it called the other one.

@kring
Copy link
Member

kring commented Apr 25, 2013

Almost done, just those couple of things left. Thanks for your patience with my endless comments.

@hpinkos
Copy link
Contributor Author

hpinkos commented Apr 25, 2013

@kring I appreciate your thoroughness. Anything else?

@kring
Copy link
Member

kring commented Apr 25, 2013

Tests pass, Sandcastle examples look good (especially the terrain one where you can see the sun and moon specular highlight), jsHint is happy. Code looks allocation-free!

Just one last problem, I promise! I just noticed that Simon1994PlanetaryPositions shows up as just PlanetaryPositions in the doc. You at least need to change the @exports line at the top, and possible rename var PlanetaryPositions as well - probably not a bad idea to do that whether you need to or not, actually, just for consistency.

@mramato
Copy link
Contributor

mramato commented Apr 26, 2013

@hpinkos just an FYI; we don't get automatic notification to every change, so when you are done with review comments, it's usually a good idea to write a quick "ready for another review" message. Otherwise @kring wouldn't know you finished the rename until he remembers to check. That being said, I'll let him merge this, since he's been the one reviewing it.

@kring
Copy link
Member

kring commented Apr 27, 2013

Looks good. Thanks, @hpinkos! Merging.

kring added a commit that referenced this pull request Apr 27, 2013
Compute sun and moon positions
@kring kring merged commit ed60594 into CesiumGS:master Apr 27, 2013
@hpinkos hpinkos deleted the computeSun branch May 8, 2013 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compute sun position
4 participants