-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Compute sun and moon positions #677
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
Changes from all commits
a13745e
fab8f1c
2c893a1
3bad847
0e219c5
75fcac4
9e52045
77e7116
7a44268
1b0ab53
927ea78
e130bde
35201b6
6bb9d2d
57284fe
dc2b76e
24ff9d5
508f45d
933c043
2840e56
d728d27
8815db0
336dfa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ define([ | |
'../Core/EncodedCartesian3', | ||
'../Core/BoundingRectangle', | ||
'../Core/Transforms', | ||
'../Core/computeSunPosition', | ||
'../Core/Simon1994PlanetaryPositions', | ||
'../Scene/SceneMode' | ||
], function( | ||
DeveloperError, | ||
|
@@ -29,7 +29,7 @@ define([ | |
EncodedCartesian3, | ||
BoundingRectangle, | ||
Transforms, | ||
computeSunPosition, | ||
Simon1994PlanetaryPositions, | ||
SceneMode) { | ||
"use strict"; | ||
|
||
|
@@ -182,18 +182,23 @@ define([ | |
uniformState._encodedCameraPositionMCDirty = true; | ||
} | ||
|
||
var sunPositionWC = new Cartesian3(); | ||
var sunPositionScratch = new Cartesian3(); | ||
|
||
var position = new Cartesian3(); | ||
var transformMatrix = new Matrix3(); | ||
function setSunAndMoonDirections(uniformState, frameState) { | ||
computeSunPosition(frameState.time, sunPositionWC); | ||
if (typeof Transforms.computeIcrfToFixedMatrix(frameState.time, transformMatrix) === 'undefined') { | ||
transformMatrix = Transforms.computeTemeToPseudoFixedMatrix(frameState.time, transformMatrix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We talked about this already, and I think it's a good idea. But I just wanted to call attention to it for everyone else. Basically, if the ICRF->Fixed transformation is not available (because the data is missing or even just not downloaded yet), we fall back on using the TEME->Pseudo Fixed transformation. If we don't do a good job of prefetching the ICRF data (which we're probably not, currently), this could result in an (imperceptible?) jump in the Sun and Moon position. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this line of code, we know |
||
} | ||
|
||
Cartesian3.normalize(sunPositionWC, uniformState._sunDirectionWC); | ||
Matrix3.multiplyByVector(uniformState.getViewRotation3D(), sunPositionWC, sunPositionScratch); | ||
Cartesian3.normalize(sunPositionScratch, uniformState._sunDirectionEC); | ||
position = Simon1994PlanetaryPositions.ComputeSunPositionInEarthInertialFrame(frameState.time, position); | ||
transformMatrix.multiplyByVector(position, position); | ||
Cartesian3.normalize(position, uniformState._sunDirectionWC); | ||
Matrix3.multiplyByVector(uniformState.getViewRotation3D(), position, position); | ||
Cartesian3.normalize(position, uniformState._sunDirectionEC); | ||
|
||
// Pseudo direction for now just for lighting | ||
Cartesian3.negate(uniformState._sunDirectionEC, uniformState._moonDirectionEC); | ||
position = Simon1994PlanetaryPositions.ComputeMoonPositionInEarthInertialFrame(frameState.time, position); | ||
transformMatrix.multiplyByVector(position, position); | ||
Matrix3.multiplyByVector(uniformState.getViewRotation3D(), position, position); | ||
Cartesian3.normalize(position, uniformState._moonDirectionEC); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/*global defineSuite*/ | ||
defineSuite(['Core/Simon1994PlanetaryPositions', | ||
'Core/JulianDate', | ||
'Core/TimeStandard', | ||
'Core/TimeConstants', | ||
'Core/Math', | ||
'Core/Matrix3', | ||
'Core/Cartesian3', | ||
'Core/Transforms'], | ||
function(PlanetaryPositions, | ||
JulianDate, | ||
TimeStandard, | ||
TimeConstants, | ||
CesiumMath, | ||
Matrix3, | ||
Cartesian3, | ||
Transforms) { | ||
"use strict"; | ||
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ | ||
|
||
|
||
// Values for the X Y and Z were found using the STK Components GeometryTransformer on the position of the | ||
// sun center of mass point and the earth J2000 reference frame. | ||
it('computes correct sun position', function() { | ||
var date = JulianDate.fromTotalDays(2451545.0, TimeStandard.TAI); | ||
var sun = PlanetaryPositions.ComputeSunPositionInEarthInertialFrame(date); | ||
var X = 26500268539.790234; | ||
var Y = -132756447253.27325; | ||
var Z = -57556483362.533806; | ||
expect(X).toEqualEpsilon(sun.x, CesiumMath.EPSILON4); //TODO | ||
expect(Y).toEqualEpsilon(sun.y, CesiumMath.EPSILON4); | ||
expect(Z).toEqualEpsilon(sun.z, CesiumMath.EPSILON4); | ||
|
||
date = JulianDate.fromTotalDays(2456401.5, TimeStandard.TAI); | ||
sun = PlanetaryPositions.ComputeSunPositionInEarthInertialFrame(date); | ||
X = 131512388940.33589; | ||
Y = 66661342667.949928; | ||
Z = 28897975607.905258; | ||
expect(X).toEqualEpsilon(sun.x, CesiumMath.EPSILON4); | ||
expect(Y).toEqualEpsilon(sun.y, CesiumMath.EPSILON4); | ||
expect(Z).toEqualEpsilon(sun.z, CesiumMath.EPSILON4); | ||
|
||
date = JulianDate.fromTotalDays(2455998.591667, TimeStandard.TAI); | ||
sun = PlanetaryPositions.ComputeSunPositionInEarthInertialFrame(date); | ||
X = 147109989956.19534; | ||
Y = -19599996881.217579; | ||
Z = -8497578102.7696457; | ||
expect(X).toEqualEpsilon(sun.x, CesiumMath.EPSILON4); | ||
expect(Y).toEqualEpsilon(sun.y, CesiumMath.EPSILON4); | ||
expect(Z).toEqualEpsilon(sun.z, CesiumMath.EPSILON4); | ||
}); | ||
|
||
// Values for X Y and Z were found using the STK Components GeometryTransformer on the Simon 1994 moon point and the earth | ||
// J2000 reference frame. | ||
it('computes correct moon position', function() { | ||
var date = JulianDate.fromTotalDays(2451545.0, TimeStandard.TAI); | ||
var moon = PlanetaryPositions.ComputeMoonPositionInEarthInertialFrame(date); | ||
var X = -291632410.61232185; | ||
var Y = -266522146.36821631; | ||
var Z = -75994518.081043154; | ||
expect(X).toEqualEpsilon(moon.x, CesiumMath.EPSILON4); | ||
expect(Y).toEqualEpsilon(moon.y, CesiumMath.EPSILON4); | ||
expect(Z).toEqualEpsilon(moon.z, CesiumMath.EPSILON4); | ||
|
||
date = JulianDate.fromTotalDays(2456401.5, TimeStandard.TAI); | ||
moon = PlanetaryPositions.ComputeMoonPositionInEarthInertialFrame(date); | ||
X = -223792974.4736526; | ||
Y = 315772435.34490639; | ||
Z = 97913011.236112773; | ||
expect(X).toEqualEpsilon(moon.x, CesiumMath.EPSILON4); | ||
expect(Y).toEqualEpsilon(moon.y, CesiumMath.EPSILON4); | ||
expect(Z).toEqualEpsilon(moon.z, CesiumMath.EPSILON4); | ||
|
||
date = JulianDate.fromTotalDays(2455998.591667, TimeStandard.TAI); | ||
moon = PlanetaryPositions.ComputeMoonPositionInEarthInertialFrame(date); | ||
X = -268426117.00202647; | ||
Y = -220468861.73998192; | ||
Z = -110670164.58446842; | ||
expect(X).toEqualEpsilon(moon.x, CesiumMath.EPSILON4); | ||
expect(Y).toEqualEpsilon(moon.y, CesiumMath.EPSILON4); | ||
expect(Z).toEqualEpsilon(moon.z, CesiumMath.EPSILON4); | ||
}); | ||
|
||
it('has the sun rising in the east and setting in the west', function() { | ||
//Julian dates for 24 hours, starting from July 6th 2011 @ 01:00 UTC | ||
var transformMatrix = new Matrix3(); | ||
var timesOfDay = []; | ||
for ( var i = 1; i < 25; i++) { | ||
var date = new Date('July 6, 2011'); | ||
date.setUTCHours(i, 0, 0, 0); | ||
timesOfDay.push(JulianDate.fromDate(date)); | ||
} | ||
var angles = []; | ||
for (i = 0; i < 24; i++) { | ||
transformMatrix = Transforms.computeIcrfToFixedMatrix(timesOfDay[i], transformMatrix); | ||
if (typeof transformMatrix === 'undefined') { | ||
transformMatrix = Transforms.computeTemeToPseudoFixedMatrix(timesOfDay[i], transformMatrix); | ||
} | ||
var position = PlanetaryPositions.ComputeSunPositionInEarthInertialFrame(timesOfDay[i]); | ||
transformMatrix.multiplyByVector(position, position); | ||
angles.push(CesiumMath.convertLongitudeRange(Math.atan2(position.y, position.x))); | ||
} | ||
//Expect a clockwise motion. | ||
for (i = 1; i < 24; i++) { | ||
expect(angles[i]).toBeLessThan(angles[i - 1]); | ||
} | ||
}); | ||
|
||
it('works without a time', function() { | ||
PlanetaryPositions.ComputeSunPositionInEarthInertialFrame(undefined); | ||
}); | ||
|
||
}); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying it "alters" the value of input x is a bit misleading. It's ok to just copy the doc right out of Components. The comment in the code in Components about the second modulus is useful as well (even if it's mispelled modules).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the doc from the existing negativePiToPi function right above this one. I'll change the doc for both.