Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Elliptical Orbit Tilt Help

Discussion in 'Scripting' started by Filtiarn_, May 13, 2022.

  1. Filtiarn_

    Filtiarn_

    Joined:
    Jan 24, 2013
    Posts:
    173
    I am trying to tilt my elliptical on x axis. For most part it kinda works but I got 2 problems. First I want to tilt by degrees (inclination parameter) but big issue when I do inclination the orbit stretches on x axis. I am not the best at math but I am trying to learn and use this as practice but yea I am having trouble with inclination / tilt.

    Here is code below.
    Code (CSharp):
    1.  public static Vector3 MathGetOrbitPositionInclined(float anomaly, float semiMajorLength, float semiMinorLength, float inclination, float centreX, float centreY)
    2.     {
    3.         //Anomaly
    4.         Vector3 position = Vector3.zero;
    5.         position.x = (Mathf.Cos(anomaly) * semiMajorLength + centreX);
    6.         position.z = (Mathf.Sin(anomaly) * semiMinorLength + centreY);
    7.  
    8.         //Inclination
    9.         position.y = Mathf.Cos(anomaly) * inclination * Mathf.PI * 2;
    10.  
    11.         return position;
    12.     }
    Here are pictures. You can see inclination value in inspector.
    Screen Shot 2022-05-12 at 11.02.52 PM.png
    Screen Shot 2022-05-12 at 11.03.09 PM.png
    Screen Shot 2022-05-12 at 11.03.24 PM.png
     
  2. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    442
    What's happening here is that you aren't actually rotating your ellipse, you are shearing it by extending it along the Y axis. This makes the ellipse visually longer, but doesn't actually stretch it in the X.

    The way to do this would be:

    Code (CSharp):
    1.  
    2.         float untiltedX = Mathf.Cos(anomaly) * semiMajorLength;
    3.         position.x = (untiltedX * Mathf.Cos(inclination)) + centreX;
    4.         position.z = (Mathf.Sin(anomaly) * semiMinorLength + centreY);
    5.         //Inclination
    6.         position.y = untiltedX * Mathf.Sin(inclinaton);
    IIRC Sin and Cos use Radians rather than degrees, but Mathf provides scale values to convert between the two as necessary.
     
    Last edited: May 13, 2022
    Filtiarn_ likes this.
  3. Filtiarn_

    Filtiarn_

    Joined:
    Jan 24, 2013
    Posts:
    173
    Thanks so much. Here is my end result with degrees implemented. I made it more step by step for me to understand I know I am calculating but I think its better for readability and understanding for myself. Thanks again.

    Code (CSharp):
    1.  
    2. public static Vector3 MathGetOrbitPositionInclined(float anomaly, float semiMajorLength, float semiMinorLength, float inclination, float centreX, float centreY)
    3.     {
    4.         //Inclination To Radians From Degrees
    5.         inclination *= Mathf.Deg2Rad;
    6.  
    7.         //Position (No Centre)
    8.         Vector3 position = Vector3.zero;
    9.         position.x = Mathf.Cos(anomaly) * semiMajorLength;
    10.         position.z = (Mathf.Sin(anomaly) * semiMinorLength);
    11.  
    12.         //Inclination
    13.         position.y = Mathf.Sin(inclination) * position.x;
    14.         position.x = Mathf.Cos(inclination) * position.x;
    15.  
    16.         //Centre
    17.         position.x += centreX;
    18.         position.z += centreY;
    19.  
    20.         //Return Position
    21.         return position;
    22.     }
    23.  
     
    Last edited: May 13, 2022