Shared Math Utilities

Overview

services/tick-engine/src/math_utils.py centralises physical constants and basic vector operations used across the tick-engine service. Before this module, each file defined its own copies of _G, STANDARD_GRAVITY, and vector helpers, risking value drift and duplication.

Constants

Symbol Value Description
_G 6.6743e-11 Gravitational constant (m^3 kg^-1 s^-2)
TWO_PI 2 * math.pi Full circle in radians
STANDARD_GRAVITY 9.80665 Standard gravitational acceleration (m/s^2)

Vector functions (3-tuples)

  • vec_mag(v) – magnitude
  • vec_sub(a, b) – subtraction (a - b)
  • vec_add(a, b) – addition (a + b)
  • vec_scale(v, s) – scalar multiplication
  • vec_dot(a, b) – dot product
  • vec_cross(a, b) – cross product
  • vec_normalize(v) – unit vector (returns zero if magnitude < 1e-10)

Redis extraction

  • extract_pos(data) – position tuple from Redis hash dict
  • extract_vel(data) – velocity tuple from Redis hash dict
  • extract_pos_vel(data) – (position, velocity) pair from Redis hash dict

Import chain

Modules that previously defined their own copies now import from math_utils and re-export under underscore-prefixed names for backward compatibility:

  • automation_helpers re-exports STANDARD_GRAVITY, _extract_pos, _extract_pos_vel, _vec_mag, _vec_sub, _vec_dot, _vec_normalize
  • automation_orbital re-exports _G
  • orbital imports _G as G

Downstream modules (automation_maneuvers, maneuver_interplanetary, maneuver_landing, maneuver_ascent, trajectory_planner) import through these chains or directly from math_utils.

qlaw.py retains its own independent _G and vector math for performance isolation.


Back to top

Galaxy — Kubernetes-based multiplayer space game

This site uses Just the Docs, a documentation theme for Jekyll.