Beispiel #1
0
 /// <summary>
 /// Applies the inverse of this rotation to the given rotation.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public void ApplyInverse(ref OrthoBasis3d other, ref OrthoBasis3d result)
 {
     result.SetXY(
         ApplyInverse(other._x),
         ApplyInverse(other._y)
         );
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="eye"></param>
        /// <param name="target"></param>
        /// <param name="up"></param>
        /// <returns></returns>
        public static Orient3d CreateLookAt(Vec3d eye, Vec3d target, Vec3d up)
        {
            var rot = new OrthoBasis3d(target - eye, up);

            rot.SwapZX();

            var orient = new Orient3d(rot, eye);

            orient.Invert();

            return(orient);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rotation"></param>
        public void Set(ref OrthoBasis3d rotation)
        {
            // impl ref
            // http://www.cs.ucr.edu/~vbz/resources/quatut.pdf

            (var x, var y, var z) = rotation;
            double trace = x.X + y.Y + z.Z;

            if (trace > 0.0)
            {
                double s = Math.Sqrt(trace + 1.0);
                W = 0.5 * s;

                s = 0.5 / s;
                X = (y.Z - z.Y) * s;
                Y = (z.X - x.Z) * s;
                Z = (x.Y - y.X) * s;
            }
            else if (Math.Abs(x.X) > Math.Abs(y.Y) && Math.Abs(x.X) > Math.Abs(z.Z))
            {
                double s = Math.Sqrt(1.0 + x.X - y.Y - z.Z);
                X = 0.5 * s;

                s = 0.5 / s;
                Y = (x.Y + y.X) * s;
                Z = (z.X + x.Z) * s;
                W = (y.Z - z.Y) * s;
            }
            else if (Math.Abs(y.Y) > Math.Abs(z.Z))
            {
                double s = Math.Sqrt(1.0 - x.X + y.Y - z.Z);
                Y = 0.5 * s;

                s = 0.5 / s;
                X = (x.Y + y.X) * s;
                Z = (y.Z + z.Y) * s;
                W = (z.X - x.Z) * s;
            }
            else
            {
                double s = Math.Sqrt(1.0 - x.X - y.Y + z.Z);
                Z = 0.5 * s;

                s = 0.5 / s;
                X = (z.X + x.Z) * s;
                Y = (y.Z + z.Y) * s;
                W = (x.Y - y.X) * s;
            }
        }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public Quaterniond(OrthoBasis3d rotation)
     : this()
 {
     Set(ref rotation);
 }
Beispiel #5
0
 /// <summary>
 /// Applies this rotation to the given rotation.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public OrthoBasis3d Apply(OrthoBasis3d other)
 {
     Apply(ref other, ref other);
     return(other);
 }
Beispiel #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public bool Set(ref OrthoBasis3d rotation)
 {
     return(Set(new Quaterniond(rotation)));
 }
Beispiel #7
0
 /// <summary>
 /// Applies the given rotation to the axis of this rotation.
 /// </summary>
 /// <param name="rotation"></param>
 public void RotateAxis(ref OrthoBasis3d rotation)
 {
     _axis = rotation.Apply(_axis);
 }
Beispiel #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 public void Deconstruct(out OrthoBasis3d rotation, out Vec3d translation)
 {
     rotation    = Rotation;
     translation = Translation;
 }
Beispiel #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public AxisAngle3d(OrthoBasis3d rotation)
     : this()
 {
     Set(ref rotation);
 }
Beispiel #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 /// <param name="translation"></param>
 public Orient3d(OrthoBasis3d rotation, Vec3d translation)
 {
     Rotation    = rotation;
     Translation = translation;
 }
Beispiel #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="origin"></param>
 /// <param name="xAxis"></param>
 /// <param name="xyVector"></param>
 public Orient3d(Vec3d origin, Vec3d xAxis, Vec3d xyVector)
 {
     Rotation    = new OrthoBasis3d(xAxis, xyVector);
     Translation = origin;
 }
Beispiel #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="scale"></param>
 /// <param name="orientation"></param>
 public Transform3d(Vec3d scale, Orient3d orientation)
 {
     Scale       = scale;
     Rotation    = orientation.Rotation;
     Translation = orientation.Translation;
 }
Beispiel #13
0
 /// <summary>
 /// Applies this rotation to the given rotation in place.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public void Apply(ref OrthoBasis3d other)
 {
     Apply(ref other, ref other);
 }
Beispiel #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="scale"></param>
 /// <param name="rotation"></param>
 /// <param name="translation"></param>
 public Transform3d(Vec3d scale, OrthoBasis3d rotation, Vec3d translation)
 {
     Scale       = scale;
     Rotation    = rotation;
     Translation = translation;
 }
Beispiel #15
0
 /// <summary>
 /// Creates a relative rotation from r0 to r1.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 public static OrthoBasis3d CreateFromTo(ref OrthoBasis3d from, ref OrthoBasis3d to)
 {
     return(to.Apply(from.Inverse));
 }
Beispiel #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 public bool ApproxEquals(ref OrthoBasis3d other, double tolerance = zMath.ZeroTolerance)
 {
     return
         (_x.ApproxEquals(other._x, tolerance) &&
          _y.ApproxEquals(other._y, tolerance));
 }
Beispiel #17
0
 /// <summary>
 /// Applies the inverse of this rotation to the given rotation.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public OrthoBasis3d ApplyInverse(OrthoBasis3d other)
 {
     ApplyInverse(ref other, ref other);
     return(other);
 }
Beispiel #18
0
 /// <summary>
 /// Applies the inverse of this rotation to the given rotation in place.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public void ApplyInverse(ref OrthoBasis3d other)
 {
     ApplyInverse(ref other, ref other);
 }