pub struct Frame { /* private fields */ }Expand description
A right-handed orthonormal frame: an origin and axes x, y, z with
x × y = z, each unit to within rounding, whatever the constructor was
given. Every analytic surface and curve is placed by one, so a
transform is a frame change and nothing else (docs/DATA-MODEL.md
§Conventions).
Only the validating constructors build one; there is no way to hold a
Frame whose axes are not orthonormal.
use arris_math::{Frame, Point3, Vec3};
let f = Frame::new(Point3::new(1.0, 2.0, 3.0), Vec3::z(), Vec3::new(1.0, 1.0, 0.0)).unwrap();
let local = Point3::new(1.0, 0.0, 0.0);
let world = f.to_world(local);
assert!((f.to_local(world) - local).norm() < 1e-15);
assert!((f.x().dot(&f.y())).abs() < 1e-15);Implementations§
Source§impl Frame
impl Frame
Sourcepub fn new(origin: Point3, z: Vec3, x_hint: Vec3) -> Result<Self, FrameError>
pub fn new(origin: Point3, z: Vec3, x_hint: Vec3) -> Result<Self, FrameError>
A frame with axis z (normalised) and x the direction of
x_hint’s component perpendicular to z; y = z × x.
Errors: a non-finite input, a zero z, or a hint with no
perpendicular component. A hint that is nearly parallel to z
still yields an orthonormal frame, but its x is whatever rounding
left of the perpendicular component; a caller who wants to reject
that compares the hint against z with its own Tolerance first.
Sourcepub fn from_z(origin: Point3, z: Vec3) -> Result<Self, FrameError>
pub fn from_z(origin: Point3, z: Vec3) -> Result<Self, FrameError>
A frame with axis z and x chosen by the rule Open CASCADE’s
gp_Ax3(P, N) uses (read in the reference tree’s gp package,
reimplemented): zero the axis coordinate of smallest magnitude, swap
the other two with the sign that keeps the larger one, so a
cylinder built from an axis alone seams where the oracle’s does.
For z along a coordinate axis: +z ↦ x = +x, +x ↦ x = +z,
+y ↦ x = +z.
Errors: a non-finite input or a zero z.
Sourcepub fn from_orthonormal(
origin: Point3,
x: Vec3,
y: Vec3,
z: Vec3,
) -> Result<Self, FrameError>
pub fn from_orthonormal( origin: Point3, x: Vec3, y: Vec3, z: Vec3, ) -> Result<Self, FrameError>
A frame from axes that already are one: each unit, mutually
perpendicular and z = x × y, all to rounding
(crate::RELATIVE_ROUNDING), stored bit for bit — what the
native format reads a frame back through, so a round trip changes
nothing. Errors: a non-finite input, or
FrameError::NotOrthonormal.
use arris_math::{Frame, FrameError, Point3, Vec3};
let f = Frame::from_orthonormal(Point3::origin(), Vec3::y(), Vec3::z(), Vec3::x()).unwrap();
assert_eq!(f.x().into_inner(), Vec3::y());
let bad = Frame::from_orthonormal(Point3::origin(), Vec3::x(), Vec3::x(), Vec3::z());
assert_eq!(bad, Err(FrameError::NotOrthonormal));Sourcepub fn from_rotation(origin: Point3, rotation: &UnitQuaternion<f64>) -> Self
pub fn from_rotation(origin: Point3, rotation: &UnitQuaternion<f64>) -> Self
The frame whose axes are the images of the coordinate axes under
rotation. Infallible: a unit quaternion’s basis is orthonormal.
Sourcepub const fn with_origin(&self, origin: Point3) -> Frame
pub const fn with_origin(&self, origin: Point3) -> Frame
The same axes at another origin, bit for bit: a translation that
leaves the orientation untouched, where transformed by a pure
translation would re-round the axes through the identity rotation.
Sourcepub fn vec_to_local(&self, v: Vec3) -> Vec3
pub fn vec_to_local(&self, v: Vec3) -> Vec3
The components of a world vector along the axes.
Sourcepub fn vec_to_world(&self, v: Vec3) -> Vec3
pub fn vec_to_world(&self, v: Vec3) -> Vec3
The world vector with local components v.
Sourcepub fn rotation(&self) -> UnitQuaternion<f64>
pub fn rotation(&self) -> UnitQuaternion<f64>
The rotation taking the coordinate axes onto this frame’s axes.
Sourcepub fn as_isometry(&self) -> Isometry
pub fn as_isometry(&self) -> Isometry
The rigid motion taking local coordinates to world coordinates:
as_isometry().apply(p) == to_world(p) to rounding.
Sourcepub fn transformed(&self, motion: &Isometry) -> Frame
pub fn transformed(&self, motion: &Isometry) -> Frame
This frame moved by motion. Moving geometry is moving its frame,
and this is that.
Trait Implementations§
impl Copy for Frame
impl StructuralPartialEq for Frame
Auto Trait Implementations§
impl Freeze for Frame
impl RefUnwindSafe for Frame
impl Send for Frame
impl Sync for Frame
impl Unpin for Frame
impl UnsafeUnpin for Frame
impl UnwindSafe for Frame
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.