/// <summary> /// Determines whether this instance of type <see cref="EulerAngles" /> can be considered /// equal to another. /// </summary> /// <param name="other"> Another set of angles. </param> /// <param name="precision"> Precision of comparison. </param> /// <returns> /// True, if difference between components of the angles is less then <paramref /// name="precision" />. /// </returns> public bool IsEquivalent(EulerAngles other, float precision = MathHelpers.ZeroTolerance) { return (Math.Abs(this.Pitch - other.Pitch) < precision && Math.Abs(this.Roll - other.Roll) < precision && Math.Abs(this.Yaw - other.Yaw) < precision); }
/// <summary> /// Creates a matrix that represents rotation represented by given Euler angles. /// </summary> /// <param name="rad">Angles of rotation.</param> /// <param name="t"> Optional translation vector.</param> /// <returns>A new matrix that represents rotation represented by given Euler angles.</returns> public static Matrix34 CreateRotationWithEulerAngles(EulerAngles rad, Vector3 t = default(Vector3)) { var matrix = new Matrix34(); matrix.SetRotationWithEulerAngles(rad, t); return(matrix); }
/// <summary> /// Creates new matrix that is set to represent rotation around fixed Axes. /// </summary> /// <param name="rad">Angles of rotation.</param> /// <returns>New matrix.</returns> public static Matrix33 CreateRotationFromAngles(EulerAngles rad) { var matrix = new Matrix33(); matrix.SetRotationFromAngles(rad); return(matrix); }
/// <summary> /// Sets this matrix to represent rotation around fixed Axes. /// </summary> /// <param name="rad"><see cref="EulerAngles"/> that defines rotations around XYZ.</param> public void SetRotationFromAngles(EulerAngles rad) { double sx, cx; MathHelpers.SinCos(rad.Pitch, out sx, out cx); double sy, cy; MathHelpers.SinCos(rad.Roll, out sy, out cy); double sz, cz; MathHelpers.SinCos(rad.Yaw, out sz, out cz); double sycz = (sy * cz), sysz = (sy * sz); this.M00 = (float)(cy * cz); this.M01 = (float)(sycz * sx - cx * sz); this.M02 = (float)(sycz * cx + sx * sz); this.M10 = (float)(cy * sz); this.M11 = (float)(sysz * sx + cx * cz); this.M12 = (float)(sysz * cx - sx * cz); this.M20 = (float)(-sy); this.M21 = (float)(cy * sx); this.M22 = (float)(cy * cx); }
/// <summary> /// Checks equality of this object and given one. /// </summary> /// <param name="obj"> Given object. </param> /// <returns> /// True, if given object is <see cref="EulerAngles" /> equal to this instance, otherwise false. /// </returns> public override bool Equals(object obj) { if (!(obj is EulerAngles)) { return(false); } EulerAngles o = (EulerAngles)obj; // ReSharper disable CompareOfFloatsByEqualityOperator return(o.Pitch == this.Pitch && this.Roll == o.Roll && this.Yaw == o.Yaw); // ReSharper restore CompareOfFloatsByEqualityOperator }
/// <summary> /// Convert three Euler angles to 3x3 matrix (rotation order:XYZ) /// </summary> /// <param name="rad">Angles of rotation.</param> /// <param name="t"> Optional translation vector.</param> public void SetRotationWithEulerAngles(EulerAngles rad, Vector3 t = default(Vector3)) { this = new Matrix34(Matrix33.CreateRotationFromAngles(rad)); this.SetTranslation(t); }
/// <summary> /// Determines whether this instance of type <see cref="EulerAngles" /> can be considered /// equal to another. /// </summary> /// <param name="other"> Another set of angles. </param> /// <param name="precision"> Precision of comparison. </param> /// <returns> /// True, if difference between components of the angles is less then <paramref /// name="precision" />. /// </returns> public bool IsEquivalent(EulerAngles other, float precision = MathHelpers.ZeroTolerance) { return Math.Abs(this.Pitch - other.Pitch) < precision && Math.Abs(this.Roll - other.Roll) < precision && Math.Abs(this.Yaw - other.Yaw) < precision; }