Plane

Struct Plane 

Source
pub struct Plane<V>(/* private fields */);
Expand description

Plane, defined by the four parameters of the plane equation.

Implementations§

Source§

impl<B> Plane<Vector<[f32; 4], Real<3, B>>>

Source

pub const YZ: Self

The x = 0 coordinate plane.

Source

pub const XZ: Self

The y = 0 coordinate plane.

Source

pub const XY: Self

The z = 0 coordinate plane.

Source

pub const fn new(a: f32, b: f32, c: f32, d: f32) -> Self

Creates a new plane with the given coefficients.

The returned plane satisfies the plane equation

ax + by + cz = d,

or equivalently

ax + by + cz - d = 0.

Note the sign of the d coefficient.

The coefficients (a, b, c) make up a vector normal to the plane, and d is proportional to the plane’s distance to the origin. If (a, b, c) is a unit vector, then d is exactly the offset of the plane from the origin in the direction of the normal.

§Examples
use retrofire_core::{geom::Plane3, math::Vec3};

let p = <Plane3>::new(1.0, 0.0, 0.0, -2.0);
assert_eq!(p.normal(), Vec3::X);
assert_eq!(p.offset(), -2.0);
Source

pub fn from_points(a: Point3<B>, b: Point3<B>, c: Point3<B>) -> Self

Creates a plane given three points on the plane.

§Panics

If the points are collinear or nearly so.

§Examples
use retrofire_core::{geom::Plane3, math::{pt3, vec3}};

let p = <Plane3>::from_points(
    pt3(0.0, 0.0, 2.0),
    pt3(1.0, 0.0, 2.0),
    pt3(0.0, 1.0, 2.0),
);
assert_eq!(p.normal(), vec3(0.0, 0.0, 1.0));
assert_eq!(p.offset(), 2.0);
Source

pub fn from_point_and_normal(pt: Point3<B>, n: Normal3) -> Self

Creates a plane given a point on the plane and a normal.

n does not have to be normalized.

§Panics

If n is non-finite or nearly zero-length.

§Examples
use retrofire_core::{geom::Plane3, math::{Vec3, pt3, vec3}};

let p = <Plane3>::from_point_and_normal(pt3(1.0, 2.0, 3.0), Vec3::Z);
assert_eq!(p.normal(), Vec3::Z);
assert_eq!(p.offset(), 3.0);
Source

pub fn normal(&self) -> Normal3

Returns the normal vector of self.

The normal returned is unit length.

§Examples
use retrofire_core::{geom::Plane3, math::Vec3};

assert_eq!(<Plane3>::XY.normal(), Vec3::Z);
assert_eq!(<Plane3>::YZ.normal(), Vec3::X);
Source

pub fn offset(&self) -> f32

Returns the signed distance of self from the origin.

This distance is negative if the origin is outside the plane and positive if the origin is inside the plane.

§Examples
use retrofire_core::{geom::Plane3, math::{Vec3, pt3}};

assert_eq!(<Plane3>::new(0.0, 1.0, 0.0, 3.0).offset(), 3.0);
assert_eq!(<Plane3>::new(0.0, 2.0, 0.0, 6.0).offset(), 3.0);
assert_eq!(<Plane3>::new(0.0, -1.0, 0.0, -3.0).offset(), -3.0);
Source

pub fn project(&self, pt: Point3<B>) -> Point3<B>

Returns the perpendicular projection of a point on self.

In other words, returns P’, the point on the plane closest to P.

         ^        P
        /         ·
       /          ·
      / · · · · · P'
     /           ·
    /           ·
   O------------------>
§Examples
use retrofire_core::geom::Plane3;
use retrofire_core::math::{Point3, pt3};

let pt: Point3 = pt3(1.0, 2.0, -3.0);

assert_eq!(<Plane3>::XZ.project(pt), pt3(1.0, 0.0, -3.0));
assert_eq!(<Plane3>::XY.project(pt), pt3(1.0, 2.0, 0.0));

assert_eq!(<Plane3>::new(0.0, 0.0, 1.0, 2.0).project(pt), pt3(1.0, 2.0, 2.0));
assert_eq!(<Plane3>::new(0.0, 0.0, 2.0, 2.0).project(pt), pt3(1.0, 2.0, 1.0));
Source

pub fn signed_dist(&self, pt: Point3<B>) -> f32

Returns the signed distance of a point to self.

§Examples
use retrofire_core::geom::Plane3;
use retrofire_core::math::{Point3, pt3, Vec3};

let pt: Point3 = pt3(1.0, 2.0, -3.0);

assert_eq!(<Plane3>::XZ.signed_dist(pt), 2.0);
assert_eq!(<Plane3>::XY.signed_dist(pt), -3.0);

let p = <Plane3>::new(-1.0, 0.0, 0.0, 2.0);
assert_eq!(p.signed_dist(pt), -3.0);
Source

pub fn is_inside(&self, pt: Point3<B>) -> bool

Returns whether a point is in the half-space that the normal of self points away from.

§Examples
use retrofire_core::geom::Plane3;
use retrofire_core::math::{Point3, pt3};

let pt: Point3 = pt3(1.0, 2.0, -3.0);

assert!(!<Plane3>::XZ.is_inside(pt));
assert!(<Plane3>::XY.is_inside(pt));
Source

pub fn basis<F>(&self) -> Mat4x4<RealToReal<3, F, B>>

Returns an orthonormal affine basis on self.

The y-axis of the basis is the normal vector; the x- and z-axes are two arbitrary orthogonal unit vectors tangent to the plane. The origin point is the point on the plane closest to the origin.

§Examples
use retrofire_core::assert_approx_eq;
use retrofire_core::geom::Plane3;
use retrofire_core::math::{Point3, pt3, vec3, Apply};

let p = <Plane3>::from_point_and_normal(pt3(0.0,1.0,0.0), vec3(0.0,1.0,1.0));
let m = p.basis::<()>();

assert_approx_eq!(m.apply(&Point3::origin()), pt3(0.0, 0.5, 0.5));

Trait Implementations§

Source§

impl<V: Clone> Clone for Plane<V>

Source§

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

Returns a duplicate 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<V: Debug> Debug for Plane<V>

Source§

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

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

impl<V: PartialEq> PartialEq for Plane<V>

Source§

fn eq(&self, other: &Plane<V>) -> 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<V: Copy> Copy for Plane<V>

Source§

impl<V: Eq> Eq for Plane<V>

Source§

impl<V> StructuralPartialEq for Plane<V>

Auto Trait Implementations§

§

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

§

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

§

impl<V> Send for Plane<V>
where V: Send,

§

impl<V> Sync for Plane<V>
where V: Sync,

§

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

§

impl<V> UnwindSafe for Plane<V>
where V: 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
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> 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.