/// <summary> /// 相等 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(System.Object obj) { if (obj == null) { return(false); } Double3 p = (Double3)obj; if ((System.Object)p == null) { return(false); } return((x == p.x) && (y == p.y) && (z == p.z)); }
/// <summary> /// 夹角[0, PI] /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static double Angle(Double3 from, Double3 to) { double dot = Dot(from, to); double sqrDot = (dot * dot) / (from.sqrMagnitude * to.sqrMagnitude); if (dot > 0) { dot = System.Math.Sqrt(sqrDot); dot = System.Math.Min(dot, 1.0f); } else { dot = -System.Math.Sqrt(sqrDot); dot = System.Math.Max(dot, -1.0f); } return(System.Math.Acos(dot)); }
/// <summary> /// 求角度 /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="axis">from, to 的垂直轴</param> /// <returns></returns> public static double SignedAngle(Double3 from, Double3 to, Double3 axis) { return(0); }
/// <summary> /// 分量分别相乘,得到新的向量 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Double3 Scale(Double3 a, Double3 b) { return(new Double3(a.x * b.x, a.y * b.y, a.z * b.z)); }
/// <summary> /// 求发射光线 /// </summary> /// <param name="inDirection">入射光线</param> /// <param name="inNormal">法线</param> /// <returns></returns> public static Double3 Reflect(Double3 inDirection, Double3 inNormal) { return(inDirection - Double3.Project(inDirection, inNormal) * 2); }
/// <summary> /// 求向量vector 在平面上的投影 /// </summary> /// <param name="vector"></param> /// <param name="planeNormal">平面法向量</param> /// <returns></returns> public static Double3 ProjectOnPlane(Double3 vector, Double3 planeNormal) { return(vector - Double3.Project(vector, planeNormal)); }
/// <summary> /// vector 在 onNormal的投影 /// </summary> /// <param name="vector"></param> /// <param name="onNormal"></param> /// <returns></returns> public static Double3 Project(Double3 vector, Double3 onNormal) { Double3 normal = onNormal.normalized; return(Double3.Dot(vector, normal) * normal); }
/// <summary> /// Spherically interpolates between two vectors. 向量球面插值,非限制 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="t"></param> /// <returns></returns> public static Double3 SlerpUnclamped(Double3 a, Double3 b, double t) { return(Double3.zero); }
/// <summary> /// 非限制性在点start,end 之间插值Linearly interpolates between two points. /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="t"></param> /// <returns></returns> public static Double3 LerpUnclamped(Double3 start, Double3 end, double t) { return(start + (end - start) * t); }
/// <summary> /// 限制性在点start,end 之间插值Linearly interpolates between two points. /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="t">[0,1]</param> /// <returns></returns> public static Double3 Lerp(Double3 start, Double3 end, double t) { t = t < 0 ? 0 : t; t = t > 1 ? 1 : t; return(start + (end - start) * t); }
/// <summary> /// 求距离 /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public static double Distance(Double3 start, Double3 end) { return((start - end).magnitude); }
/// <summary> /// 点积 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static double Dot(Double3 a, Double3 b) { return(a.x * b.x + a.y * b.y + a.z * b.z); }
/// <summary> /// 叉积 Cross Product of two vectors /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Double3 Cross(Double3 lhs, Double3 rhs) { return(new Double3(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x)); }
/// <summary> /// 保持向量方向,调整向量长度 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Double3 ClampMagnitude(Double3 a, double maxLength) { return(a.normalized * maxLength); }
/// <summary> /// 绕目标轴旋转 /// </summary> /// <param name="current"></param> /// <param name="target"></param> /// <param name="maxRadiansDelta"></param> /// <param name="maxMagnitudeDelta"></param> /// <returns></returns> public static Double3 RotateTowards(Double3 current, Double3 target, double maxRadiansDelta, double maxMagnitudeDelta) { return(Double3.zero); }
/// <summary> /// Spherically interpolates between two vectors 向量球面插值 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="t"></param> /// <returns></returns> public static Double3 Slerp(Double3 a, Double3 b, double t) { return(Double3.zero); }
/// <summary> /// 获取Min向量,计算包围盒有用 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Double3 Min(Double3 a, Double3 b) { return(new Double3(System.Math.Min(a.x, b.x), System.Math.Min(a.y, b.y), System.Math.Min(a.z, b.z))); }
/// <summary> /// /// </summary> /// <param name="current"></param> /// <param name="target"></param> /// <param name="currentVelocity"></param> /// <param name="smoothTime"></param> /// <param name="maxSpeed"></param> /// <param name="deltaTime"></param> /// <returns></returns> public static Double3 SmoothDamp(Double3 current, Double3 target, ref Double3 currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { return(Double3.zero); }
/// <summary> /// 朝目标向量移动maxDistanceDelta距离,未考虑移出。 /// </summary> /// <param name="current"></param> /// <param name="target"></param> /// <param name="maxDistanceDelta"></param> /// <returns></returns> public static Double3 MoveTowards(Double3 current, Double3 target, double maxDistanceDelta) { return(current + (target - current).normalized * maxDistanceDelta); }