Skip to content

Wave

Cargo featurefeatures = ["physics"]

One figure for four kinds of wave, chosen by kind:

  • WaveKind::Transverse: the medium moves up and down;
  • WaveKind::Longitudinal: a row of particles that bunch and spread;
  • WaveKind::Standing: 2A sin(kx) cos(ωt) with its nodes and dashed envelope;
  • WaveKind::Superposition: the wave and a second one (second_wavelength, second_amplitude) drawn thin, with their sum drawn thick.

With front (the default) the medium starts at rest and the wave leaves the left end. marker picks out one point of the medium, which only moves in place. displacement(x, t), envelope(x) and nodes() give the numbers. Gallery scene: Wave (all four).

Wave demo, first frame
Wave 5 s
use fframes_kit::prelude::*;
fn figure<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> {
ui.show(Wave {
kind: WaveKind::Superposition,
origin: (-6.0, 0.0),
length: 12.0,
amplitude: 0.5,
wavelength: 3.0,
second_wavelength: 2.2,
speed: 3.0,
marker: Some(6.0),
..ui.defaults()
})
}

harmonic(n) turns a wave into the standing wave of a string’s nth harmonic, fixed at both ends (Manim-physics’ StandingWave): Wave { length: 9.0, ..ui.defaults() }.harmonic(3). Manim-physics’ LinearWave is Wave { front: false, .. } with speed = wavelength / period.

Components are plain structs. Set the fields you need and fill the rest with ..ui.defaults(): the defaults below come from the current theme (theme. values are fields of Theme).

Field Type Default Description
kind WaveKind WaveKind::Transverse What the wave shows: a transverse wave, a longitudinal one, a standing wave or two waves added.
origin (f64, f64) (-6.0, 0.0) Left end of the medium, on its resting line, in units of ui.space.
length f64 12.0 Length of the medium in meters.
scale f64 1.0 Units of ui.space per meter.
amplitude f64 0.8 Largest displacement in meters; a standing wave reaches twice this.
wavelength f64 4.0 Meters between two crests.
speed f64 2.0 Speed the wave travels right at in m/s.
second_wavelength f64 3.0 Meters between two crests of the second wave of a Superposition.
second_amplitude f64 0.5 Largest displacement in meters of the second wave of a Superposition.
front bool true The medium is at rest at the start and the wave leaves the left end on the clock; off makes the whole length move from the start.
marker Option<f64> None Meters from the left end of one point of the medium to highlight, which shows it oscillates in place; None for none.
particles usize 48 Particles of a longitudinal wave.
band f64 1.2 Meters tall, the lines that stand for the particles of a longitudinal wave.
delay f32 0.0 Seconds after the container’s start before the wave begins.
time_scale f32 1.0 Speed of the motion over local time; 2 runs twice as fast, 1 is real time.
color Color theme.colors.accent Colour of the wave, or of the first wave of a Superposition.
second_color Color theme.colors.highlight Colour of the second wave of a Superposition and of the nodes of a standing wave.
marker_color Color theme.colors.title Colour of the highlighted point and of the summed wave of a Superposition.
guide_color Color theme.colors.muted Colour of the dashed axis and of a standing wave’s envelope.
stroke_width f32 theme.stroke.regular Width of the wave line in pixels; the other lines use the theme’s thin width.
enter Option<EnterAnim> None How the axis draws in; None shows it from the start.
exit Option<ExitAnim> None How the axis leaves at the end of the container; None stays.
parts_enter Option<FadeIn> None How the medium fades in; None for none.
parts_exit Option<FadeOut> None How the medium fades out before the end; None for none.

Methods:

  • fn displacement(&self, x: f64, t: f64) -> f64: The displacement in meters of the medium x meters from the left end after t seconds: up for the transverse kinds, to the right for the longitudinal one.
  • fn envelope(&self, x: f64) -> f64: The largest displacement of a standing wave at x, 2A sin(kx).
  • fn harmonic(self, n: u32) -> Self: The standing wave of the nth harmonic of a string length meters long, fixed at both ends: Manim-physics’ StandingWave(n, length), n half wavelengths along it.
  • fn nodes(&self) -> Vec<f64>: The nodes of a standing wave, every half wavelength from the left end, in meters.

Feature physics · Source