public static T Distance <T>(T dp, T sd) where T : IVector, new() { double lp = VecX.Project01(dp, sd); lp = MathX.Clamp(lp, 0.0, 1.0); return(VecX.Sub(dp, VecX.Mul(sd, lp))); }
public static Vec3 Distance(Vec3 dp, Vec3 sd) { double lp = VecX.Project01(dp, sd); lp = MathX.Clamp(lp, 0.0, 1.0); return(dp - lp * sd); }
public static Vec2 GetRandom() { double theta = MathX.TWO_PI * MathX.GetRandom(); Vec2 nv; nv.x = Math.Sin(theta); nv.y = Math.Cos(theta); return(nv); }
public static T Clamp <T>(T v, T min, T max) where T : IVector, new() { T nv = new T(); int dim = nv.Dimension; for (int i = 0; i < dim; i++) { nv[i] = MathX.Clamp(v[i], min[i], max[i]); } return(nv); }
public static Vec3 GetRandom() { double theta = MathX.TWO_PI * MathX.GetRandom(); double phi = Math.Acos(MathX.GetRandom(-1, 1)); Vec3 nv; nv.x = Math.Sin(theta) * Math.Sin(phi); nv.y = Math.Cos(theta) * Math.Sin(phi); nv.z = Math.Cos(phi); return(nv); }
public static Vec4 GetRandom() { //Not even double theta = MathX.TWO_PI * MathX.GetRandom(); double phi = Math.Acos(MathX.GetRandom(-1, 1)); double rho = Math.Acos(MathX.GetRandom(-1, 1)); Vec4 nv; nv.x = Math.Sin(theta) * Math.Sin(phi) * Math.Sin(rho); nv.y = Math.Cos(theta) * Math.Sin(phi) * Math.Sin(rho); nv.z = Math.Cos(phi) * Math.Sin(rho); nv.w = Math.Cos(rho); return(nv); }
public static Quat GetRandom() { double a = MathX.GetRandom(-MathX.TWO_PI, MathX.TWO_PI); return(FromAngleAxis(a, Vec3.GetRandom())); }