Trying to write some maths from Wikipedia in Javascript (sun position computation) -
i trying approximate position of sun in xyz threejs project.
i following maths found here: http://en.wikipedia.org/wiki/position_of_the_sun
following above, have written following javascript code:
var n = ((2440587.5 + (this.datemillis / 8.64e7)) - 2451545); var l = 280.460 + 0.9856474 * n; var g = 357.528 + 0.9856003 * n; l = (l + 360) % 360; g = (g + 360) % 60; var lambda = l + 1.915 * math.sin(g) + 0.0020 * math.sin(2 * g); var r = 1.00014 - 0.01671 * math.cos(g) - 0.00014 * math.cos(2 * g); var e = 23.439 - 0.0000004 * n; var x = (r * this.constants.earth_radius * 2) * math.cos(lambda); var y = (r * this.constants.earth_radius * 2) * math.cos(e) * math.sin(lambda); var z = (r * this.constants.earth_radius * 2) * math.sin(e) * math.sin(lambda); this.datemillis returned getmillisecond function of javascript date object. updated each frame time advances @ 1 hour every 2 seconds.
however must not correct not produce expected result. when apply computed x y z coordinates sun in threejs project, can see sun rotate around earth (sitting in 0,0,0) @ slow rate (rotating earth in few days instead of 24 hours).
i'm thinking might have angle calculations i'm not doing correctly (degrees/radians?) i'm not @ maths don't know i'm doing maybe misinterpreted wiki calculations.
if spot obvious i'm doing wrong , me fix this, appreciated!
thanks
edit: sun not rotating around earth in continous way - rotates clockwise/counterclockwise alternatively , jumps positions...
i cannot answer question know solved problem in threejs. there example running in architecture/engineering workflow on github on topic. sun position code here https://github.com/radio412/viewer/blob/gh-pages/sun-position.js
you can see being tapped directional light in threejs @ line 108 here: https://github.com/radio412/viewer/blob/gh-pages/va3c-viewer.js
Comments
Post a Comment