Jump to content

Have problems to calculate the right PhaseAngle (kOS)


Recommended Posts

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°.thumb.php?api=SYNO.PhotoStation.Thumb&me

 

 

can someone help me ? 

Link to comment
Share on other sites

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

https://www.reddit.com/r/Kos/

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
Link to comment
Share on other sites

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

Edited by Steven Mading
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...