pub struct Quaternion {
pub w: f64,
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
四元数(用于表示3D旋转)
四元数是表示3D旋转的数学工具,避免了欧拉角的万向节锁问题。
Fields§
§w: f64实部
x: f64虚部 i
y: f64虚部 j
z: f64虚部 k
Implementations§
Source§impl Quaternion
impl Quaternion
Sourcepub fn from_euler(roll: Rad, pitch: Rad, yaw: Rad) -> Self
pub fn from_euler(roll: Rad, pitch: Rad, yaw: Rad) -> Self
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
归一化(确保单位四元数)
§数值稳定性
如果四元数的模接近 0(< 1e-10),返回默认单位四元数 (1, 0, 0, 0) 以避免除零错误和 NaN 扩散。
这种情况理论上不应发生,但在初始化错误、序列化错误或数值计算 累积误差时可能出现。
Sourcepub fn multiply(&self, other: &Quaternion) -> Quaternion
pub fn multiply(&self, other: &Quaternion) -> Quaternion
四元数乘法(组合旋转)
Sourcepub fn conjugate(&self) -> Quaternion
pub fn conjugate(&self) -> Quaternion
共轭(逆旋转)
Trait Implementations§
Source§impl Clone for Quaternion
impl Clone for Quaternion
Source§fn clone(&self) -> Quaternion
fn clone(&self) -> Quaternion
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Quaternion
impl Debug for Quaternion
Source§impl Display for Quaternion
impl Display for Quaternion
Source§impl PartialEq for Quaternion
impl PartialEq for Quaternion
impl Copy for Quaternion
impl StructuralPartialEq for Quaternion
Auto Trait Implementations§
impl Freeze for Quaternion
impl RefUnwindSafe for Quaternion
impl Send for Quaternion
impl Sync for Quaternion
impl Unpin for Quaternion
impl UnwindSafe for Quaternion
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more