vibe coding an orbital mechanics simulation to try out claude code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

45 lines
1.1 KiB

#ifndef PHYSICS_H
#define PHYSICS_H
// 3D Vector
struct Vec3 {
double x, y, z;
};
// 3x3 Matrix (row-major)
struct Mat3 {
double m00, m01, m02;
double m10, m11, m12;
double m20, m21, m22;
};
// Gravitational constant (m^3 kg^-1 s^-2)
const double G = 6.67430e-11;
// Vector math functions
Vec3 vec3_add(Vec3 a, Vec3 b);
Vec3 vec3_sub(Vec3 a, Vec3 b);
Vec3 vec3_cross(Vec3 a, Vec3 b);
Vec3 vec3_scale(Vec3 v, double s);
double vec3_magnitude(Vec3 v);
double vec3_distance(Vec3 a, Vec3 b);
Vec3 vec3_normalize(Vec3 v);
double vec3_dot(Vec3 a, Vec3 b);
// Matrix functions
Mat3 mat3_identity();
Mat3 mat3_multiply(Mat3 a, Mat3 b);
Vec3 mat3_multiply_vec3(Mat3 m, Vec3 v);
Mat3 mat3_rotation_x(double angle);
Mat3 mat3_rotation_z(double angle);
Mat3 mat3_rotation_orbital(double omega, double i, double Omega);
// Physics functions
Vec3 calculate_acceleration(Vec3 force, double mass);
// Physics integration functions
void rk4_step(Vec3* position, Vec3* velocity, double dt,
double body_mass, double parent_mass);
Vec3 evaluate_acceleration(Vec3 relative_pos, double body_mass, double parent_mass);
#endif