public NuGenRot3D(NuGenVec3D from, NuGenVec3D to) { from.Normalize(); to.Normalize(); double cost = NuGenVec3D.Dot(from, to) / Math.Sqrt(NuGenVec3D.Dot(from, to) * NuGenVec3D.Dot(to, to)); if (cost > 0.99999) { r = 1; v = new NuGenVec3D(0, 0, 0); } else if (cost < -0.99999) { NuGenVec3D frm = from.Normalized; v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitX); if (v.Length < 0.00001) { v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitY); } r = 0; v.Normalize(); } else { r = Math.Sqrt(0.5 * (1.0 + cost)); v = NuGenVec3D.Cross(from, to); v *= Math.Sqrt((0.5 * (1.0 - cost)) / NuGenVec3D.Dot(v, v)); } }
public NuGenRot3D(NuGenVec3D from, NuGenVec3D to) { from.Normalize(); to.Normalize(); double cost = NuGenVec3D.Dot(from, to) / Math.Sqrt(NuGenVec3D.Dot(from, to) * NuGenVec3D.Dot(to, to)); if (cost > 0.99999) { r = 1; v = new NuGenVec3D(0, 0, 0); } else if (cost < -0.99999) { NuGenVec3D frm = from.Normalized; v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitX); if (v.Length < 0.00001) v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitY); r = 0; v.Normalize(); } else { r = Math.Sqrt(0.5 * (1.0 + cost)); v = NuGenVec3D.Cross(from, to); v *= Math.Sqrt((0.5 * (1.0 - cost))/NuGenVec3D.Dot(v, v)); } }
public NuGenRot3D(double radians, NuGenVec3D axis) { axis.Normalize(); r = Math.Cos(radians / 2.0); v = axis.Normalized * Math.Sin(radians / 2.0); }
public NuGenRot3D(double radians, NuGenVec3D axis) { axis.Normalize(); r = Math.Cos(radians/2.0); v = axis.Normalized * Math.Sin(radians/2.0); }