Beispiel #1
0
		/// <summary>
		/// Multiplication operator.
		/// </summary>
		/// <param name="q1"> The lhs operand. </param>
		/// <param name="q2"> The rhs operand. </param>
		/// <returns> A new <see cref="Quaternion"/> that is the product of q1 and q2. </returns>
		public static Quaternion operator*(Quaternion q1, Quaternion q2)
		{
			Quaternion ret = new Quaternion();
			ret.Scalar = q1.Scalar * q2.Scalar - q1.Vector.Dot(q2.Vector);
			ret.Vector = q2.Vector * q1.Scalar + q1.Vector * q2.Scalar + q1.Vector.Cross(q2.Vector);
			return ret;
		}
Beispiel #2
0
		/// <summary>
		/// Rotates the vector about the given axis with the given angle.
		/// </summary>
		/// <param name="axis"> Axis of rotation. </param>
		/// <param name="angle"> Angle of rotation. </param>
		public Vector Rotate(Vector axis, Angle angle)
		{
			// quaternion method
			Quaternion R = new Quaternion();
			R.Scalar = (angle/2.0).Cos();
			R.Vector = axis.Normalize() * (angle/2.0).Sin();
			Quaternion v = new Quaternion(0.0, this);
			Quaternion res = R * v * R.T();
			return res.Vector;
		}