Struct trackball::Plane

source ·
#[repr(C)]
pub struct Plane<N: Copy + RealField> { pub normal: Unit<Vector3<N>>, pub bias: N, }
Expand description

Plane encoding position with singed bias along unit normal.

Realizes plane equation a*x+b*y+c*z+d=0 with unit normal [x, y, z] and signed bias d.

Fields§

§normal: Unit<Vector3<N>>

Plane unit normal.

§bias: N

Signed bias along unit normal.

Implementations§

source§

impl<N: Copy + RealField> Plane<N>

source

pub fn new(normal: Unit<Vector3<N>>, distance: N) -> Self

Plane from unit normal and signed distance from the origin.

use trackball::{
    nalgebra::{Point3, Vector3},
    Plane,
};

// Plane intersecting y-axis at `5.0`.
let plane = Plane::new(Vector3::y_axis(), 5.0);

// Origin projected onto plane where plane intersects y-axis.
let point = plane.project_point(&Point3::origin());
assert_eq!(point, Point3::new(0.0, 5.0, 0.0));

// Bias is negated distance.
assert_eq!(plane.distance(), 5.0);
assert_eq!(plane.bias, -5.0);

// Plane intersecting y-axis at `-5.0`.
let plane = Plane::new(Vector3::y_axis(), -5.0);

// Origin projected onto plane where plane intersects y-axis.
let point = plane.project_point(&Point3::origin());
assert_eq!(point, Point3::new(0.0, -5.0, 0.0));

// Bias is negated distance.
assert_eq!(plane.distance(), -5.0);
assert_eq!(plane.bias, 5.0);
source

pub fn with_point(normal: Unit<Vector3<N>>, point: &Point3<N>) -> Self

Plane from unit normal with point in plane.

source

pub fn distance(&self) -> N

Signed orthogonal distance from the origin.

source

pub fn distance_from(&self, point: &Point3<N>) -> N

Signed orthogonal distance from point.

source

pub fn project_point(&self, point: &Point3<N>) -> Point3<N>

Projects point onto plane.

source

pub fn project_axis(&self, axis: &Unit<Vector3<N>>) -> Unit<Vector3<N>>

Projects axis onto plane.

source

pub fn project_vector(&self, vector: &Vector3<N>) -> Vector3<N>

Projects vector onto plane.

source

pub fn angle_between(&self, a: &Vector3<N>, b: &Vector3<N>) -> N

Singed angle from a to b where both vectors are in the plane.

source

pub fn rotate_by(self, rot: &UnitQuaternion<N>) -> Self

Rotates plane.

source

pub fn translate_by(self, vec: &Vector3<N>) -> Self

Translates plane.

source

pub fn transform_by(self, iso: &Isometry3<N>) -> Self

Transforms plane by direct isometry, i.e., rotation followed by translation.

use core::f64::{
    consts::FRAC_PI_2,
    EPSILON,
};
use trackball::{
    approx::AbsDiffEq,
    nalgebra::{Isometry3, Vector3},
    Plane,
};

// Plane intersecting y-axis at `5.0`.
let plane = Plane::new(Vector3::y_axis(), 5.0)
    .transform_by(&Isometry3::new(
        // Translation by after rotation.
        Vector3::new(-5.0, 0.0, 0.0),
        // Rotation by 90 degrees before translation.
        Vector3::new(0.0, 0.0, FRAC_PI_2),
    ));
// Plane intersecting x-axis at `-10.0`.
assert!(plane.abs_diff_eq(&Plane::new(-Vector3::x_axis(), 10.0), EPSILON));
source

pub fn cast<M: Copy + RealField>(self) -> Plane<M>
where N: SubsetOf<M>,

Casts components to another type, e.g., between f32 and f64.

Trait Implementations§

source§

impl<N: Copy + RealField + AbsDiffEq> AbsDiffEq for Plane<N>
where N::Epsilon: Copy,

§

type Epsilon = <N as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> N::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: N::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<N: Clone + Copy + RealField> Clone for Plane<N>

source§

fn clone(&self) -> Plane<N>

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<N: Debug + Copy + RealField> Debug for Plane<N>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de, N> Deserialize<'de> for Plane<N>
where N: Deserialize<'de> + Copy + RealField,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<N: Copy + RealField> From<Plane<N>> for Reflection3<N>

source§

fn from(plane: Plane<N>) -> Self

Converts to this type from the input type.
source§

impl<N: Copy + RealField> From<Reflection<N, Const<3>, ArrayStorage<N, 3, 1>>> for Plane<N>

source§

fn from(reflection: Reflection3<N>) -> Self

Converts to this type from the input type.
source§

impl<N: PartialEq + Copy + RealField> PartialEq for Plane<N>

source§

fn eq(&self, other: &Plane<N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<N: Copy + RealField + RelativeEq> RelativeEq for Plane<N>
where N::Epsilon: Copy,

source§

fn default_max_relative() -> N::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq( &self, other: &Self, epsilon: N::Epsilon, max_relative: N::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
source§

impl<N> Serialize for Plane<N>
where N: Serialize + Copy + RealField,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<N: Copy + RealField + UlpsEq> UlpsEq for Plane<N>
where N::Epsilon: Copy,

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

fn ulps_eq(&self, other: &Self, epsilon: N::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
source§

impl<N: Copy + Copy + RealField> Copy for Plane<N>

source§

impl<N: Eq + Copy + RealField> Eq for Plane<N>

source§

impl<N: Copy + RealField> StructuralPartialEq for Plane<N>

Auto Trait Implementations§

§

impl<N> Freeze for Plane<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for Plane<N>
where N: RefUnwindSafe,

§

impl<N> Send for Plane<N>

§

impl<N> Sync for Plane<N>

§

impl<N> Unpin for Plane<N>
where N: Unpin,

§

impl<N> UnwindSafe for Plane<N>
where N: 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> 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<T> CloneToUninit for T
where T: Copy,

source§

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

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

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

source§

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

🔬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> Same for T

§

type Output = T

Should always be Self
source§

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

source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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,

§

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>,

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,