Create a mathematically correct ellipse

anyone has written a script for this ?

what is the algo ?

thanks
happy bl

1 Like

lol what an absurd response to a serious question. Do people think that 3d modeling doesnt reflect real world problems that are solved with mathematics? I’m doing an orbital model to create graphics for a powerpoint presentation to a global space conference.

I also was a bit puzzled, because the original astronomical problem was formulated in mathematics (of course), even if Kepler couldn’t prove it itself, so that’s the problem interest for mathematicians and the question:

Trying to code Kepler’s law as a function of time

seems to be typical (for me) application in physics (ask in a physics forum) and the anser is off-topic ?!?

So now i understand you special interest and count yourself lucky to have ask this here on BA and not on a physik forum :rofl:

Yes, so essentially I’ve got to plot an orbit that is equidistant from Earth and Mars at all/most times, with 36 satellites in that orbit around the sun, with them as evenly spread as possible. Of course due to orbital mechanics they are going to be closest together at perigee (when the orbit is closest to the sun) and furthest apart at apogee (furthest from the sun) because they move fastest at perigee and slowest at apogee while having the most ground to cover at apogee. Now, an orbit between Earth and Mars is not terribly eccentric. Earth’s eccentricity is 1.67% and Mars is about 9.7%. The equidistant orbit I’ve calculated has an eccentricity of 6.32 %. Then the orbital inclinations are also trying to fit between mars and earth equally, except of course both planets have different inclination but due to their orbits different longitudinal orientation, these two orbital planes are around 100 degrees away from each other, so this means the satellite orbit should have a longitude half way at 50 degrees and half the difference of the inclination… Thats all not hard to do, the real hard issue really is the keplerian motion spacing the satellites out around the orbit.
I’ve got preliminary data and plots here.

1 Like


Here’s the preliminary orbital plot. Red is Mars orbit, Blue is Earth, Green is the satellites.

1 Like

Sometimes the internet is a weird thing: the other day while i did a little research i didn’t found very useful stuff so i just made some testing with a liitle bit from a formular and nothing precise and it look quit good and now i looked again and i found Simulating a real solar system with 70 lines of Python code.

So, @RickyBlender seems to be interested in making a plugin, have fun :slight_smile:

interesting indeed

ellipse are sort of a difficult to calculate with high precision
and considering the orbit size even more so!
not certain if double precision is good enough to get high resolution on orbits

and having a constant distance is also difficult to do

i will see if i can test the last script

thanks
happy bl

Hej @mlorrey, I did google it myself, as I was curious if there really is no quick solution available that gives you the parameters at hand that you want.
I found the code in the link below fitting and utilized its essential part. I made a quick script that records keyframes for planet orbit animations. But you could also write the orbit data gathered into a mesh, just might need to be more careful to orbit just once. The script utilized two Objects that you have to create and name “MARS” and “EARTH” in blender. I dont know if you need a specific timeframe for the simulation (have a look at the code reference for its day to date mapping), but it doesnt sound like you need that.
So to use, create the objects, run the script, then run the animation.
So yeah, hope it helps.

Edit: Now my coffee is cold. :wink:

import bpy
import math
marsObj = bpy.data.objects["MARS"]
earthObj = bpy.data.objects["EARTH"]

sunX=0 
sunY=0 
sunZ=0 

scalingFactor = 0.75;
resolution = 20;   

def planet(planet,days):

    if planet == "MARS":
        planetAngle = 146.25
        perihelion = 207       # million km
        aperihelion = 249       # million km
        longitude = 336         # degrees
        year= 686.98           # earth days
    elif planet == "EARTH":
        planetAngle = 336.05
        perihelion = 147  
        aperihelion = 152
        longitude = 102
        year = 365.25
       
    # Distance from ellipse centre to sun
    focusDist = scalingFactor * (aperihelion - perihelion) / 2 
    
    # Ellipse axes
    major = scalingFactor * aperihelion - focusDist 
    minor = math.sqrt(major * major - focusDist * focusDist) 
    
    phi = longitude 
    cosPhi = math.cos(phi) 
    sinPhi = math.sin(phi) 
    
    # Angle relative the perihelion
    angle = planetAngle - phi 
    
    # Center of ellipse
    cx = sunX - focusDist * cosPhi 
    cy = sunY + focusDist * sinPhi 
    
    eccentricity = focusDist / major 
    angleConstant = 360 * major * minor / year 
    
      
    step = math.copysign( 1/resolution,days) 

    time  = 0
    while time < abs(days):
        
        time += resolution

        # Distance from sun
        r = major * (1 - eccentricity * eccentricity) / (1 + eccentricity * math.cos(angle)) 
        
        # Update angle around sun
        angle += step * angleConstant / (r * r) 

    
    r = major * (1 - eccentricity * eccentricity) / (1 + eccentricity * math.cos(angle)) 
                    
    # Position based on non-rotated ellipse
    x = r * math.cos(angle) + focusDist 
    y = r * math.sin(angle) 
    
    # Rotate based on ellipse rotation
    return (cx + x * cosPhi - y * sinPhi,
            cy - x * sinPhi - y * cosPhi,
            0) 
     
# No of frames to set
for i in range(750):
    
    day = i*30
    bpy.context.scene.frame_set(i)
    marsObj.location = planet("MARS",day)
    marsObj.keyframe_insert(data_path ="location", index =-1)
    
    earthObj.location = planet("EARTH",day)
    earthObj.keyframe_insert(data_path ="location", index =-1)

Scene

Thanks a lot, I can use this in future presentations. I can add in my own satellite constellation orbiting between these two planets. Really appreciate it!

Yeah could be used for that, just one more note, the orbiting animation itself was just meant as a demonstration. At its core this is just a method to calculate a concrete position at a given time. So you could also use it to visualize/plot the shape of the orbits or to calculate timebased evenly spread positions of your satellites on their individual orbit.

is there a script to make an ellipse with points at constant distance ?

i tried to do it but could not get high precision !

thanks
happy bl

Wow, this post has gone astronomical, Literally :smile:

I have started my google just looking to draw an ellipse and then have continued reading this thread till the end, I enjoyed the read, a Lot!

@mlorrey I hope your conference went well, hope to hear back from you on how it was.
@Okidoki I like what you came up with while doing your “casual” searches :wink:

Thanks All!
btw, I signed up to this website just to write you this comment :slight_smile: sooo, kudos

Just wondering how you would tweak this so that the vertices are closer together on the other end of the elipse, so that it’s more like in this animation? https://www.physics.unlv.edu/~jeffery/astro/orbit/kepler_2nd_law.html

Welcome :tada:
…well… the animation you gave a link to… just has more denser points on one side…

…and i really have to re-familiarize with the topic again… :wink: