It's not remotely obvious to me how to do this in a script though. Probably something to do with vectors I guess?
(this'd be one for the wikibook if we can figure it out, definitely
![Smile :)](./images/smilies/icon_smile.gif)
Malenfant wrote:For my planetary magnitudes script that I'm working on, I need to find the phase angle - the angle between the Sun-Body and Body-Observer lines.
It's not remotely obvious to me how to do this in a script though. Probably something to do with vectors I guess?
(this'd be one for the wikibook if we can figure it out, definitely).
Code: Select all
sun_planet_vector = planet:getposition() - sun:getposition()
obs_planet_vector = planet:getposition() - celestia:getobserver():getposition()
phase_angle = math.arcos(sun_planet_vector:normalize() ^ obs_planet_vector:normalize())
Malenfant wrote:Doesn't seem to work (it's acos, btw, not arcos). Keeps saying it expects a number in the phase_angle line but gets userdata instead. [\quote]
I'll keep fiddling with it, see if I can come up with something... Are you sure that ^ means Cross Product? I thought it was 'to the power of'. Oh, and doesn't cross product find the vector that's perpendicular to both the other vectors you put into it? Don't we need the dot product here?
Code: Select all
phase_angle = math.acos(sun_planet_vector:normalize() * obs_planet_vector:normalize())
Malenfant wrote:Aha, that did it (I think - gotta convert the display of phase_angle to degrees for it to make any sense to me but that's easy enough). Thanks muchly!
I should add that none of this is remotely clear to me from any of the CELX documentation that I'm using... I can see why Hank is so keen on the idea of getting stuff in the wikibook...