Jump to content

kOS: triangulation of angels results in "NaN" Error


inoculator

Recommended Posts

EDIT: Sorry... I think I got the error: ARCTAN has to be used, not ARCSIN..... But I will update, as soon as I got a solution.

............................

Hi all

I try to calculate the relative time to a transfer node on an orbit around kerbin.

I would like to use the vector "kerbin to mun" and "kerbin to ship" to get the relative angels to calculate the way around the ship orbit until the node to be added.

Here is some code to get You to the point:

//calculating mun transfer node

//get mun vector
set mun_vec to kerbin:position-mun:position.

//get ship vector
set ship_vec to kerbin:position-ship:position.

//get mun triangle
set am to mun_vec:z.
set bm to mun_vec:x.
set cm to mun_vec:mag. //always 12.000.000m

//get angle of alpha relative to normalized quadrant (not finished yet)
if am >0 and bm >0 {
set arc_m to arcsin(am/bm).
set qm=1.
}
if am >0 and bm <0 {
set arc_m to arcsin(am/bm).
set qm=2.
}
if am >=0 and bm >=0 {
set arc_m to arcsin(am/bm).
set qm=3.
}
if am >=0 and bm >=0 {
set arc_m to arcsin(am/bm).
set qm=4.
}

print "am=" + am.
print "bm=" + bm.
print "cm=" + cm.
print "arc_m=" + arc_m.

The code is not ready yet, because I got stuck at the "arcsin".

If the Mun in relative 0-45° off-set X-axis (am < bm), the arcsin is ok.

If the Mun is relative 45-90° off-set X-axis (am > bm) the arcsin fails (Tried to push NaN into the stack).

If I calculate with any pocket calculator I got no issues, regardless in which quadrant of the circle I am.

If I got the documentation right, there are still some issues with floating point operations in kOS.

Is this one of the issues, that come with this?

At the moment I try to get around this problem by setting a virtual X-axis to -45° off real x-axis, but somehow I fear, this will not solve this?!

Am I wrong? Do I miss anything?

br

Carsten

Edited by inoculator
Error: ARCTAN not ARCSIN
Link to comment
Share on other sites

EDIT: Sorry... I think I got the error: ARCTAN has to be used, not ARCSIN..... But I will update, as soon as I got a solution.

Correct. ArcSin requires a valid possible sin value as input, something in the range [-1..1]. NaN means "can't be represented as a real number". You get NaN either from imaginary numbers (i.e. sqrt() of a negative number), or from trig that is impossible (like ARCSIN(1.5).)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...