#[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>
impl<N: Copy + RealField> Plane<N>
Sourcepub fn new(normal: Unit<Vector3<N>>, distance: N) -> Self
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);
Sourcepub fn with_point(normal: Unit<Vector3<N>>, point: &Point3<N>) -> Self
pub fn with_point(normal: Unit<Vector3<N>>, point: &Point3<N>) -> Self
Plane from unit normal with point in plane.
Sourcepub fn distance_from(&self, point: &Point3<N>) -> N
pub fn distance_from(&self, point: &Point3<N>) -> N
Signed orthogonal distance from point
.
Sourcepub fn project_point(&self, point: &Point3<N>) -> Point3<N>
pub fn project_point(&self, point: &Point3<N>) -> Point3<N>
Projects point onto plane.
Sourcepub fn project_axis(&self, axis: &Unit<Vector3<N>>) -> Unit<Vector3<N>>
pub fn project_axis(&self, axis: &Unit<Vector3<N>>) -> Unit<Vector3<N>>
Projects axis onto plane.
Sourcepub fn project_vector(&self, vector: &Vector3<N>) -> Vector3<N>
pub fn project_vector(&self, vector: &Vector3<N>) -> Vector3<N>
Projects vector onto plane.
Sourcepub fn angle_between(&self, a: &Vector3<N>, b: &Vector3<N>) -> N
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.
Sourcepub fn rotate_by(self, rot: &UnitQuaternion<N>) -> Self
pub fn rotate_by(self, rot: &UnitQuaternion<N>) -> Self
Rotates plane.
Sourcepub fn translate_by(self, vec: &Vector3<N>) -> Self
pub fn translate_by(self, vec: &Vector3<N>) -> Self
Translates plane.
Sourcepub fn transform_by(self, iso: &Isometry3<N>) -> Self
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));
Trait Implementations§
Source§impl<N: Copy + RealField + AbsDiffEq> AbsDiffEq for Plane<N>
impl<N: Copy + RealField + AbsDiffEq> AbsDiffEq for Plane<N>
Source§fn default_epsilon() -> N::Epsilon
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
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
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of
AbsDiffEq::abs_diff_eq
.Source§impl<'de, N> Deserialize<'de> for Plane<N>
impl<'de, N> Deserialize<'de> for Plane<N>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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<Reflection<N, Const<3>, ArrayStorage<N, 3, 1>>> for Plane<N>
impl<N: Copy + RealField> From<Reflection<N, Const<3>, ArrayStorage<N, 3, 1>>> for Plane<N>
Source§fn from(reflection: Reflection3<N>) -> Self
fn from(reflection: Reflection3<N>) -> Self
Converts to this type from the input type.
Source§impl<N: Copy + RealField + RelativeEq> RelativeEq for Plane<N>
impl<N: Copy + RealField + RelativeEq> RelativeEq for Plane<N>
Source§fn default_max_relative() -> N::Epsilon
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
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
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
The inverse of
RelativeEq::relative_eq
.Source§impl<N: Copy + RealField + UlpsEq> UlpsEq for Plane<N>
impl<N: Copy + RealField + UlpsEq> UlpsEq for Plane<N>
impl<N: Copy + Copy + RealField> Copy for Plane<N>
impl<N: Eq + Copy + RealField> Eq for Plane<N>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.