• 0

# Have problems to calculate the right PhaseAngle (kOS)

## Question

Hey,

i have problems to calculate the right PhaseAngle with kOS.

here my Script:

```function CurrentPhaseAngle{
parameter origin.
parameter destination.

set normal to  origin:OBT:POSITION:NORMALIZED.
set projected to VECTOREXCLUDE(normal,destination:POSITION).
set result to VECTORANGLE(origin:POSITION, projected).
if VDOT(VCRS(origin:POSITION, projected), normal) < 0
{
return 360 - result.
}
else
{
return result.
}
}

set currentPhase to CurrentPhaseAngle(Kerbin,Duna).

print "CurrentPhaseAngle:"+ currentPhase.```

Result is i my example 90° to from Kerbin to Duna but transfer Window Planer says it's 119°.

can someone help me ?

## Recommended Posts

• 0

image hosted on 192.168.192.2 - nice

looking at your script - seems you're not getting the definition right. phase angle zero isn't the direction of destination - it's your own planet prograde.

##### Share on other sites
• 0

The best place for kOS advice is Reddit. (meanwhile, autocorrect reckons for iOS advice, go to Redditch)

I see you have a variable called normal that you set to a normalized vector. Are you aware these can have very different meanings? Normal is usually used to mean at 90° to the plane of the orbit. Using :normalized returns a vector in the same direction, just reduced to a length of one unit.

Edit 2: wish I could help, but I've not got my head around vector exclusion yet!

Edited by ElWanderer
darned autocarrot

##### Share on other sites
• 0

Don't use SHIP:OBT:POSITION, that's the position relative to the center of the universe which is YOU in kOS's reckoning, so you're taking a magnitude near-zero vector and stretching it out to length 1 when you normalize it.  It's going to be super fiddly which way that's pointing.

If you're looking for a vector where you guarantee you know the origin of it, use vector subtraction to force it to work no matter what the underlying XYZ looks like.

Try (object:POSITION - BODY:POSITION) to get a vector you know for certain means a vector from a body to the object, whatever object happens to be.

Also be aware that the kind of calculation I'm speaking of presumes that origin and destination are both in the same SOI and share the same parent body (i.e. going from Kerbin to Duna, it's using Sun as the body they both orbit.)  That's not wrong, you just need to ensure you understand that when doing their math.  If you tried to transfer from, say, Kerbin to Ike rather than from Kerbin to Duna, the fact that Ike's parent body isn't the Sun like Kerbin's is could cause problems if you don't account for it.  I'd just make it explicit by passing a third parameter, the common body they share, and then using that as the origin point for all your vector position subtractions).

## 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.