# Orbit

> A planet on a Kepler orbit around a star at focus: semi_major units, eccentricity, the perihelion to the right of the star, once around every period…

Page: https://fframes-kit.pages.dev/docs/physics/orbit/
Cargo feature: `physics` (`fframes-kit = { version = "..", features = ["physics"] }`)

A planet on a Kepler orbit around a star at `focus`: `semi_major` units, `eccentricity`, the
perihelion to the right of the star, once around every `period` seconds (Kepler's equation
is solved for each frame). With `sweeps`, the first orbit shades that many sectors from the
star, each swept in the same `sweep` fraction of the period. The sector near the star is
short and wide, the far one long and thin, and their areas are equal. `position(t)` and
`eccentric_anomaly(m, e)` give the numbers. Gallery scene: `Orbit`.

Gallery clip of `Orbit`: https://fframes-kit.pages.dev/media/scenes/Orbit-40f988b2.mp4

```rust
use fframes_kit::prelude::*;

fn figure<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> {
    ui.show(Orbit {
        focus: (2.0, -0.5),
        semi_major: 4.0,
        eccentricity: 0.6,
        period: 5.0,
        sweeps: 3,
        sweep: 0.12,
        ..ui.defaults()
    })
}
```

## API

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`).

### Orbit

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `focus` | `(f64, f64)` | `(1.5, 0.0)` | Where the star sits, one focus of the ellipse, in units of `ui.space`. |
| `semi_major` | `f64` | `3.5` | Half the long axis of the ellipse in units of `ui.space`. |
| `eccentricity` | `f64` | `0.6` | How stretched the ellipse is: 0 is a circle, close to 1 a thin ellipse. |
| `period` | `f64` | `5.0` | Seconds the planet takes for one orbit. |
| `start` | `f64` | `0.0` | Where the planet is when its clock starts, as a fraction of the period after the closest point to the star. |
| `delay` | `f32` | `0.0` | Seconds after the container's start before the planet starts to move. |
| `time_scale` | `f32` | `1.0` | Speed of the motion over local time; 2 runs twice as fast, 1 is real time. |
| `sweeps` | `usize` | `3` | Number of shaded sectors, swept at even times around the first orbit; 0 for none. |
| `sweep` | `f64` | `0.1` | Fraction of the period each sector takes to sweep, so each covers the same area. |
| `star_radius` | `f32` | `24.0` | Radius of the star in pixels. |
| `planet_radius` | `f32` | `13.0` | Radius of the planet in pixels. |
| `orbit_color` | `Color` | `theme.colors.muted` | Colour of the dashed orbit ellipse. |
| `star_color` | `Color` | `theme.colors.highlight` | Colour of the star. |
| `planet_color` | `Color` | `theme.colors.accent` | Colour of the planet. |
| `sweep_color` | `Color` | `theme.colors.accent` | Colour of the shaded sectors. |
| `stroke_width` | `f32` | `theme.stroke.thin` | Width of the orbit ellipse in pixels. |
| `enter` | `Option<EnterAnim>` | `None` | How the orbit and the star draw in; `None` shows them from the start. |
| `exit` | `Option<ExitAnim>` | `None` | How the orbit and the star leave at the end of the container; `None` stays. |
| `parts_enter` | `Option<FadeIn>` | `None` | How the planet and the sectors fade in; `None` for none. |
| `parts_exit` | `Option<FadeOut>` | `None` | How the planet and the sectors fade out before the end; `None` for none. |

Methods:

- `fn semi_minor(&self) -> f64`: The semi-minor axis, `a √(1 - e²)`.
- `fn position(&self, t: f64) -> (f64, f64)`: The planet's offset from the star in units after `t` seconds of its clock.
- `fn sweep_start(&self, i: usize) -> f64`: Seconds of the planet's clock when sector `i` of `Orbit::sweeps` starts.

Feature `physics` · [Source](https://github.com/khanhthanhdev/fframes-kit/blob/main/fframes-kit/src/kits/physics/orbit.rs#L28)
