Quaternion 结构

定义

表示三维旋转的结构。Structure that represents a rotation in three dimensions.

public value class Quaternion : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Media.Media3D.QuaternionConverter))]
public struct Quaternion : IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Media.Media3D.QuaternionConverter))]
[System.Serializable]
public struct Quaternion : IFormattable
type Quaternion = struct
    interface IFormattable
Public Structure Quaternion
Implements IFormattable
继承
Quaternion
属性
实现

示例

<!-- Trigger the rotation animation when the 3D object loads. -->
<Viewport3D.Triggers>
  <EventTrigger RoutedEvent="Viewport3D.Loaded">
    <BeginStoryboard>
      <Storyboard>

        <!-- This animation animates the Rotation property of the RotateTransform3D
             causing the 3D shape to rotate. -->
        <QuaternionAnimation
         Storyboard.TargetName="myQuaternionRotation3D"
         Storyboard.TargetProperty="Quaternion" From="0,0,1,0" To="0.3, 0.3, 1, 0" 
         Duration="0:0:2" />

      </Storyboard>
    </BeginStoryboard>
  </EventTrigger>
</Viewport3D.Triggers>
//Read new settings
try
{
    Double WValue = System.Convert.ToDouble(QuaternionWText.Text);
    Double XValue = System.Convert.ToDouble(QuaternionXText.Text);
    Double YValue = System.Convert.ToDouble(QuaternionYText.Text);
    Double ZValue = System.Convert.ToDouble(QuaternionZText.Text);

    endQuaternion = new Quaternion(XValue, YValue, ZValue, WValue);
}
catch
{
    MessageBox.Show("Set non-null values for the quaternion.");
}

myQuaternionRotation3D = new QuaternionRotation3D(endQuaternion);
myRotateTransform3D.Rotation = myQuaternionRotation3D;

//update matrix display
qrotationMatrix3D = myRotateTransform3D.Value;
'Read new settings
Try
    Dim WValue As Double = Convert.ToDouble(QuaternionWText.Text)
    Dim XValue As Double = Convert.ToDouble(QuaternionXText.Text)
    Dim YValue As Double = Convert.ToDouble(QuaternionYText.Text)
    Dim ZValue As Double = Convert.ToDouble(QuaternionZText.Text)

    endQuaternion = New Quaternion(XValue, YValue, ZValue, WValue)
Catch
    MessageBox.Show("Set non-null values for the quaternion.")
End Try

myQuaternionRotation3D = New QuaternionRotation3D(endQuaternion)
myRotateTransform3D.Rotation = myQuaternionRotation3D

'update matrix display
qrotationMatrix3D = myRotateTransform3D.Value

注解

通过使用四元数,可以在应用于对象的旋转转换之间进行插入,从而更容易计算旋转的平滑动画。Quaternions allow you to interpolate between rotation transformations applied to an object, thereby making it easier to compute smooth animations of rotations. 四元数表示旋转轴以及围绕该轴旋转。A quaternion represents an axis of rotation and a rotation around that axis. 可以单独定义旋转对象的起始位置和结束位置的旋转轴和角度,但在动画过程中该对象的中间位置不确定。It's possible to individually define the axis and angle of rotation of the starting and ending positions of a rotated object ,but the intermediate positions of that object during an animation are computationally uncertain. 通过确定表示三维对象的原始方向的四元数,以及一个表示其目标方向的四元数,可以在这些方向之间平稳插值。By determining a quaternion that represents the original orientation of a 3-D object and one that represents its destination orientation, you can smoothly interpolate between those orientations.

在 XAML 中,Quaternion 的值之间的分隔符可以是逗号或空格。In XAML, the delimiter between the values of a Quaternion can be either a comma or a space.

某些区域性可能使用逗号字符作为小数分隔符,而不是句点字符。Some cultures might use the comma character as the decimal delimiter instead of the period character. 在大多数 XAML 处理器实现中,用于固定区域性的 XAML 处理默认为 en-us,并期望句点是小数分隔符。XAML processing for invariant culture defaults to en-US in most XAML processor implementations, and expects the period to be the decimal delimiter. 如果在 XAML 中指定 Quaternion,则应避免使用逗号字符作为小数分隔符,因为这将与 Quaternion 特性值在其组件中的字符串类型转换冲突。You should avoid using the comma character as the decimal delimiter if specifying a Quaternion in XAML, because that will clash with the string type conversion of a Quaternion attribute value into its components.

XAML 特性用法XAML Attribute Usage

<object property="x,y,z,w"/>  
-or-  
<object property="x y z w"/>  

XAML 值XAML Values

xx
Quaternion 结构的 X 组件。The X component of this Quaternion structure.

yy
Quaternion 结构的 Y 组件。The Y component of this Quaternion structure.

zz
Quaternion 结构的 Z 组件。The Z component of this Quaternion structure.

ww
Quaternion 结构的 W 组件。The W component of this Quaternion structure.

构造函数

Quaternion(Double, Double, Double, Double)

初始化 Quaternion 结构的新实例。Initializes a new instance of the Quaternion structure.

Quaternion(Vector3D, Double)

初始化 Quaternion 结构的新实例。Initializes a new instance of the Quaternion structure.

属性

Angle

获取四元数的角度(以度为单位)。Gets the quaternion's angle, in degrees.

Axis

获取四元数的轴。Gets the quaternion's axis.

Identity

获取 Identity 四元数。Gets the Identity quaternion.

IsIdentity

获取一个值,该值指示指定的四元数是否为 Identity 四元数。Gets a value that indicates whether the specified quaternion is an Identity quaternion.

IsNormalized

获取指示四元数是否规范化的值。Gets a value that indicates whether the quaternion is normalized.

W

获取四元数的 W 分量。Gets the W component of the quaternion.

X

获取四元数的 X 分量。Gets the X component of the quaternion.

Y

获取四元数的 Y 分量。Gets the Y component of the quaternion.

Z

获取四元数的 Z 分量。Gets the Z component of the quaternion.

方法

Add(Quaternion, Quaternion)

将指定的四元数相加。Adds the specified quaternions.

Conjugate()

用四元数的共轭替换四元数。Replaces a quaternion with its conjugate.

Equals(Object)

比较两个 Quaternion 实例是否相等。Compares two Quaternion instances for equality.

Equals(Quaternion)

比较两个 Quaternion 实例是否相等。Compares two Quaternion instances for equality.

Equals(Quaternion, Quaternion)

比较两个 Quaternion 实例是否相等。Compares two Quaternion instances for equality.

GetHashCode()

返回 Quaternion 的哈希代码。Returns the hash code for the Quaternion.

Invert()

用四元数的逆矩阵替换指定的四元数。Replaces the specified quaternion with its inverse.

Multiply(Quaternion, Quaternion)

将两个指定的 Quaternion 值相乘。Multiplies the specified Quaternion values.

Normalize()

返回规范化的四元数。Returns a normalized quaternion.

Parse(String)

Quaternion 的字符串表示形式转换为等效的 Quaternion 结构。Converts a string representation of a Quaternion into the equivalent Quaternion structure.

Slerp(Quaternion, Quaternion, Double)

使用球状线性插入方式,在两个方向之间进行插入。Interpolates between two orientations using spherical linear interpolation.

Slerp(Quaternion, Quaternion, Double, Boolean)

使用球状线性插入方法在方向之间进行插入,如 Quaternion 结构所示。Interpolates between orientations, represented as Quaternion structures, using spherical linear interpolation.

Subtract(Quaternion, Quaternion)

从另一个四元数中减去一个四元数。Subtracts a Quaternion from another.

ToString()

创建对象的字符串表示形式。Creates a string representation of the object.

ToString(IFormatProvider)

创建对象的字符串表示形式。Creates a string representation of the object.

运算符

Addition(Quaternion, Quaternion)

加上指定的 Quaternion 值。Adds the specified Quaternion values.

Equality(Quaternion, Quaternion)

比较两个 Quaternion 实例是否完全相等。Compares two Quaternion instances for exact equality.

Inequality(Quaternion, Quaternion)

比较两个 Quaternion 实例是否完全不相等。Compares two Quaternion instances for exact inequality.

Multiply(Quaternion, Quaternion)

将指定的四元数与另一个四元数相乘。Multiplies the specified quaternion by another.

Subtraction(Quaternion, Quaternion)

从另一个四元数中减去指定的四元数。Subtracts a specified quaternion from another.

显式接口实现

IFormattable.ToString(String, IFormatProvider)

此成员支持 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基础结构,但不能在代码中直接使用。This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code. 有关此成员的说明,请参见 ToString(String, IFormatProvider)For a description of this member, see ToString(String, IFormatProvider).

适用于