#[repr(C)]pub struct Plane {
pub normal: Vec3,
pub bias: f32,
}Expand description
Plane encoding position with signed 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: Vec3Plane unit normal.
bias: f32Signed bias along unit normal.
Implementations§
Source§impl Plane
impl Plane
Sourcepub const fn new(normal: Vec3, distance: f32) -> Self
pub const fn new(normal: Vec3, distance: f32) -> Self
Plane from unit normal and signed distance from the origin.
use trackball::{Plane, glam::Vec3};
// Plane intersecting y-axis at `5.0`.
let plane = Plane::new(Vec3::Y, 5.0);
// Origin projected onto plane where plane intersects y-axis.
let point = plane.project_point(Vec3::ZERO);
assert_eq!(point, Vec3::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(Vec3::Y, -5.0);
// Origin projected onto plane where plane intersects y-axis.
let point = plane.project_point(Vec3::ZERO);
assert_eq!(point, Vec3::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: Vec3, point: Vec3) -> Self
pub fn with_point(normal: Vec3, point: Vec3) -> Self
Plane from unit normal with point in plane.
Sourcepub fn distance_from(&self, point: Vec3) -> f32
pub fn distance_from(&self, point: Vec3) -> f32
Signed orthogonal distance from point.
Sourcepub fn project_point(&self, point: Vec3) -> Vec3
pub fn project_point(&self, point: Vec3) -> Vec3
Projects point onto plane.
Sourcepub fn project_axis(&self, axis: Vec3) -> Vec3
pub fn project_axis(&self, axis: Vec3) -> Vec3
Projects axis onto plane regardless of bias.
Sourcepub fn project_vector(&self, vector: Vec3) -> Vec3
pub fn project_vector(&self, vector: Vec3) -> Vec3
Projects vector onto plane regardless of bias.
Sourcepub fn angle_between(&self, a: Vec3, b: Vec3) -> f32
pub fn angle_between(&self, a: Vec3, b: Vec3) -> f32
Signed angle from a to b where both vectors are in the plane.
Unlike Vec3::angle_between(), small and nearly opposite angles are precise.
Sourcepub fn translate_by(self, vec: Vec3) -> Self
pub fn translate_by(self, vec: Vec3) -> Self
Translates plane.
Sourcepub fn transform_by(self, rigid: Rigid) -> Self
pub fn transform_by(self, rigid: Rigid) -> Self
Transforms plane by direct isometry, i.e., rotation followed by translation.
use core::f32::consts::FRAC_PI_2;
use trackball::{
Plane, Rigid,
glam::{Quat, Vec3},
};
// Plane intersecting y-axis at `5.0`.
let plane = Plane::new(Vec3::Y, 5.0).transform_by(Rigid::from_rotation_translation(
// Rotation by 90 degrees before translation.
Quat::from_rotation_z(FRAC_PI_2),
// Translation after rotation.
Vec3::new(-5.0, 0.0, 0.0),
));
// Plane intersecting x-axis at `-10.0`.
assert!(plane.abs_diff_eq(Plane::new(-Vec3::X, 10.0), 1e-6));Sourcepub fn abs_diff_eq(&self, other: Self, max_abs_diff: f32) -> bool
pub fn abs_diff_eq(&self, other: Self, max_abs_diff: f32) -> bool
Whether all components are approximately equal within absolute difference max_abs_diff.