/// <summary> /// Determines whether this instance can be considered equal to another. /// </summary> /// <param name="p"> Another object. </param> /// <param name="epsilon"> Precision of comparison. </param> /// <returns> True, if this instance can be considered equal to another. </returns> public bool IsEquivalent(QuaternionTranslation p, float epsilon = 0.05f) { var q0 = p.Q; var q1 = -p.Q; bool t0 = (Math.Abs(this.Q.V.X - q0.V.X) <= epsilon) && (Math.Abs(this.Q.V.Y - q0.V.Y) <= epsilon) && (Math.Abs(this.Q.V.Z - q0.V.Z) <= epsilon) && (Math.Abs(this.Q.W - q0.W) <= epsilon); bool t1 = (Math.Abs(this.Q.V.X - q1.V.X) <= epsilon) && (Math.Abs(this.Q.V.Y - q1.V.Y) <= epsilon) && (Math.Abs(this.Q.V.Z - q1.V.Z) <= epsilon) && (Math.Abs(this.Q.W - q1.W) <= epsilon); return((t0 | t1) && (Math.Abs(this.T.X - p.T.X) <= epsilon) && (Math.Abs(this.T.Y - p.T.Y) <= epsilon) && (Math.Abs(this.T.Z - p.T.Z) <= epsilon)); }
/// <summary> /// Calculates normalized linear interpolation. /// </summary> /// <param name="start"> Starting point. </param> /// <param name="end"> Ending point. </param> /// <param name="amount"> Amount of interpolation. </param> public void NormalizedLinearInterpolation(QuaternionTranslation start, QuaternionTranslation end, float amount) { var d = end.Q; if ((start.Q | d) < 0) { d = -d; } var vDiff = d.V - start.Q.V; this.Q.V = start.Q.V + (vDiff * amount); this.Q.W = start.Q.W + ((d.W - start.Q.W) * amount); this.Q.Normalize(); vDiff = end.T - start.T; this.T = start.T + (vDiff * amount); }
public void SetFromVectors(Vector3 vx, Vector3 vy, Vector3 vz, Vector3 pos) { var m34 = new Matrix34 { M00 = vx.X, M01 = vy.X, M02 = vz.X, M03 = pos.X, M10 = vx.Y, M11 = vy.Y, M12 = vz.Y, M13 = pos.Y, M20 = vx.Z, M21 = vy.Z, M22 = vz.Z, M23 = pos.Z }; this = new QuaternionTranslation(m34); }
/// <summary> /// Determines whether this instance can be considered equal to another. /// </summary> /// <param name="p"> Another object. </param> /// <param name="epsilon"> Precision of comparison. </param> /// <returns> True, if this instance can be considered equal to another. </returns> public bool IsEquivalent(QuaternionTranslation p, float epsilon = 0.05f) { var q0 = p.Q; var q1 = -p.Q; bool t0 = (Math.Abs(this.Q.V.X - q0.V.X) <= epsilon) && (Math.Abs(this.Q.V.Y - q0.V.Y) <= epsilon) && (Math.Abs(this.Q.V.Z - q0.V.Z) <= epsilon) && (Math.Abs(this.Q.W - q0.W) <= epsilon); bool t1 = (Math.Abs(this.Q.V.X - q1.V.X) <= epsilon) && (Math.Abs(this.Q.V.Y - q1.V.Y) <= epsilon) && (Math.Abs(this.Q.V.Z - q1.V.Z) <= epsilon) && (Math.Abs(this.Q.W - q1.W) <= epsilon); return ((t0 | t1) && (Math.Abs(this.T.X - p.T.X) <= epsilon) && (Math.Abs(this.T.Y - p.T.Y) <= epsilon) && (Math.Abs(this.T.Z - p.T.Z) <= epsilon)); }