Skip to main content

Module kinematics

Module kinematics 

Source
Expand description

Two-body elastic kinematics, direction rotation and planar surface refraction. Pure functions, no state.

Functionsยง

gamma
Kinematic factor gamma = 4 M1 M2 / (M1 + M2)^2.
lab_angles
Laboratory deflection of projectile and recoil for a centre-of-mass scattering angle theta and mass ratio mu = M1 / M2.
lab_projectile_sc
Lab deflection of the projectile, as (sin psi, cos psi), from the half-angle sine and cosine of the centre-of-mass angle (s = sin(theta/2), c = cos(theta/2), s^2 + c^2 = 1) and mu = M1 / M2.
normalize
Normalise a vector to unit length.
refract_out
Planar surface barrier at a face with outward normal along x (sign of dir[0] gives which face).
refract_out_normal
refract_out through a face with outward unit normal normal (any orientation, not only the planar x faces): the normal component of the momentum is reduced, the tangential components are unchanged. The particle must be moving outward (dir . normal > 0) to escape.
rotate
Rotate unit vector u by polar angle polar (from u) at azimuth azimuth about u. The azimuth is measured in a frame built from u and the coordinate axis least aligned with it; since the azimuth is drawn uniformly the choice of frame does not matter, it only has to be fixed so results are reproducible.
rotate_sc
rotate with the polar and azimuthal angles given as (sin, cos) pairs, so a caller that already has them (the collision code gets the lab deflection from the half-angle tangent, without an inverse trigonometric call) pays for no sin_cos.
sin_cos_turns
(sin, cos) of the angle 2 pi u for u in [0, 1), the azimuth of a collision drawn as a fraction of a turn.