Modeling Earth


Celestial coordinate systems

Read more: Transforming between coordinate systems


Spherical coordinates

import math

def sphericalcoord(r, theta, phi): # altitude, longitude, latitude
    x = r * math.sin(theta) * math.cos(phi)
    y = r * math.sin(theta) * math.sin(phi)
    z = r * math.cos(theta)
    return sphere_x, sphere_y, sphere_z

def cartesian_to_spherical(x, y, z): # z is up
    r = math.sqrt(math.pow(x, 2) + math.pow(y, 2) + math.pow(z, 2))
    theta = math.acos(z / r)
    phi = math.atan(y / x)
    return r, theta, phi

Using Numpy implementing from The sun's position in the sky.

import numpy as np
import math

spherecoord = np.array([r * math.sin(theta) * math.cos(phi),
                        r * math.sin(theta) * math.sin(phi), 
                        r * math.cos(theta)])


Ecliptic

t = 0 # time

ecliptic = np.array([math.cos(t), math.sin(t), 0])
ecliptic.reshape(3, 1)
ecliptic = np.matrix(ecliptic)


Equatorial

epsilon = math.radians(23.44) # earths tilt in radians

axialtilt = np.array([1,                 0,                 0,
                      0, math.cos(epsilon), math.sin(epsilon),
                      0, math.sin(epsilon, math.cos(epsilon))])
axialtilt.reshape(3, 3)
axialtilt = np.matrix(axialtilt)

equatorial = axialtilt * ecliptic


Sidereal day

A sidereal day is the time it takes for earth to make one revolution around it's axis of rotation so the stars line up in exactly the same place they started in the sky from one sidereal day ago.

Modular arithmetic

Modulo etc for timekeeping.

Barycentric coordinates/interpolation

Interpolate between three data points.