public static IEnumerable <float> NormalDistribution() { bool ready = false; float second = 0.0f; while (true) { if (ready) { ready = false; yield return(second); } else { var cr = UnityEngine.Random.insideUnitCircle; var lcr = cr.magnitude; var r = MathExOps.Sqrt(-2.0f * MathExOps.Log(lcr) / lcr); second = r * cr.x; ready = true; yield return(r * cr.y); } } // yield break; }
public static float easeExpoInOut(float t) { if (t == 0f) { return(0f); } if (t == 1f) { return(1f); } t *= 2f; if (t < 1f) { return(0.5f * MathExOps.Pow(2f, 10f * (t - 1f))); } return(1f - 0.5f * MathExOps.Pow(2f, -10f * (t - 1f))); }
protected int calculateT(ref float t) { int i; if (t >= 1f) { t = 1f; i = p.Length - 4; } else { t = MathExOps.Clamp(t, 0, 1) * (numberOfNodes - 1); i = (int)t; t -= i; i *= 3; } return(i); }
public static IEnumerable <CurveIterator <vec2> > Iterate(this circle c, int sectors) { if (c.isEmpty) { yield break; } float dA0 = 0; float dA = 2f * MathExOps.PI / sectors; for (int i = 0; i <= sectors; i++) { Foreach.CurveIterator <vec2> ci = new Foreach.CurveIterator <vec2>(); float a = dA0 + i * dA; ci.t = ((float)i) / sectors; ci.value = c.o + c.r * (new vec2(MathExOps.Cos(a), MathExOps.Sin(a))); yield return(ci); } yield break; }
public circle(vec2 a, vec2 b, vec2 c) { float det = (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y); if (MathExOps.Abs(det) < float.Epsilon) { o = vec2.empty; r = 0f; } else { float offset = b ^ b; float bc = ((a ^ a) - offset) / 2f; float cd = (offset - (c ^ c)) / 2f; float idet = 1f / det; o = new vec2((bc * (b.y - c.y) - cd * (a.y - b.y)) * idet , (cd * (a.x - b.x) - bc * (b.x - c.x)) * idet); r = (a - o).length; } }
public static IEnumerable <CurveIterator <T> > IterateEquidistant <T>(this curve <T> c, float fraction) { var d = c.distance; float length = d.length; float delta = d.length * fraction; float cd = 0; while (true) { CurveIterator <T> i; i.t = d.time(cd); i.value = c.value(i.t); i.velocity = c.velocity(i.t); yield return(i); if (cd == length) { yield break; } cd = MathExOps.Clamp(cd + delta, 0, length); } }
public static IEnumerable <CurveIterator <T> > Iterate <T>(this curve <T> c, float stepMultiplier) { float sl = c.length; float islsl = 1 / (sl * sl); float t = 0; while (true) { CurveIterator <T> i; i.t = t; i.value = c.value(t); i.velocity = c.velocity(t); yield return(i); if (t == 1) { yield break; } float dt = MathExOps.Clamp(MathTypeTag <T> .Get().scalar(i.velocity) * islsl * stepMultiplier, islsl, 1); t = MathExOps.Clamp01(t + dt); } }
public static int Clamp(this vec2 v, int f) { return(MathExOps.Clamp(f, (int)v.x, (int)v.y)); }
public static vec2 Adc(this vec2 v, float th) { return(new vec2(MathExOps.Abs(v.x) < th ? 0 : MathExOps.Sign(v.x), MathExOps.Abs(v.y) < th ? 0 : MathExOps.Sign(v.y))); }
public static vec2i Clamp(this vec2i v, vec2i min, vec2i max) { return(MathExOps.Clamp(v, min, max)); }
public static float Clamp(this vec2i v, float f) { return(MathExOps.Clamp(f, v.x, v.y)); }
public static bool eq(float a, float b, float eps) => MathExOps.Abs(a - b) <= eps;
public static float easeExpoOut(float t) { return(t == 1f ? 1f : 1f - MathExOps.Pow(2f, -10f * t)); }
public static float easeExpoIn(float t) { return(t == 0f ? 0f : MathExOps.Pow(2f, 10f * (t - 1f))); }