Skip to main content

Module vector

Module vector 

Source
Expand description

Vector quantities: three components sharing one dimension.

A position, a velocity, a force and a field are all DVec3 to the compiler, and adding two of them is a bug the compiler cannot see. QVec3 carries the same seven exponents as Qty, so a displacement and a velocity stop being interchangeable.

Two of the operations are worth noticing, because they fall out of the dimensions rather than being decided:

  • QVec3::normalize returns a bare DVec3. A direction has no dimension — dividing a length by a length leaves a pure number — so a unit vector is exactly the right type for “which way”, and a ray direction cannot be mistaken for a displacement.
  • QVec3::length returns the scalar of the same dimension, which needs no exponent arithmetic and so works for every dimension at once.

dot and cross are missing on purpose: both change the dimension, and there is no way to express “the square of L” in a const generic parameter without unstable features. QVec3::along covers the case that actually comes up — projecting onto a unit direction, which preserves the dimension.

Structs§

QVec3
Three components of one dimension, stored in SI base units.

Functions§

centripetal
Force needed to hold mass in a circle — the check that a rotating stage’s bearing can take what a scan rate asks of it.
distance
Distance between two points, which is what a length actually measures.
free_travel
Speed acquired, and distance covered, under a constant acceleration.
kinetic_energy
Kinetic energy, ½mv². Needs the squared magnitude, so it is written out here rather than falling out of an operator.
momentum
Momentum of a moving mass.
newton_second
Newton’s second law, with the dimensions doing the checking.

Type Aliases§

AccelerationVec
An acceleration, m·s⁻².
ForceVec
A force, newtons.
LengthVec
A position or a displacement, m. The same dimension, and deliberately the same type: the difference between them is a choice of origin, not of physics.
MomentumVec
A momentum, kg·m·s⁻¹. The vector a closed system conserves component by component — and see the note in the workspace README on why the smallest component is what binds a conservation audit.
VelocityVec
A velocity, m·s⁻¹.