Esempio n. 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)
         );
 }
Esempio n. 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);
        }
Esempio n. 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;
            }
        }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public Quaterniond(OrthoBasis3d rotation)
     : this()
 {
     Set(ref rotation);
 }
Esempio n. 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);
 }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public bool Set(ref OrthoBasis3d rotation)
 {
     return(Set(new Quaterniond(rotation)));
 }
Esempio n. 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);
 }
Esempio n. 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;
 }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public AxisAngle3d(OrthoBasis3d rotation)
     : this()
 {
     Set(ref rotation);
 }
Esempio n. 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 /// <param name="translation"></param>
 public Orient3d(OrthoBasis3d rotation, Vec3d translation)
 {
     Rotation    = rotation;
     Translation = translation;
 }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 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);
 }
Esempio n. 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;
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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);
 }
Esempio n. 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);
 }