|
void | bj_compute_kinematics_2d (bj_real out[restrict static(2)], const bj_real position[restrict static(2)], const bj_real velocity[restrict static(2)], const bj_real acceleration[restrict static(2)], bj_real time) |
void | bj_compute_kinematics_velocity_2d (bj_real out[restrict static(2)], const bj_real velocity[restrict static(2)], const bj_real acceleration[restrict static(2)], bj_real time) |
void | bj_apply_particle_force_2d (bj_particle_2d *p_particle, const bj_vec2 force) |
void | bj_step_particle_2d (bj_particle_2d *p_particle, bj_real dt) |
void | bj_apply_gravity_2d (bj_particle_2d *p_particle, bj_real gravity) |
void | bj_apply_point_gravity_2d (bj_particle_2d *restrict p_particle_from, const bj_particle_2d *restrict p_particle_to, const bj_real gravity_factor) |
void | bj_apply_point_gravity_softened_2d (bj_particle_2d *restrict p_particle_from, const bj_particle_2d *restrict p_particle_to, const bj_real gravity_factor, const bj_real epsilon) |
void | bj_apply_drag_2d (bj_particle_2d *p_particle, bj_real k1, bj_real k2) |
bj_real | bj_compute_particle_drag_coefficient_2d (const bj_vec2 vel, const bj_real k1, const bj_real k2) |
bj_bool | bj_compute_particle_drag_force_2d (bj_real result[restrict static(2)], const bj_real vel[restrict static(2)], const bj_real k1, const bj_real k2) |
void | bj_apply_angular_torque_2d (bj_angular_2d *angular, bj_real torque) |
void | bj_step_angular_2d (bj_angular_2d *angular, double delta_time) |
void | bj_apply_rigidbody_force_2d (bj_rigid_body_2d *body, const bj_vec2 force) |
void | bj_step_rigid_body_2d (bj_rigid_body_2d *body, double delta_time) |
2D physics utilities (point masses, forces, kinematics).
This header provides small helpers for common 2D physics operations. By default, quantities are interpreted in SI units (meters, seconds), but formulas are dimensionally homogeneous: results are correct for any consistent unit system (e.g., km and s; cm and s), provided all inputs use the same system.
Dimensionality uses the base dimensions L (length) and T (time). For example:
- position: [L]
- velocity: [L T^-1]
- acceleration: [L T^-2]
- time: [T]
◆ bj_particle_2d_t
2D point mass state and physical properties.
Positions, velocities, accelerations and force accumulator are expressed in world space. Damping is a unitless velocity decay factor applied per-step. Mass is represented as inverse mass; use 0 to represent an immovable object.
- Parameters
-
position | Current 2D position [L] |
velocity | Current 2D velocity [L T^-1] |
acceleration | Current 2D acceleration [L T^-2] |
forces | Accumulated force for the next integration step [M L T^-2] |
damping | Velocity damping factor in [0, 1] |
inverse_mass | Inverse of mass [M^-1]; 0 means infinite mass |
◆ bj_angular_2d_t
Angular.
2D angular state and properties (scalar angle about Z).
Angle units are radians. Damping is unitless per-step decay on angular velocity. Inertia is represented via inverse inertia; use 0 for infinite inertia.
- Parameters
-
value | Angle theta [rad] |
velocity | Angular velocity omega [rad T^-1] |
acceleration | Angular acceleration alpha [rad T^-2] |
torque | Accumulated torque tau for next step [M L^2 T^-2] |
damping | Angular velocity damping factor in [0, 1] |
inverse_inertia | Inverse moment of inertia I^-1 [M^-1 L^-2] |
◆ bj_rigid_body_2d_t
struct bj_rigid_body_2d_t |
Rigid body with translational and angular components.
Particle terms are in world space. Angle is about +Z.
- Parameters
-
particle | Linear state (position, velocity, forces) |
angular | Angular state (theta, omega, tau) |
◆ bj_angular_2d
◆ bj_particle_2d
◆ bj_rigid_body_2d
◆ bj_apply_angular_torque_2d()
Add torque to the angular accumulator.
- Parameters
-
angular | Angular state to modify |
torque | Torque to add tau [M L^2 T^-2] |
◆ bj_apply_drag_2d()
Apply quadratic + linear drag to a particle's accumulator.
Drag magnitude = k1 * |v| + k2 * |v|^2 along -v_hat.
- Parameters
-
p_particle | Particle to affect |
k1 | Linear drag coefficient [M T^-1] |
k2 | Quadratic drag coefficient [M L^-1] |
◆ bj_apply_gravity_2d()
Apply constant downward gravity in world space to a particle.
Adds force F = m * g * (0, -1) assuming -Y is "down".
- Parameters
-
p_particle | Particle to affect |
gravity | Gravitational acceleration magnitude g >= 0 [L T^-2] |
◆ bj_apply_particle_force_2d()
Add a force to a particle's accumulator.
The force will be used on the next integration step, then should be cleared by the step routine.
- Parameters
-
p_particle | Particle to modify |
force | Force to add [M L T^-2] |
◆ bj_apply_point_gravity_2d()
Apply point gravity from one particle to another.
Adds a Newtonian attraction from p_particle_to to p_particle_from. Uses F = Gm1m2 r_hat / r^2 with gravity_factor = G.
- Parameters
-
p_particle_from | Particle receiving the force |
p_particle_to | Source particle |
gravity_factor | Gravitational constant G [L^3 M^-1 T^-2] |
◆ bj_apply_point_gravity_softened_2d()
Apply softened point gravity to avoid singularities at small r.
Uses F proportional to r / (r^2 + epsilon^2)^(3/2).
- Parameters
-
p_particle_from | Particle receiving the force |
p_particle_to | Source particle |
gravity_factor | Gravitational constant G [L^3 M^-1 T^-2] |
epsilon | Softening length epsilon >= 0 [L] |
◆ bj_apply_rigidbody_force_2d()
Apply a world-space force at the center of mass.
Only affects linear state. Use external torque to affect rotation.
- Parameters
-
body | Rigid body to modify |
force | Force to add [M L T^-2] |
◆ bj_compute_kinematics_2d()
void bj_compute_kinematics_2d |
( |
bj_real | out[restrict static(2)], |
|
|
const bj_real | position[restrict static(2)], |
|
|
const bj_real | velocity[restrict static(2)], |
|
|
const bj_real | acceleration[restrict static(2)], |
|
|
bj_real | time ) |
Integrate constant-acceleration 2D kinematics: position at time t.
Uses: out = position + velocity * time + 0.5 * acceleration * time^2.
- Parameters
-
out | Output position at time t [L] |
position | Initial position [L] |
velocity | Initial velocity [L T^-1] |
acceleration | Constant acceleration [L T^-2] |
time | Elapsed time t [T] |
◆ bj_compute_kinematics_velocity_2d()
void bj_compute_kinematics_velocity_2d |
( |
bj_real | out[restrict static(2)], |
|
|
const bj_real | velocity[restrict static(2)], |
|
|
const bj_real | acceleration[restrict static(2)], |
|
|
bj_real | time ) |
Integrate constant-acceleration 2D kinematics: velocity at time t.
Uses: out = velocity + acceleration * time.
- Parameters
-
out | Output velocity at time t [L T^-1] |
velocity | Initial velocity [L T^-1] |
acceleration | Constant acceleration [L T^-2] |
time | Elapsed time t [T] |
◆ bj_compute_particle_drag_coefficient_2d()
Return scalar drag coefficient for a velocity.
Computes c = k1 * |v| + k2 * |v|^2.
- Parameters
-
vel | Velocity vector [L T^-1] |
k1 | Linear drag coefficient [M T^-1] |
k2 | Quadratic drag coefficient [M L^-1] |
- Returns
- c >= 0 [M T^-1]
◆ bj_compute_particle_drag_force_2d()
Compute drag force for a velocity.
result = -c * v_hat with c as above. Zero if vel is near zero.
- Parameters
-
result | Output force [M L T^-2] |
vel | Velocity vector [L T^-1] |
k1 | Linear drag coefficient [M T^-1] |
k2 | Quadratic drag coefficient [M L^-1] |
- Return values
-
BJ_TRUE | result written |
BJ_FALSE | velocity too small to define direction; result set to (0,0) |
◆ bj_step_angular_2d()
void bj_step_angular_2d |
( |
bj_angular_2d * | angular, |
|
|
double | delta_time ) |
Semi-implicit Euler step for angular motion.
Integrates alpha and omega, applies damping, and advances theta. Clears torque.
- Parameters
-
angular | Angular state to integrate |
delta_time | Time step [T] |
◆ bj_step_particle_2d()
Semi-implicit Euler step for a particle.
Integrates acceleration and velocity, applies damping, and advances position. Clears the force accumulator after use.
- Parameters
-
p_particle | Particle to integrate |
dt | Time step [T] |
◆ bj_step_rigid_body_2d()
Step rigid body linear and angular states.
Calls the corresponding particle and angular integrators. Clears accumulators.
- Parameters
-
body | Rigid body to integrate |
delta_time | Time step [T] |