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>>>
impl<B> Plane<Vector<[f32; 4], Real<3, B>>>
Sourcepub const fn new(a: f32, b: f32, c: f32, d: f32) -> Self
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);
Sourcepub fn from_points(a: Point3<B>, b: Point3<B>, c: Point3<B>) -> Self
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);
Sourcepub fn from_point_and_normal(pt: Point3<B>, n: Normal3) -> Self
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);
Sourcepub fn normal(&self) -> Normal3
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);Sourcepub fn offset(&self) -> f32
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);Sourcepub fn project(&self, pt: Point3<B>) -> Point3<B>
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));Sourcepub fn signed_dist(&self, pt: Point3<B>) -> f32
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);Sourcepub fn is_inside(&self, pt: Point3<B>) -> bool
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));Sourcepub fn basis<F>(&self) -> Mat4x4<RealToReal<3, F, B>>
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));