Skip to content

Doppler

Cargo featurefeatures = ["physics"]

A source moving right from start at source_speed m/s sends out a front every period seconds, and the fronts spread at wave_speed m/s. They bunch up ahead of the source and spread out behind it. At or above the wave speed they pile into a cone. A front fades as it grows and is gone at max_radius meters. Listeners ahead and behind (meters from start) show the frequency they hear, f c / (c ∓ v), once the first front has reached them. The source’s own frequency sits above it, on a chip of the background. heard and fronts give the numbers. Gallery scene: Doppler.

Doppler demo, first frame
Doppler 5.5 s
use fframes_kit::prelude::*;
fn figure<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> {
ui.show(Doppler {
start: (-3.5, 0.0),
scale: 0.7,
source_speed: 1.0,
wave_speed: 3.0,
period: 0.4,
ahead: Some(8.0),
behind: Some(-4.0),
..ui.defaults()
})
}

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
start (f64, f64) (-4.0, 0.0) Where the source starts, in units of ui.space; meters below are measured from it.
scale f64 1.0 Units of ui.space per meter.
source_speed f64 1.0 Speed of the source to the right in m/s; at or above wave_speed the fronts pile into a cone.
wave_speed f64 3.0 Speed the wavefronts spread at in m/s.
period f64 0.4 Seconds between two wavefronts; the source’s own frequency is its inverse.
max_radius f64 6.0 Radius in meters where a front is gone; it fades out on the way.
ahead Option<f64> Some(10.0) Listener in meters from start, to the right of the source; None for none.
behind Option<f64> Some(-2.5) Listener in meters from start, to the left of the source; None for none.
labels bool true Writes the source’s frequency above it and the frequency each listener hears once the first front reaches it.
delay f32 0.0 Seconds after the container’s start before the source starts moving.
time_scale f32 1.0 Speed of the motion over local time; 2 runs twice as fast, 1 is real time.
source_color Color theme.colors.accent Colour of the source and its frequency label.
wave_color Color theme.colors.text Colour of the wavefronts.
listener_color Color theme.colors.highlight Colour of the listener marks.
stroke_width f32 theme.stroke.thin Width of the wavefronts in pixels.
enter Option<EnterAnim> None How the listener marks draw in; None shows them from the start.
exit Option<ExitAnim> None How the listener marks leave at the end of the container; None stays.
parts_enter Option<FadeIn> None How the source and the fronts fade in; None for none.
parts_exit Option<FadeOut> None How the source and the fronts fade out before the end; None for none.

Methods:

  • fn source(&self, t: f64) -> f64: Meters from start, the source after t seconds.
  • fn heard(&self, x: f64, t: f64) -> Option<f64>: The frequency in Hz a listener at x meters from start hears while the source is where it is after t seconds: f c / (c - v) ahead of it, f c / (c + v) behind. None ahead of a source at or above the wave speed, where no front has come.
  • fn fronts(&self, t: f64) -> Vec<(f64, f64)>: The emission time and the radius in meters of every front alive after t seconds, oldest first.

Feature physics · Source