trackball

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

Source§

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,

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

Source§

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