Expand description
§use-oscillation
Oscillation and simple harmonic motion helpers for RustUse.
§Install
[dependencies]
use-oscillation = "0.0.1"§Foundation
use-oscillation provides small scalar helpers for simple harmonic motion, period,
frequency, angular frequency, spring oscillators, pendulum approximations, damping,
resonance, and oscillator state summaries.
Inputs are expected to be SI-style numeric values:
- seconds for period and time
- hertz for frequency
- radians per second for angular frequency
- meters for displacement, amplitude, and pendulum length
- kilograms for mass
- newtons per meter for spring constant
- meters per second squared for gravitational acceleration
- joules for energy
Radians are used for phase.
§Example
use core::f64::consts::{PI, TAU};
use use_oscillation::{SimpleHarmonicOscillator, spring_period};
let oscillator = SimpleHarmonicOscillator::new(2.0, TAU, 0.0).unwrap();
let period = spring_period(8.0, 2.0).unwrap();
assert!((oscillator.displacement(0.0).unwrap() - 2.0).abs() < 1.0e-12);
assert!((period - PI).abs() < 1.0e-12);§When to use directly
Choose use-oscillation when you only need reusable scalar helpers for simple oscillators.
§Scope
- This crate stays
f64-first and scalar-only. - It is not a wave library, signal-processing library, acoustics library, numerical simulator, or control-system package.
- Wave abstractions belong in the top-level
use-waveset. - Signal processing belongs in the top-level
use-signalset. - Acoustics belongs in the top-level
use-acousticsset. - Units belong in the top-level
use-unitsset.
§Status
use-oscillation is a pre-1.0 crate with a deliberately small API.
Oscillation-specific scalar helpers.
Modules§
Structs§
- Simple
Harmonic Oscillator - A simple scalar harmonic oscillator state.
- Spring
Oscillator - A spring-mass oscillator state.
Functions§
- acceleration
- Computes acceleration for simple harmonic motion using
a(t) = -Aω² * cos(ωt + φ). - acceleration_
from_ displacement - Computes simple-harmonic acceleration from displacement using
a = -ω²x. - angular_
frequency_ from_ frequency - Computes angular frequency from frequency using
ω = 2πf. - angular_
frequency_ from_ period - Computes angular frequency from period using
ω = 2π / T. - critical_
damping_ coefficient - Computes the critical damping coefficient using
c_critical = 2 * sqrt(mk). - damped_
angular_ frequency - Computes the damped angular frequency for an underdamped oscillator.
- damping_
ratio - Computes damping ratio using
ζ = c / (2 * sqrt(mk)). - damping_
ratio_ from_ quality_ factor - Computes damping ratio from quality factor using
ζ = 1 / (2Q). - displacement
- Computes displacement for simple harmonic motion using
x(t) = A * cos(ωt + φ). - frequency_
from_ angular_ frequency - Computes frequency from angular frequency using
f = ω / 2π. - frequency_
from_ period - Computes frequency from period using
f = 1 / T. - is_
critically_ damped - Returns
truewhen the damping ratio is withintoleranceof critical damping. - is_
overdamped - Returns
truewhen the damping ratio represents an overdamped system. - is_
underdamped - Returns
truewhen the damping ratio represents an underdamped system. - kinetic_
energy_ from_ total_ and_ potential - Computes kinetic energy from total energy and potential energy using
KE = E_total - U. - mass_
from_ spring_ period - Computes mass from spring constant and period using
m = kT² / 4π². - max_
acceleration - Computes the maximum acceleration using
a_max = Aω². - max_
speed - Computes the maximum speed using
v_max = Aω. - oscillator_
total_ energy - Computes oscillator total energy using
E = 0.5 * k * A². - pendulum_
length_ from_ period - Computes pendulum length from period using
L = g * (T / 2π)². - period_
from_ angular_ frequency - Computes period from angular frequency using
T = 2π / ω. - period_
from_ frequency - Computes period from frequency using
T = 1 / f. - quality_
factor_ from_ damping_ ratio - Computes quality factor from damping ratio using
Q = 1 / (2ζ). - resonance_
angular_ frequency_ natural - Computes the natural resonance angular frequency of a spring-mass oscillator.
- simple_
pendulum_ angular_ frequency - Computes small-angle simple pendulum angular frequency using
ω = sqrt(g / L). - simple_
pendulum_ frequency - Computes small-angle simple pendulum frequency in cycles per second.
- simple_
pendulum_ period - Computes the small-angle simple pendulum period using
T = 2π * sqrt(L / g). - spring_
angular_ frequency - Computes spring angular frequency using
ω = sqrt(k / m). - spring_
constant_ from_ period - Computes spring constant from mass and period using
k = 4π²m / T². - spring_
frequency - Computes spring frequency in cycles per second.
- spring_
period - Computes spring period using
T = 2π * sqrt(m / k). - spring_
potential_ energy - Computes spring potential energy using
U = 0.5 * k * x². - velocity
- Computes velocity for simple harmonic motion using
v(t) = -Aω * sin(ωt + φ).