/// <summary> /// /// </summary> /// <param name="y"></param> /// <param name="yz"></param> /// <returns></returns> public static OrthoBasis3d CreateFromYZ(Vector3d y, Vector3d yz) { OrthoBasis3d result = default; result.SetYZ(y, yz); return(result); }
/// <summary> /// /// </summary> /// <param name="direction"></param> /// <param name="up"></param> /// <returns></returns> public static Quaterniond CreateLookAt(Vector3d direction, Vector3d up) { // impl ref // http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/ return(new Quaterniond(OrthoBasis3d.CreateLookAt(direction, up))); }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="xz"></param> /// <returns></returns> public static OrthoBasis3d CreateFromXZ(Vector3d x, Vector3d xz) { OrthoBasis3d result = default; result.SetXY(x, xz); return(result); }
/// <summary> /// /// </summary> /// <param name="z"></param> /// <param name="xz"></param> /// <returns></returns> public static OrthoBasis3d CreateFromZX(Vector3d z, Vector3d xz) { OrthoBasis3d result = default; result.SetZX(z, xz); return(result); }
/// <summary> /// /// </summary> /// <param name="y"></param> /// <param name="xy"></param> /// <returns></returns> public static OrthoBasis3d CreateFromYX(Vector3d y, Vector3d xy) { OrthoBasis3d result = default; result.SetYX(y, xy); return(result); }
/// <summary> /// Applies the inverse of this rotation to the given rotation in place. /// </summary> /// <param name="other"></param> /// <returns></returns> public OrthoBasis3d ApplyInverse(ref OrthoBasis3d other) { var x = ApplyInverse(other._x); var y = ApplyInverse(other._y); return(new OrthoBasis3d { _x = x, _y = y, _z = Vector3d.Cross(x, y) }); }
/// <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; } }
/// <summary> /// /// </summary> /// <param name="rotation"></param> public Quaterniond(OrthoBasis3d rotation) : this() { Set(ref rotation); }
/// <summary> /// /// </summary> /// <param name="eye"></param> /// <param name="target"></param> /// <param name="up"></param> /// <returns></returns> public static Orient3d CreateLookAt(Vector3d eye, Vector3d target, Vector3d up) { return(new Orient3d(OrthoBasis3d.CreateLookAt(target - eye, up), eye)); }
/// <summary> /// Creates a relative rotation from r0 to r1. /// </summary> /// <param name="from"></param> /// <param name="to"></param> public static OrthoBasis3d CreateFromTo(OrthoBasis3d from, OrthoBasis3d to) { return(CreateFromTo(ref from, ref to)); }
/// <summary> /// /// </summary> /// <param name="rotation"></param> /// <param name="translation"></param> public void Deconstruct(out OrthoBasis3d rotation, out Vector3d translation) { rotation = Rotation; translation = Translation; }
/// <summary> /// /// </summary> /// <param name="p0"></param> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public static Orient3d CreateFromPoints(Vector3d p0, Vector3d p1, Vector3d p2) { return(new Orient3d(OrthoBasis3d.CreateFromXY(p1 - p0, p2 - p0), p0)); }
/// <summary> /// Applies this rotation to the given rotation in place. /// </summary> /// <param name="other"></param> /// <returns></returns> public OrthoBasis3d Apply(OrthoBasis3d other) { return(Apply(ref other)); }
/// <summary> /// /// </summary> /// <param name="rotation"></param> /// <param name="translation"></param> public Orient3d(OrthoBasis3d rotation, Vector3d translation) { Rotation = rotation; Translation = translation; }
/// <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); }
/// <summary> /// /// </summary> /// <param name="scale"></param> /// <param name="rotation"></param> /// <param name="translation"></param> public Transform3d(Vector3d scale, OrthoBasis3d rotation, Vector3d translation) { Scale = scale; Rotation = rotation; Translation = translation; }
/// <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) { var inv = from.Inverse; return(to.Apply(ref inv)); }
/// <summary> /// /// </summary> /// <param name="rotation"></param> public bool Set(ref OrthoBasis3d rotation) { return(Set(new Quaterniond(rotation))); }
/// <summary> /// /// </summary> /// <param name="rotation"></param> public AxisAngle3d(OrthoBasis3d rotation) : this() { Set(ref rotation); }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <param name="epsilon"></param> /// <returns></returns> public bool ApproxEquals(ref OrthoBasis3d other, double epsilon = D.ZeroTolerance) { return (_x.ApproxEquals(other._x, epsilon) && _y.ApproxEquals(other._y, epsilon)); }
/// <summary> /// /// </summary> /// <param name="other"></param> /// <param name="epsilon"></param> /// <returns></returns> public bool ApproxEquals(OrthoBasis3d other, double epsilon = D.ZeroTolerance) { return(ApproxEquals(ref other, epsilon)); }
/// <summary> /// /// </summary> /// <param name="rotation"></param> public void Set(OrthoBasis3d rotation) { Set(ref rotation); }
/// <summary> /// /// </summary> /// <param name="scale"></param> /// <param name="orientation"></param> public Transform3d(Vector3d scale, Orient3d orientation) { Scale = scale; Rotation = orientation.Rotation; Translation = orientation.Translation; }
/// <summary> /// /// </summary> /// <param name="rotation"></param> /// <returns></returns> public bool Set(OrthoBasis3d rotation) { return(Set(ref rotation)); }
/// <summary> /// Applies the inverse of this rotation to the given rotation in place. /// </summary> /// <param name="other"></param> /// <returns></returns> public OrthoBasis3d ApplyInverse(OrthoBasis3d other) { return(ApplyInverse(ref other)); }