Skip to main content

Frame

Struct Frame 

Source
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

Source

pub fn world() -> Self

The world frame: origin at zero, axes the coordinate axes.

Source

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.

Source

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.

Source

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));
Source

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.

Source

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.

Source

pub const fn origin(&self) -> Point3

The origin.

Source

pub const fn x(&self) -> UnitVec3

The x axis.

Source

pub const fn y(&self) -> UnitVec3

The y axis, z × x.

Source

pub const fn z(&self) -> UnitVec3

The z axis, x × y.

Source

pub fn to_local(&self, p: Point3) -> Point3

The coordinates of a world point in this frame.

Source

pub fn to_world(&self, p: Point3) -> Point3

The world point at local coordinates p.

Source

pub fn vec_to_local(&self, v: Vec3) -> Vec3

The components of a world vector along the axes.

Source

pub fn vec_to_world(&self, v: Vec3) -> Vec3

The world vector with local components v.

Source

pub fn rotation(&self) -> UnitQuaternion<f64>

The rotation taking the coordinate axes onto this frame’s axes.

Source

pub fn as_isometry(&self) -> Isometry

The rigid motion taking local coordinates to world coordinates: as_isometry().apply(p) == to_world(p) to rounding.

Source

pub fn transformed(&self, motion: &Isometry) -> Frame

This frame moved by motion. Moving geometry is moving its frame, and this is that.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Self

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 Copy for Frame

Source§

impl Debug for Frame

Source§

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

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

impl PartialEq for Frame

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.