简体   繁体   中英

Ursina / Python - How do I make it so update() modifies positions from coordinates instead of time

I am trying to make an animation of the Sun-Earth-Moon system on Ursina with python by using Newton's law of gravitation with the sympletic integration. My problem is I don't know how to make the entities move by giving them positions at different times, I feel like you are only able to make them move by assigning each entity a function of time `

positons = [[ 0.00000000e+00  0.00000000e+00 -1.66774382e-01  9.69067588e-01
  -4.35526765e-01  9.85610511e-01]
 [ 0.00000000e+00  0.00000000e+00 -1.68497848e-01  9.68769962e-01
  -4.37721005e-01  9.79750463e-01]
 [-1.59474289e-12  9.16713058e-12 -1.70220804e-01  9.68469320e-01
  -4.39790170e-01  9.73882842e-01]
 ...
 [-2.27069908e-07  5.59350368e-07 -7.17772272e-01  6.76844085e-01
  -6.36398380e-01  4.38107193e-01]
 [-2.28638915e-07  5.62267372e-07 -7.18980419e-01  6.75586087e-01
  -6.32080373e-01  4.39241274e-01]
 [-2.30214659e-07  5.65190707e-07 -7.20186344e-01  6.74325991e-01
  -6.27807854e-01  4.40505728e-01]]

` where each line is [sun_x,sun_y,earth_x,earth_y,moon_x,moon_y] and each column is for a different iteration (I used dt=0.1).

I don't know Ursina very well and can't find any documents that would help.`

from ursina import *
import numpy as np

`def update():
    for entity in entities:`                           
        entity.rotation_y += time.dt * 100          
    
app = Ursina() 

entities = [] 
sun = Entity(model='sphere', color=color.yellow, scale=1)
earth = Entity(parent=sun,model='sphere', color=color.blue,position=(-0.1667743823220, 0, 0.9690675883429), scale=0.4)
moon = Entity(parent=earth,model='sphere', color=color.white,position=(-0.1694619061456, 0, 0.9692330175719), scale=0.3)
entities.append(sun)
entities.append(earth)
entities.append(moon)

app.run()

I used this as a start but it doesn't show the real trajectory of the pl.nets and is only time dependant, it is also using the 'parent' term which has no real physical/ astronomy meaning.

I'd like to find a way to code something like that:

def update():
    
    earth.x=#the position x of the earth at a set time
    earth.y=#the position y of the earth at a set time
    moon.x=#the position x of the moon at a set time
    moon.y=#the position y of the moon at a set time

maybe with a loop inside the update() to make them move for a set dt? Thank you for reading and helping!

Dont you maybe wanna use something like

Moon.anmiate_rotation(*rotation here*,*duration*,*kwargs*)

And so on Its easier that way And if you want it looping i cant really tell you how right now without confirming If you wan it to go different rotation u can setup a next animation with invoking another Its just how ive done some of my animations Maybe theres a better way to do it.

Def sleep():

    Moon.anmiate_rotation(*rotation here*,*duration*,*kwargs*)

Invoke(sleep,delay =*delay)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM