def apply_forces(self): F = Vector3D(0.0, 0.0, 0.0) G = 66743.e-15 step = {"Hours": 3600, "Minutes": 60} boom = False for planet in self.p_positions: planet_pos = self.p_positions[planet] planet_size = self.p_sizes[planet] planet_mass = self.p_masses[planet] d = self.pos.distance(planet_pos) if d < planet_size: boom = True F_val = (G * self.total_mass() * planet_mass) / (AU_to_m(d)**2) F += F_val * (planet_pos - self.pos) / d self._g_force = F return not boom
from CreateMatrix import createMatrix from vector3d import Vector3D p0 = Vector3D(0, 0, 0) p1 = Vector3D(50, 0, 0) p2 = Vector3D(0, 0, 100) (origin, ax, ay, az) = createMatrix(p0, p1, p2) print(origin, ax, ay, az)
def test_vector3d_more_than_3_elements(self): self.assertRaises(ValueError, lambda: Vector3D([1, 2, 3, 4])) self.assertRaises(ValueError, lambda: Vector3D([1, 2, 3, 4, 5])) self.assertRaises(ValueError, lambda: Vector3D([1, 2, 3, 4, 5, 6]))
def test_vector3d_less_than_3_elements(self): self.assertRaises(ValueError, lambda: Vector3D([])) self.assertRaises(ValueError, lambda: Vector3D([1])) self.assertRaises(ValueError, lambda: Vector3D([1, 2]))
def test_complex_vector3d(self): self.assert_all_of_type(Vector3D([1j, 2j, 3j]).elements, complex)
def test_float_vector3d(self): self.assert_all_of_type(Vector3D([1., 2., 3.]).elements, float)
def test_int_vector3d(self): self.assert_all_of_type(Vector3D([1, 2, 3]).elements, int)
def random_complex_vector(): return Vector3D([random_complex(), random_complex(), random_complex()])
def random_float_vector(): return Vector3D([random_float(), random_float(), random_float()])
def random_int_vector(): return Vector3D([random_int(), random_int(), random_int()])
def _fromMQPoint(mqpoint): return Vector3D(mqpoint.x, mqpoint.y, mqpoint.z)
# coding:sjis from vector3d import Vector3D a = Vector3D() b = Vector3D(0, 1, 2) c = Vector3D(1, 2, 3) print("‚ ‚ ", a, b, b.abs(), b.abs()) print(a, b, c) print(-a, -b, -c) print(a + b, b + c) print(a - b, b - c) print(a * 2, b * 3, c * 4) print(2 * a, 3 * b, 4 * c) print(a / 2, b / 3, c / 4) print(a.length(), b.length(), c.length()) print(a.length2(), b.length2(), c.length2()) print(a.dot(b), b.dot(c)) print(a.cross(b), b.cross(c))
''' An implementation of Runge-Kutta 4th order numerical integration, to estimate position and velocity with respect to time and given acceleration. In this example, acceleration is constant as only gravity is accounted for, but can be varied as a function of force and mass. ''' from vector3d import Vector3D # initial params timestep = 0.01 # [ms] duration = 2.0 # [s] position = Vector3D([0.0, 9.8, 0.0]) velocity = Vector3D([0.0, 0.0, 0.0]) acceleration = Vector3D([0.0, -9.8, 0.0]) class State(object): def __init__(self, x=0.0, v=0.0): self.p = x # position self.v = v # velocity class StateVector(object): def __init__(self, position, velocity): self.vector = [ State(p, v) for p, v in zip(position.points, velocity.points) ]
"Eris": m_to_AU(1163 * 1000), "Sun": m_to_AU(695700 * 1000) } # =============== PLANET LOAD ===================== print("Loading planets data...") planets_total = get_planets(sim_time, takeoff) print("Done.") earth_v = earth_speed(planets_total[0]["Earth"]) # ================ ROCKET PARAMETERS ============== start_pos = Vector3D( planets_total[0]["Earth"][0], planets_total[0]["Earth"][1] + m_to_AU(1000 * (6380 + 20000)), # Earth high orbit planets_total[0]["Earth"][2]) start_vel = Vector3D(10000 + earth_v[0], 8000 + earth_v[1], 0) fuel = 8e4 # 4e3 mass = 4e3 engine_thrust = 6e5 # 6e4 engine_isp = 345 rocket = Rocket(start_pos, start_vel, fuel, mass, engine_thrust, engine_isp) print(f"Fuel consumption: {round(rocket._fuel_consumption, 3)} kg/s") print(f"Burn time available: {int(rocket.remaining_burn_time())} s") rocket.set_planets_info(masses=masses, sizes=sizes) # ================== FLIGHT ======================== print("Simulating flight...")