Problem background

You must be curious , The moon moves in a circle around the earth , The earth goes around the sun again , The sun goes around the Milky way ……. Then take any one of the rotation centers as the relative coordinate center , What is the trajectory of the moon ?
Assuming the sun as the center , So what's the trajectory of the moon ?
In this paper, the method of constructing coordinate system from mathematics , On the orbit equation of any star relative to other stars , And use python matplotlib This powerful drawing library simulates the motion model of sun, earth and moon

model building

Now suppose the sun - earth - The moon system , The sun is the center of rotation , The angular velocity of the earth relative to the sun is ω1ω1 Uniform circular motion of , The moon is relative to the earth ω2ω2 Uniform circular motion of .

Building a three-dimensional coordinate system with the sun as the origin , I.e. sun coordinate point (x0,y0,z0)(x0,y0,z0) = (0,0,0)(0,0,0)
Now suppose the orbit plane of the earth's revolution ( Ecliptic ) stay x-y On the axis plane .

Known orbital plane of the moon ( Baidaomian ) And ecliptic ( The plane of the earth's orbit ) Keep it 5.145 396° Angle between , Namely and x-y The axis plane is 5.145 396° Angle between

As a result of x-y The included angle of the axis plane can be in any direction , Setting the orbit surface of the moon for modeling convenience y Axis tilt up 5.145 396° And in the initial state : sunlight , earth , The moon in y-z On the plane ( For later use
φφ Represents the fixed angle between the moon's orbit plane and the earth's orbit plane )
Suppose the radius of the earth's revolution is r1r1, The revolution radius of the moon is r2r2,
For the earth , Assume that the t The coordinate of the time is (x1,y1,z1)(x1,y1,z1), There are

⎧⎩⎨⎪⎪x1=x0+r1⋅cos(ω1t)y1=y0+r1⋅sin(ω1t)z1=z0+0{x1=x0+r1⋅cos⁡(ω1t)y1=y0+r1⋅sin⁡(
ω1t)z1=z0+0
Now model the trajectory of the moon : arbitrarily t time , The orbit of the moon satisfies the following equation
{z2=z1+(y2−y1)⋅tanφ(x2−x1)2+(y2−y1)2+(z2−z1)2=r22{z2=z1+(y2−y1)⋅tan⁡φ(x2−x1)2+(
y2−y1)2+(z2−z1)2=r22
The initial direction vector of the moon is (0,cosφ,sinφ)(0,cos⁡φ,sin⁡φ)
stay t time , The angle of rotation of the moon ω2tω2t, The direction vector is (x2−x1,y2−y1,z2−z1)(x2−x1,y2−y1,z2−z1)
From the angle formula of vector, there are ,
ω2t=(y2−y1)⋅cosφ+(z2−z1)⋅sinφω2t=(y2−y1)⋅cos⁡φ+(z2−z1)⋅sin⁡φ
Simultaneous up formula , Available
⎧⎩⎨⎪⎪⎪⎪⎪⎪x2=x1+r2⋅sin(ω2t)y2=y1+r2⋅cos(ω2t)cosφ(1+tan2φ)z2=z1+(y2−y1)⋅tanφ{x2=x
1+r2⋅sin⁡(ω2t)y2=y1+r2⋅cos⁡(ω2t)cos⁡φ(1+tan2⁡φ)z2=z1+(y2−y1)⋅tan⁡φ

python realization

It can be known by referring to relevant materials
Distance between sun and earth : about 1.5 100 million kilometers , It's an astronomical unit .
Distance between the moon and the earth : about 38.4 Thousands of meters
therefore r1r2=390.625r1r2=390.625

Out of 3D Intuitiveness of drawing , Suppose here r1=10r1=10,r2=1r2=1
And because the earth goes around the sun once , It's exactly 12 months , That is to say, the rotation speed of the moon around the earth is the rotation speed of the earth around the sun 12 times
Therefore, it can be set ω1=2πω1=2π, ω2=24πω2=24π

t from 0 ~ 1 It means the revolution of a star , python The code model is implemented as follows :
import numpy as np import matplotlib as mpl mpl.use("TkAgg") from matplotlib
import pyplot as plt from mpl_toolkits.mplot3d import Axes3D import
matplotlib.animationas animmation r1 = 10 r2 = 1 omega1 = 2 * np.pi omega2 = 24
* np.pi phi =5.1454 * np.pi / 180 def update(data): global line1, line2 , line3
line1.set_data([data[0], data[1]]) line1.set_3d_properties(data[2])
line2.set_data([data[3], data[4]]) line2.set_3d_properties(data[5])
line3.set_data([data[6], data[7]]) line3.set_3d_properties(data[8]) return
line1,line2,line3,def init(): global line1, line2, line3 ti = 0 t =
t_drange[np.mod(ti, t_dlen)] xt1 = x0 + r1 * np.cos(omega1 * t) yt1 = y0 + r1 *
np.sin(omega1 * t) zt1 = z0 +0 xt2 = xt1 + r2 * np.sin(omega2 * t) yt2 = yt1 +
r2 * np.cos(omega2 * t)/(np.cos(phi) * (1 + np.tan(phi) ** 2)) zt2 = zt1 + (yt2
- yt1) * np.tan(phi) xt21 = xt1 + r2 * np.sin(2 * np.pi * t_range) yt21 = yt1 +
r2 * np.cos(2 * np.pi * t_range)/(np.cos(phi) * (1 + np.tan(phi) ** 2)) zt21 =
zt1 + (yt21 - yt1) * np.tan(phi) line1, = ax.plot([xt1], [yt1], [zt1], marker=
'o', color='blue',markersize=8) line2, = ax.plot([xt2], [yt2], [zt2], marker='o'
, color='orange',markersize=4) line3, = ax.plot(xt21, yt21, zt21, color='purple'
)return line1,line2,line3 def data_gen(): #global x0,y0,z0,ti, t_drang,
t_range, omega1, omega2, phi global x0,y0,z0,t_dlen #while true: data = [] for
tiin range(1,t_dlen): t = t_drange[ti] xt1 = x0 + r1 * np.cos(omega1 * t) yt1 =
y0 + r1 * np.sin(omega1 * t) zt1 = z0 xt2 = xt1 + r2 * np.sin(omega2 * t) yt2 =
yt1 + r2 * np.cos(omega2 * t)/(np.cos(phi) * (1 + np.tan(phi) ** 2)) zt2 = zt1
+ (yt2 - yt1) * np.tan(phi) xt21 = xt1 + r2 * np.sin(2 * np.pi * t_range) yt21
= yt1 + r2 * np.cos(2 * np.pi * t_range)/(np.cos(phi) * (1 + np.tan(phi) ** 2))
zt21 = zt1 + (yt21 - yt1) * np.tan(phi) data.append([xt1, yt1, zt1, xt2, yt2,
zt2, xt21, yt21, zt21])return data #yield (xt1, yt1, zt1, xt2, yt2, zt2, xt21,
yt21, zt21) t_range = np.arange(0, 1 + 0.005, 0.005) t_drange = np.arange(0, 1,
0.005 ) t_len = len(t_range) t_dlen = len(t_drange) #sun's coordination x0 = 0
y0 =0 z0 = 0 #earth's orbit x1 = x0 + r1 * np.cos(omega1 * t_range) y1 = y0 +
r1 * np.sin(omega1 * t_range) z1 = z0 + np.zeros(t_len)#moon's orbit x2 = x1 +
r2 * np.sin(omega2 * t_range) y2 = y1 + r2 * np.cos(omega2 *
t_range)/(np.cos(phi) * (1 + np.tan(phi) ** 2)) z2 = z1 + (y2 - y1) *
np.tan(phi) f = plt.figure(figsize=(6,6)) ax = f.add_subplot(111,projection='3d'
)#plt.rcParams['animation.ffmpeg_path'] = r"C:\Program Files\ffmpeg\bin\ffmpeg"
#plt.rcParams['animation.convert_path'] = r"C:\Program
Files\ImageMagick-7.0.7-Q16\magick.exe" ax.set_aspect('equal') ax.set_title(
"Sun-Earth-Moon Model") ax.plot([0], [0], [0], marker='o', color= 'red',
markersize=16) ax.plot(x1, y1, z1, 'r') ax.plot(x2, y2, z2, 'b')
ax.set_xlim([-(r1 +2), (r1 + 2)]) ax.set_ylim([-(r1 + 2), (r1 + 2)])
ax.set_zlim([-5, 5]) # line1 update Earth's track dynamically # line2 update
Moon's track dynamically # line3 update Moon's orbit to earth line1, =
ax.plot([], [], [], marker='o', color='blue',markersize=8,animated = True)
line2, = ax.plot([], [], [], marker='o', color='orange',markersize=4,animated =
True) line3, = ax.plot([], [], [], color='purple',animated = True) #red sphere
for Sun, blue sphere for Earth, orange sphere for Moon ani =
animmation.FuncAnimation(f, update, frames = data_gen(), init_func =
init,interval =20) #ffwriter = animmation.ffmpegwriter(fps = 200)
#ani.save('planet.gif', writer='imagemagick', fps=40) #ani.save('planet.gif',
writer = ffwriter) plt.show()
( notes : The animation saving of the above code annotation part needs to be installed ffmpeg perhaps imagemagick Support for )
Above code , adopt matplotlib animation Demonstrated the sun - earth - Animation of the moon's trajectory model
( Red dots represent the sun , Blue dots represent the earth , The orange dots represent the moon , The red track indicates the orbit of the earth , The purple track indicates the moon's orbit relative to the earth , The blue track represents the moon's orbit relative to the sun ):

It can be found that : The moon is spiraling in the earth's orbit , This is consistent with the fact .
The model here assumes that the sun is the center of a stationary coordinate system , If we bring it back to the center of the galaxy , Let the Sun move , What will be the trajectory of the moon ? It's not really hard to achieve , As long as you're right (x0,y0,z0)(x0,y0
,z0) Just assign the equation , You can try what you are interested in .

in addition , You can also use the above model to simulate the rotation model , Because the rotation period of the moon is the same as that of its orbit around the earth ,

Modify the above code slightly , Replace the sun with the earth , Replace the earth with the moon , The orbit of the original moon as its orbit , A yellow ball indicates one of its faces ( It can be set to face the earth at the beginning ). By setting the angular velocity the same , You can see it directly —— Why can't we always see the other side of the moon on earth .

of course , If you think the model is too simple , Want to be closer to reality , You can also set the earth's orbit to an ellipse , It's also very easy to achieve , As long as you know the parametric equation of the ellipse .

Finally, Fourier series . yes , You should have found out : Infinite iteration of star motion , Is the Fourier series expansion of a curve , As long as the number of iterations is limited , The orbits of stars must be periodic .

Technology
©2019-2020 Toolsou All rights reserved,
use mt-range The effect of changing a number with the sliding bar is realized experiment 11-1-6 Output string at specified position (20 branch )( Essence 2020 year 6 month 3 Daily update ) TypeScript Detailed explanation of Chinese interface mysql Modify primary key Android 11 Official release !keras Data generator -- Data enhancement Vue Transfer parameters and receiving of page Jump Shortest path Dijkstra (Python3)c Language rose advertising code el-select At the same time label and value value