num_opt::physics

Struct PhysicsStateV3

Source
pub struct PhysicsStateV3<T: MyFloat> {
Show 14 fields m: T, g: MyVector3<T>, o: T, rot_inertia: T, mu: T, i: u64, prev_u: T, u: T, x: ComPos<T>, v: ComVel<T>, hl_normal: MyVector3<T>, w: MyVector3<T>, additional_info: PhysicsAdditionalInfo<T>, cost: Fpt,
}
Expand description

Physics solver v3

§Overview (check Self::step for details)

Store simulation parameters (m,g)
Track the state of the particle (position, velocity, u(curve parameter))
Compute intermediate values like normal acceleration, and delta_t(time step).
Determines cost based off of z direction (eyes down) g-forces measured at the heart, and rate of rotation.

Fields§

§m: T§g: MyVector3<T>§o: T§rot_inertia: T§mu: T§i: u64§prev_u: T§u: T§x: ComPos<T>§v: ComVel<T>§hl_normal: MyVector3<T>§w: MyVector3<T>§additional_info: PhysicsAdditionalInfo<T>§cost: Fpt

Implementations§

Source§

impl<T: MyFloat> PhysicsStateV3<T>

Source

pub fn m(&self) -> &T

Source

pub fn g(&self) -> &MyVector3<T>

Source

pub fn o(&self) -> &T

Source

pub fn rot_inertia(&self) -> &T

Source

pub fn mu(&self) -> &T

Source

pub fn i(&self) -> &u64

Source

pub fn prev_u(&self) -> &T

Source

pub fn u(&self) -> &T

Source

pub fn x(&self) -> &ComPos<T>

Source

pub fn v(&self) -> &ComVel<T>

Source

pub fn hl_normal(&self) -> &MyVector3<T>

Source

pub fn w(&self) -> &MyVector3<T>

Source

pub fn additional_info(&self) -> &PhysicsAdditionalInfo<T>

Source

pub fn cost(&self) -> &Fpt

Source§

impl<T: MyFloat> PhysicsStateV3<T>

Source

pub fn new(m: Fpt, g_: Fpt, curve: &Spline<T>, o: Fpt, mu: Fpt) -> Self

Initialize the physics state: m mass, g Gravity vector, curve.curve_at(0.0): Starting position of the curve at u=0

Source

pub fn set_v(&mut self, v: &MyVector3<T>)

Source

fn hl_normal_err_at_u_manual_pos( &self, u: &T, step: &T, curve: &Spline<T>, pos: &ComPos<T>, ) -> T

Source

fn hl_normal_errs_at_u(&self, u: &T, curve: &Spline<T>, step: &T) -> (T, T)

Source

pub fn determine_future_u_pos_norm_maxu_err( &self, step: &T, curve: &Spline<T>, ) -> Option<(T, ComPos<T>, MyVector3<T>, T, Fpt)>

Source

pub fn step(&mut self, step: &T, curve: &Spline<T>) -> Option<()>

Steps forward in time by step, may choose to perform smaller step(s)

§Implementation Details

The physics is based off semi-implicit euler integration, with corrective forces choosen to keep the position perfectly correct at all times (assuming such is possible while conserving energy).

The basic rule would be:
v_next = v_curr + a * dt
x_next = x_curr + v_next * dt

Acceleration would be from gravity and normal force. The normal force can be expressed as a rotation of v_curr, this ensures F_N doesn’t add any energy to the system.

Thus, we rewrite the update rules as:
v_next = rot(v_curr, R) + a * dt
x_next = x_curr + v_next * dt

Give a target x_tar, we subsitute x_next = x_tar:
x_tar = x_curr + v_next * dt
x_tar = x_curr + (rot(v_curr, R) + a * dt) * dt
x_tar = x_curr + rot(v_curr, R) * dt + a * dt^2
x_tar - (x_curr + a * dt^2) = rot(v_curr, R) * dt

From the “no velocity” position of x_curr + a * dt^2, adding velocity forms a sphere with radius v_curr * dt. The intersection of this sphere with a thick line of radius o about the curve is the domain of future possible positions.

We search for where on this domain we most closely match an ideal hl-normal.

Source

fn new_ang_vel(&self, step: &T, tgt_norm: &MyVector3<T>) -> MyVector3<T>

Source

fn correct_v_to_reduce_energy_by( &self, change_in_angular_energy: T, vel_to_correct: &ComVel<T>, ) -> ComVel<T>

Source

fn updated_v(&self, step: &T, target_pos: &ComPos<T>) -> ComVel<T>

Source

pub fn next_hl_normal( &self, u: &T, curve: &Spline<T>, vel: &ComVel<T>, ) -> MyVector3<T>

Source

pub fn future_pos_no_vel(&self, delta_t: &T, curr_pos: &ComPos<T>) -> ComPos<T>

Source

pub fn possible_positions( &self, curve: &Spline<T>, delta_t: &T, u: &T, ) -> Option<[ComPos<T>; 2]>

Source

fn energy(&self) -> T

Source

pub fn kinetic_energy(&self) -> T

Source

fn potential_energy(&self) -> T

Source

pub fn rot_energy(&self, w_mag: T) -> T

Source

pub fn description(&self) -> String

Trait Implementations§

Source§

impl<T: Clone + MyFloat> Clone for PhysicsStateV3<T>

Source§

fn clone(&self) -> PhysicsStateV3<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + MyFloat> Debug for PhysicsStateV3<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PhysicsStateV3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PhysicsStateV3<T>
where T: RefUnwindSafe,

§

impl<T> Send for PhysicsStateV3<T>

§

impl<T> Sync for PhysicsStateV3<T>

§

impl<T> Unpin for PhysicsStateV3<T>
where T: Unpin,

§

impl<T> UnwindSafe for PhysicsStateV3<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.