Skip to main content

Plane

Struct Plane 

Source
pub struct Plane<T: Number, const N: usize> { /* private fields */ }
Expand description

A plane in 3D space, defined by a normal vector and a distance from the origin

Implementations§

Source§

impl<T: Number> Plane<T, 3>

Source

pub fn xy_plane() -> Self

Source

pub fn xz_plane() -> Self

Source

pub fn yz_plane() -> Self

Source§

impl<T, const N: usize> Plane<T, N>
where T: Number,

Source

pub fn new(normal: SVector<T, N>, distance: T) -> Self

Source

pub fn normal(&self) -> SVector<T, N>

Source

pub fn with_normal(self, normal: SVector<T, N>) -> Self

Source

pub fn distance(&self) -> T

Returns the signed distance from the origin to the plane along the normal.

Source

pub fn roughly_eq(&self, other: &Self) -> bool

Approximate equality check using epsilon tolerance.

Source

pub fn origin_projection(&self) -> Point<T, N>

Returns the point on the plane closest to the origin. Requires the normal to be a unit vector.

Source

pub fn classify_point(&self, point: &Point<T, N>) -> PlaneSide

Source

pub fn has_point(&self, point: &Point<T, N>) -> bool

Source

pub fn cast<T2: Number>(self) -> Plane<T2, N>
where T: AsPrimitive<T2>,

Cast the plane’s numeric type from T to T2.

Source

pub fn flip(self) -> Self

Source

pub fn classify_polygon(&self, polygon: &Polygon<T, N>) -> PolygonClassification

Classifies a polygon

Computes signed distances for all vertices in a single pass, tracking min/max to derive the classification without per-vertex branching.

Source§

impl<T: Number, const N: usize> Plane<T, N>

Source

pub fn split_edge( &self, a: &Point<T, N>, b: &Point<T, N>, ) -> Result<(Point<T, N>, Point<T, N>, Point<T, N>), PlaneSide>

Source

pub fn split_polygon( &self, polygon: Polygon<T, N>, ) -> (Polygon<T, N>, Polygon<T, N>)

Split a spanning polygon into a front fragment and a back fragment.

Algorithm:

  1. Classify each vertex with classify_point.
  2. For each consecutive edge (a, b):
    • If a is Front, add a to the front list.
    • If a is Back, add a to the back list.
    • If a is On, add a to both lists.
    • If edge (a, b) crosses the plane (a and b have opposite Front/Back classification): compute the intersection point p = a + t*(b-a) where t = (d - n·a) / (n·(b-a)), then add p to both lists.
  3. Build two new Polygons from the front and back vertex lists, keeping the original plane.

Metadata is preserved: both fragments inherit the source polygon’s metadata.

Source§

impl<T> Plane<T, 3>
where T: Number + AddAssign + SubAssign + MulAssign + RealField,

Source

pub fn from_points(p1: Point3<T>, p2: Point3<T>, p3: Point3<T>) -> Self

Construct a plane from three non-collinear points. The normal is oriented by the right-hand rule: (p2 - p1) × (p3 - p1).

Source

pub fn rotation_to(&self, other: Plane<T, 3>) -> Matrix3<T>
where T: Signed,

Compute the 3×3 rotation matrix R such that R * self.normal() == other.normal().

In other words, given a point p that lies in the plane described by self, the product R * p will lie in the plane described by other. This is the unique shortest-arc rotation (minimum rotation angle) that carries one normal onto the other, computed via the Rodrigues rotation formula in its trigonometry-free form.

§Mathematical derivation

Let a = self.normal() and b = other.normal() (both assumed to be unit vectors).

The angle θ between them satisfies:

  cos θ  = a · b           (dot product)
  sin θ  = ‖a × b‖         (magnitude of cross product)

The rotation axis is v = a × b (unnormalized; its magnitude is sin θ).

The skew-symmetric cross-product matrix [v]× encodes the “cross with v” operation:

        ⎡  0   −v₃   v₂ ⎤
[v]× =  ⎢  v₃   0   −v₁ ⎥
        ⎣ −v₂   v₁   0  ⎦

Rodrigues’ formula then gives:

R = I  +  [v]×  +  [v]ײ  ·  1/(1 + cos θ)

This avoids calling acos/sin/cos and is numerically stable for all θ except θ = 180° (anti-parallel normals), which is handled separately below.

§Special case: anti-parallel normals (θ ≈ 180°)

When a · b ≈ −1 the denominator (1 + cos θ) approaches zero, so the formula above is undefined. Geometrically, any 180° rotation whose axis is perpendicular to a is a valid solution; we break the degeneracy by choosing the world axis that is least aligned with a (found with iamin() — the index of the smallest absolute component) as a helper to build a perpendicular rotation axis:

rot_axis = (a × world_axis).normalize()
R = −I + 2 · rot_axis · rot_axisᵀ

(This is Rodrigues with θ = π: cos π = −1, sin π = 0.)

Trait Implementations§

Source§

impl<T: Clone + Number, const N: usize> Clone for Plane<T, N>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Number, const N: usize> Debug for Plane<T, N>

Source§

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

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

impl<T: PartialEq + Number, const N: usize> PartialEq for Plane<T, N>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<T: PartialOrd + Number, const N: usize> PartialOrd for Plane<T, N>

Source§

fn partial_cmp(&self, other: &Plane<T, N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy + Number, const N: usize> Copy for Plane<T, N>

Source§

impl<T: Number, const N: usize> StructuralPartialEq for Plane<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Plane<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for Plane<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for Plane<T, N>

§

impl<T, const N: usize> Sync for Plane<T, N>

§

impl<T, const N: usize> Unpin for Plane<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnsafeUnpin for Plane<T, N>
where T: UnsafeUnpin,

§

impl<T, const N: usize> UnwindSafe for Plane<T, N>
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> 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, dest: *mut u8)

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

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

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
§

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
§

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

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ConditionalSend for T
where T: Send,

§

impl<T> OpaqueAttachment for T
where T: Send + Sync + 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

§

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,