System.Math.Sqrt(double)

Here are the examples of the csharp api System.Math.Sqrt(double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5164 Examples 7

19 Source : ZColorPicker.cs
with MIT License
from 0xLaileb

private Color PickColor(float x, float y)
        {
            float x1 = x - (float)pictureBox1.Width / 2;
            float y1 = y - (float)pictureBox1.Height / 2;
            float Radius = (float)Math.Sqrt(Math.Pow(x1, 2) + Math.Pow(y1, 2));
            if (Radius > (float)pictureBox1.Width / 2)
            {
                float mult = (float)pictureBox1.Width / 2 / Radius;
                x1 *= mult;
                y1 *= mult;
            }
            Color Color = GetPixelColor(x1, y1, ((ValueBox)pictureBox3.Tag).Value, (float)pictureBox1.Width / 2);
            if (Color == Color.Transparent) return Color.Empty;

            label1.Text = $"RGB: {Color.R}, {Color.G}, {Color.B}";
            label2.Text = $"HEX: #{Color.ToArgb():X}";
            CursorPos = new PointF(x1 + (float)pictureBox1.Width / 2, y1 + (float)pictureBox1.Height / 2);
            pictureBox2.BackColor = Color;
            ((ValueBox)pictureBox3.Tag).Color = Color;
            pictureBox1.Tag = new PointF(x, y);
            pictureBox1.Invalidate();
            pictureBox2.Invalidate();
            pictureBox3.Invalidate();

            SelectedColor = Color;
            return Color;
        }

19 Source : ZColorPicker.cs
with MIT License
from 0xLaileb

private Color GetPixelColor(float x, float y, float value, float radius)
        {
            float R = (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
            float S = (float)(R / radius);
            if (S > 1) return Color.Transparent;

            double Angle;
            if (x > 0 && y > 0) Angle = Math.Asin(y / R);
            else if (x <= 0 && y > 0) Angle = Math.Acos(y / R) + Math.PI / 2;
            else if (x <= 0 && y <= 0) Angle = Math.Asin(-y / R) + Math.PI;
            else Angle = Math.Acos(-y / R) + 3 * Math.PI / 2;
            float H = (float)(Angle / Math.PI / 2);

            return HSVtoRGB(H, S, value);
        }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static bool bidiagonalsvddecompositioninternal(ref double[] d, double[] e, int n, bool isupper, bool isfractionalaccuracyrequired, ref double[,] u, int ustart, int nru, ref double[,] c, int cstart, int ncc, ref double[,] vt, int vstart, int ncvt)
  {
    int index1 = 0;
    double num1 = 0.0;
    double num2 = 0.0;
    double cs1 = 0.0;
    double sn1 = 0.0;
    double num3 = 0.0;
    double ssmin1 = 0.0;
    double ssmin2 = 0.0;
    double ssmax = 0.0;
    double num4 = 0.0;
    double num5 = 0.0;
    double sn2 = 0.0;
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    double[] numArray4 = new double[0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double r = 0.0;
    e = (double[]) e.Clone();
    bool flag1 = true;
    if (n == 0)
      return flag1;
    if (n == 1)
    {
      if (d[1] < 0.0)
      {
        d[1] = -d[1];
        if (ncvt > 0)
        {
          for (int index2 = vstart; index2 <= vstart + ncvt - 1; ++index2)
            vt[vstart, index2] = -1.0 * vt[vstart, index2];
        }
      }
      return flag1;
    }
    double[] c1 = new double[n - 1 + 1];
    double[] s1 = new double[n - 1 + 1];
    double[] c2 = new double[n - 1 + 1];
    double[] s2 = new double[n - 1 + 1];
    int m2 = ustart + System.Math.Max(nru - 1, 0);
    int n2_1 = vstart + System.Math.Max(ncvt - 1, 0);
    int n2_2 = cstart + System.Math.Max(ncc - 1, 0);
    double[] work1 = new double[m2 + 1];
    double[] work2 = new double[n2_1 + 1];
    double[] work3 = new double[n2_2 + 1];
    int num6 = 12;
    bool isforward = true;
    double[] numArray9 = new double[n + 1];
    for (int index2 = 1; index2 <= n - 1; ++index2)
      numArray9[index2] = e[index2];
    e = new double[n + 1];
    for (int index2 = 1; index2 <= n - 1; ++index2)
      e[index2] = numArray9[index2];
    e[n] = 0.0;
    int num7 = 0;
    double num8 = 5E-16;
    double num9 = 1E-300;
    if (!isupper)
    {
      for (int index2 = 1; index2 <= n - 1; ++index2)
      {
        rotations.generaterotation(d[index2], e[index2], ref cs1, ref sn2, ref num3);
        d[index2] = num3;
        e[index2] = sn2 * d[index2 + 1];
        d[index2 + 1] = cs1 * d[index2 + 1];
        c1[index2] = cs1;
        s1[index2] = sn2;
      }
      if (nru > 0)
        rotations.applyrotationsfromtheright(isforward, ustart, m2, 1 + ustart - 1, n + ustart - 1, ref c1, ref s1, ref u, ref work1);
      if (ncc > 0)
        rotations.applyrotationsfromtheleft(isforward, 1 + cstart - 1, n + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
    }
    double num10 = System.Math.Max(10.0, System.Math.Min(100.0, System.Math.Pow(num8, -0.125))) * num8;
    if (!isfractionalaccuracyrequired)
      num10 = -num10;
    double val1_1 = 0.0;
    for (int index2 = 1; index2 <= n; ++index2)
      val1_1 = System.Math.Max(val1_1, System.Math.Abs(d[index2]));
    for (int index2 = 1; index2 <= n - 1; ++index2)
      val1_1 = System.Math.Max(val1_1, System.Math.Abs(e[index2]));
    double val1_2 = 0.0;
    double num11;
    if (num10 >= 0.0)
    {
      double val1_3 = System.Math.Abs(d[1]);
      if (val1_3 != 0.0)
      {
        double val2 = val1_3;
        for (int index2 = 2; index2 <= n; ++index2)
        {
          val2 = System.Math.Abs(d[index2]) * (val2 / (val2 + System.Math.Abs(e[index2 - 1])));
          val1_3 = System.Math.Min(val1_3, val2);
          if (val1_3 == 0.0)
            break;
        }
      }
      double num12 = val1_3 / System.Math.Sqrt((double) n);
      num11 = System.Math.Max(num10 * num12, (double) (num6 * n * n) * num9);
    }
    else
      num11 = System.Math.Max(System.Math.Abs(num10) * val1_1, (double) (num6 * n * n) * num9);
    int num13 = num6 * n * n;
    int num14 = 0;
    int num15 = -1;
    int num16 = -1;
    int index3 = n;
    while (index3 > 1)
    {
      if (num14 > num13)
        return false;
      if (num10 < 0.0 & System.Math.Abs(d[index3]) <= num11)
        d[index3] = 0.0;
      double val1_3 = System.Math.Abs(d[index3]);
      double val1_4 = val1_3;
      bool flag2 = false;
      for (int index2 = 1; index2 <= index3 - 1; ++index2)
      {
        index1 = index3 - index2;
        double num12 = System.Math.Abs(d[index1]);
        double val2 = System.Math.Abs(e[index1]);
        if (num10 < 0.0 & num12 <= num11)
          d[index1] = 0.0;
        if (val2 <= num11)
        {
          flag2 = true;
          break;
        }
        val1_4 = System.Math.Min(val1_4, num12);
        val1_3 = System.Math.Max(val1_3, System.Math.Max(num12, val2));
      }
      if (!flag2)
      {
        index1 = 0;
      }
      else
      {
        e[index1] = 0.0;
        if (index1 == index3 - 1)
        {
          --index3;
          continue;
        }
      }
      ++index1;
      if (index1 == index3 - 1)
      {
        bdsvd.svdv2x2(d[index3 - 1], e[index3 - 1], d[index3], ref ssmin2, ref ssmax, ref num5, ref num2, ref num4, ref num1);
        d[index3 - 1] = ssmax;
        e[index3 - 1] = 0.0;
        d[index3] = ssmin2;
        if (ncvt > 0)
        {
          int index2 = index3 + (vstart - 1);
          int index4 = index3 - 1 + (vstart - 1);
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = num2 * vt[index4, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = work2[index5] + num5 * vt[index2, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index2, index5] = num2 * vt[index2, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index2, index5] = vt[index2, index5] - num5 * vt[index4, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index4, index5] = work2[index5];
        }
        if (nru > 0)
        {
          int index2 = index3 + ustart - 1;
          int index4 = index3 - 1 + ustart - 1;
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = num1 * u[index5, index4];
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = work1[index5] + num4 * u[index5, index2];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index2] = num1 * u[index5, index2];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index2] = u[index5, index2] - num4 * u[index5, index4];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index4] = work1[index5];
        }
        if (ncc > 0)
        {
          int index2 = index3 + cstart - 1;
          int index4 = index3 - 1 + cstart - 1;
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = num1 * c[index4, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = work3[index5] + num4 * c[index2, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index2, index5] = num1 * c[index2, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index2, index5] = c[index2, index5] - num4 * c[index4, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index4, index5] = work3[index5];
        }
        index3 -= 2;
      }
      else
      {
        bool flag3 = false;
        if (num7 == 1 & System.Math.Abs(d[index1]) < 0.001 * System.Math.Abs(d[index3]))
          flag3 = true;
        if (num7 == 2 & System.Math.Abs(d[index3]) < 0.001 * System.Math.Abs(d[index1]))
          flag3 = true;
        if (index1 != num15 | index3 != num16 | flag3)
          num7 = System.Math.Abs(d[index1]) < System.Math.Abs(d[index3]) ? 2 : 1;
        if (num7 == 1)
        {
          if (System.Math.Abs(e[index3 - 1]) <= System.Math.Abs(num10) * System.Math.Abs(d[index3]) | num10 < 0.0 & System.Math.Abs(e[index3 - 1]) <= num11)
          {
            e[index3 - 1] = 0.0;
            continue;
          }
          if (num10 >= 0.0)
          {
            double val2 = System.Math.Abs(d[index1]);
            val1_2 = val2;
            bool flag4 = false;
            for (int index2 = index1; index2 <= index3 - 1; ++index2)
            {
              if (System.Math.Abs(e[index2]) <= num10 * val2)
              {
                e[index2] = 0.0;
                flag4 = true;
                break;
              }
              val2 = System.Math.Abs(d[index2 + 1]) * (val2 / (val2 + System.Math.Abs(e[index2])));
              val1_2 = System.Math.Min(val1_2, val2);
            }
            if (flag4)
              continue;
          }
        }
        else
        {
          if (System.Math.Abs(e[index1]) <= System.Math.Abs(num10) * System.Math.Abs(d[index1]) | num10 < 0.0 & System.Math.Abs(e[index1]) <= num11)
          {
            e[index1] = 0.0;
            continue;
          }
          if (num10 >= 0.0)
          {
            double val2 = System.Math.Abs(d[index3]);
            val1_2 = val2;
            bool flag4 = false;
            for (int index2 = index3 - 1; index2 >= index1; --index2)
            {
              if (System.Math.Abs(e[index2]) <= num10 * val2)
              {
                e[index2] = 0.0;
                flag4 = true;
                break;
              }
              val2 = System.Math.Abs(d[index2]) * (val2 / (val2 + System.Math.Abs(e[index2])));
              val1_2 = System.Math.Min(val1_2, val2);
            }
            if (flag4)
              continue;
          }
        }
        num15 = index1;
        num16 = index3;
        if (num10 >= 0.0 & (double) n * num10 * (val1_2 / val1_3) <= System.Math.Max(num8, 0.01 * num10))
        {
          ssmin1 = 0.0;
        }
        else
        {
          double num12;
          if (num7 == 1)
          {
            num12 = System.Math.Abs(d[index1]);
            bdsvd.svd2x2(d[index3 - 1], e[index3 - 1], d[index3], ref ssmin1, ref num3);
          }
          else
          {
            num12 = System.Math.Abs(d[index3]);
            bdsvd.svd2x2(d[index1], e[index1], d[index1 + 1], ref ssmin1, ref num3);
          }
          if (num12 > 0.0 && AP.Math.Sqr(ssmin1 / num12) < num8)
            ssmin1 = 0.0;
        }
        num14 = num14 + index3 - index1;
        double cs2;
        if (ssmin1 == 0.0)
        {
          if (num7 == 1)
          {
            cs1 = 1.0;
            cs2 = 1.0;
            for (int index2 = index1; index2 <= index3 - 1; ++index2)
            {
              rotations.generaterotation(d[index2] * cs1, e[index2], ref cs1, ref sn2, ref num3);
              if (index2 > index1)
                e[index2 - 1] = sn1 * num3;
              rotations.generaterotation(cs2 * num3, d[index2 + 1] * sn2, ref cs2, ref sn1, ref r);
              d[index2] = r;
              c1[index2 - index1 + 1] = cs1;
              s1[index2 - index1 + 1] = sn2;
              c2[index2 - index1 + 1] = cs2;
              s2[index2 - index1 + 1] = sn1;
            }
            double num12 = d[index3] * cs1;
            d[index3] = num12 * cs2;
            e[index3 - 1] = num12 * sn1;
            if (ncvt > 0)
              rotations.applyrotationsfromtheleft(isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c1, ref s1, ref vt, ref work2);
            if (nru > 0)
              rotations.applyrotationsfromtheright(isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c2, ref s2, ref u, ref work1);
            if (ncc > 0)
              rotations.applyrotationsfromtheleft(isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c2, ref s2, ref c, ref work3);
            if (System.Math.Abs(e[index3 - 1]) <= num11)
              e[index3 - 1] = 0.0;
          }
          else
          {
            cs1 = 1.0;
            cs2 = 1.0;
            for (int index2 = index3; index2 >= index1 + 1; --index2)
            {
              rotations.generaterotation(d[index2] * cs1, e[index2 - 1], ref cs1, ref sn2, ref num3);
              if (index2 < index3)
                e[index2] = sn1 * num3;
              rotations.generaterotation(cs2 * num3, d[index2 - 1] * sn2, ref cs2, ref sn1, ref r);
              d[index2] = r;
              c1[index2 - index1] = cs1;
              s1[index2 - index1] = -sn2;
              c2[index2 - index1] = cs2;
              s2[index2 - index1] = -sn1;
            }
            double num12 = d[index1] * cs1;
            d[index1] = num12 * cs2;
            e[index1] = num12 * sn1;
            if (ncvt > 0)
              rotations.applyrotationsfromtheleft(!isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c2, ref s2, ref vt, ref work2);
            if (nru > 0)
              rotations.applyrotationsfromtheright(!isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c1, ref s1, ref u, ref work1);
            if (ncc > 0)
              rotations.applyrotationsfromtheleft(!isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
            if (System.Math.Abs(e[index1]) <= num11)
              e[index1] = 0.0;
          }
        }
        else if (num7 == 1)
        {
          double f1 = (System.Math.Abs(d[index1]) - ssmin1) * (bdsvd.extsignbdsqr(1.0, d[index1]) + ssmin1 / d[index1]);
          double g = e[index1];
          for (int index2 = index1; index2 <= index3 - 1; ++index2)
          {
            rotations.generaterotation(f1, g, ref num2, ref num5, ref num3);
            if (index2 > index1)
              e[index2 - 1] = num3;
            double f2 = num2 * d[index2] + num5 * e[index2];
            e[index2] = num2 * e[index2] - num5 * d[index2];
            g = num5 * d[index2 + 1];
            d[index2 + 1] = num2 * d[index2 + 1];
            rotations.generaterotation(f2, g, ref num1, ref num4, ref num3);
            d[index2] = num3;
            f1 = num1 * e[index2] + num4 * d[index2 + 1];
            d[index2 + 1] = num1 * d[index2 + 1] - num4 * e[index2];
            if (index2 < index3 - 1)
            {
              g = num4 * e[index2 + 1];
              e[index2 + 1] = num1 * e[index2 + 1];
            }
            c1[index2 - index1 + 1] = num2;
            s1[index2 - index1 + 1] = num5;
            c2[index2 - index1 + 1] = num1;
            s2[index2 - index1 + 1] = num4;
          }
          e[index3 - 1] = f1;
          if (ncvt > 0)
            rotations.applyrotationsfromtheleft(isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c1, ref s1, ref vt, ref work2);
          if (nru > 0)
            rotations.applyrotationsfromtheright(isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c2, ref s2, ref u, ref work1);
          if (ncc > 0)
            rotations.applyrotationsfromtheleft(isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c2, ref s2, ref c, ref work3);
          if (System.Math.Abs(e[index3 - 1]) <= num11)
            e[index3 - 1] = 0.0;
        }
        else
        {
          double f1 = (System.Math.Abs(d[index3]) - ssmin1) * (bdsvd.extsignbdsqr(1.0, d[index3]) + ssmin1 / d[index3]);
          double g = e[index3 - 1];
          for (int index2 = index3; index2 >= index1 + 1; --index2)
          {
            rotations.generaterotation(f1, g, ref num2, ref num5, ref num3);
            if (index2 < index3)
              e[index2] = num3;
            double f2 = num2 * d[index2] + num5 * e[index2 - 1];
            e[index2 - 1] = num2 * e[index2 - 1] - num5 * d[index2];
            g = num5 * d[index2 - 1];
            d[index2 - 1] = num2 * d[index2 - 1];
            rotations.generaterotation(f2, g, ref num1, ref num4, ref num3);
            d[index2] = num3;
            f1 = num1 * e[index2 - 1] + num4 * d[index2 - 1];
            d[index2 - 1] = num1 * d[index2 - 1] - num4 * e[index2 - 1];
            if (index2 > index1 + 1)
            {
              g = num4 * e[index2 - 2];
              e[index2 - 2] = num1 * e[index2 - 2];
            }
            c1[index2 - index1] = num2;
            s1[index2 - index1] = -num5;
            c2[index2 - index1] = num1;
            s2[index2 - index1] = -num4;
          }
          e[index1] = f1;
          if (System.Math.Abs(e[index1]) <= num11)
            e[index1] = 0.0;
          if (ncvt > 0)
            rotations.applyrotationsfromtheleft(!isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c2, ref s2, ref vt, ref work2);
          if (nru > 0)
            rotations.applyrotationsfromtheright(!isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c1, ref s1, ref u, ref work1);
          if (ncc > 0)
            rotations.applyrotationsfromtheleft(!isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
        }
      }
    }
    for (int index2 = 1; index2 <= n; ++index2)
    {
      if (d[index2] < 0.0)
      {
        d[index2] = -d[index2];
        if (ncvt > 0)
        {
          for (int index4 = vstart; index4 <= n2_1; ++index4)
            vt[index2 + vstart - 1, index4] = -1.0 * vt[index2 + vstart - 1, index4];
        }
      }
    }
    for (int index2 = 1; index2 <= n - 1; ++index2)
    {
      int index4 = 1;
      double num12 = d[1];
      for (int index5 = 2; index5 <= n + 1 - index2; ++index5)
      {
        if (d[index5] <= num12)
        {
          index4 = index5;
          num12 = d[index5];
        }
      }
      if (index4 != n + 1 - index2)
      {
        d[index4] = d[n + 1 - index2];
        d[n + 1 - index2] = num12;
        if (ncvt > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = vt[index4 + vstart - 1, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index4 + vstart - 1, index5] = vt[num17 + vstart - 1, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[num17 + vstart - 1, index5] = work2[index5];
        }
        if (nru > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = u[index5, index4 + ustart - 1];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index4 + ustart - 1] = u[index5, num17 + ustart - 1];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, num17 + ustart - 1] = work1[index5];
        }
        if (ncc > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = c[index4 + cstart - 1, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index4 + cstart - 1, index5] = c[num17 + cstart - 1, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[num17 + cstart - 1, index5] = work3[index5];
        }
      }
    }
    return flag1;
  }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static void svd2x2(double f, double g, double h, ref double ssmin, ref double ssmax)
  {
    double val1_1 = System.Math.Abs(f);
    double val2_1 = System.Math.Abs(g);
    double val2_2 = System.Math.Abs(h);
    double num1 = System.Math.Min(val1_1, val2_2);
    double val1_2 = System.Math.Max(val1_1, val2_2);
    if (num1 == 0.0)
    {
      ssmin = 0.0;
      if (val1_2 == 0.0)
        ssmax = val2_1;
      else
        ssmax = System.Math.Max(val1_2, val2_1) * System.Math.Sqrt(1.0 + AP.Math.Sqr(System.Math.Min(val1_2, val2_1) / System.Math.Max(val1_2, val2_1)));
    }
    else if (val2_1 < val1_2)
    {
      double num2 = 1.0 + num1 / val1_2;
      double num3 = (val1_2 - num1) / val1_2;
      double num4 = AP.Math.Sqr(val2_1 / val1_2);
      double num5 = 2.0 / (System.Math.Sqrt(num2 * num2 + num4) + System.Math.Sqrt(num3 * num3 + num4));
      ssmin = num1 * num5;
      ssmax = val1_2 / num5;
    }
    else
    {
      double num2 = val1_2 / val2_1;
      if (num2 == 0.0)
      {
        ssmin = num1 * val1_2 / val2_1;
        ssmax = val2_1;
      }
      else
      {
        double num3 = 1.0 + num1 / val1_2;
        double num4 = (val1_2 - num1) / val1_2;
        double num5 = 1.0 / (System.Math.Sqrt(1.0 + AP.Math.Sqr(num3 * num2)) + System.Math.Sqrt(1.0 + AP.Math.Sqr(num4 * num2)));
        ssmin = num1 * num5 * num2;
        ssmin = ssmin + ssmin;
        ssmax = val2_1 / (num5 + num5);
      }
    }
  }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static void svd2x2(double f, double g, double h, ref double ssmin, ref double ssmax)
  {
    double val1_1 = System.Math.Abs(f);
    double val2_1 = System.Math.Abs(g);
    double val2_2 = System.Math.Abs(h);
    double num1 = System.Math.Min(val1_1, val2_2);
    double val1_2 = System.Math.Max(val1_1, val2_2);
    if (num1 == 0.0)
    {
      ssmin = 0.0;
      if (val1_2 == 0.0)
        ssmax = val2_1;
      else
        ssmax = System.Math.Max(val1_2, val2_1) * System.Math.Sqrt(1.0 + AP.Math.Sqr(System.Math.Min(val1_2, val2_1) / System.Math.Max(val1_2, val2_1)));
    }
    else if (val2_1 < val1_2)
    {
      double num2 = 1.0 + num1 / val1_2;
      double num3 = (val1_2 - num1) / val1_2;
      double num4 = AP.Math.Sqr(val2_1 / val1_2);
      double num5 = 2.0 / (System.Math.Sqrt(num2 * num2 + num4) + System.Math.Sqrt(num3 * num3 + num4));
      ssmin = num1 * num5;
      ssmax = val1_2 / num5;
    }
    else
    {
      double num2 = val1_2 / val2_1;
      if (num2 == 0.0)
      {
        ssmin = num1 * val1_2 / val2_1;
        ssmax = val2_1;
      }
      else
      {
        double num3 = 1.0 + num1 / val1_2;
        double num4 = (val1_2 - num1) / val1_2;
        double num5 = 1.0 / (System.Math.Sqrt(1.0 + AP.Math.Sqr(num3 * num2)) + System.Math.Sqrt(1.0 + AP.Math.Sqr(num4 * num2)));
        ssmin = num1 * num5 * num2;
        ssmin = ssmin + ssmin;
        ssmax = val2_1 / (num5 + num5);
      }
    }
  }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static void svdv2x2(double f, double g, double h, ref double ssmin, ref double ssmax, ref double snr, ref double csr, ref double snl, ref double csl)
  {
    double num1 = 0.0;
    double num2 = 0.0;
    double num3 = 0.0;
    double num4 = 0.0;
    double b1 = 0.0;
    double b2 = f;
    double num5 = System.Math.Abs(b2);
    double num6 = h;
    double num7 = System.Math.Abs(h);
    int num8 = 1;
    bool flag1 = num7 > num5;
    if (flag1)
    {
      num8 = 3;
      double num9 = b2;
      b2 = num6;
      num6 = num9;
      double num10 = num5;
      num5 = num7;
      num7 = num10;
    }
    double b3 = g;
    double num11 = System.Math.Abs(b3);
    if (num11 == 0.0)
    {
      ssmin = num7;
      ssmax = num5;
      num1 = 1.0;
      num2 = 1.0;
      num3 = 0.0;
      num4 = 0.0;
    }
    else
    {
      bool flag2 = true;
      if (num11 > num5)
      {
        num8 = 2;
        if (num5 / num11 < 5E-16)
        {
          flag2 = false;
          ssmax = num11;
          if (num7 > 1.0)
          {
            double num9 = num11 / num7;
            ssmin = num5 / num9;
          }
          else
          {
            double num9 = num5 / num11;
            ssmin = num9 * num7;
          }
          num1 = 1.0;
          num3 = num6 / b3;
          num4 = 1.0;
          num2 = b2 / b3;
        }
      }
      if (flag2)
      {
        double a = num5 - num7;
        double num9 = a != num5 ? a / num5 : 1.0;
        double num10 = b3 / b2;
        double num12 = 2.0 - num9;
        double num13 = num10 * num10;
        double num14 = System.Math.Sqrt(num12 * num12 + num13);
        double num15 = num9 != 0.0 ? System.Math.Sqrt(num9 * num9 + num13) : System.Math.Abs(num10);
        double num16 = 0.5 * (num14 + num15);
        ssmin = num7 / num16;
        ssmax = num5 * num16;
        double num17 = num13 != 0.0 ? (num10 / (num14 + num12) + num10 / (num15 + num9)) * (1.0 + num16) : (num9 != 0.0 ? b3 / bdsvd.extsignbdsqr(a, b2) + num10 / num12 : bdsvd.extsignbdsqr(2.0, b2) * bdsvd.extsignbdsqr(1.0, b3));
        double num18 = System.Math.Sqrt(num17 * num17 + 4.0);
        num2 = 2.0 / num18;
        num4 = num17 / num18;
        num1 = (num2 + num4 * num10) / num16;
        num3 = num6 / b2 * num4 / num16;
      }
    }
    if (flag1)
    {
      csl = num4;
      snl = num2;
      csr = num3;
      snr = num1;
    }
    else
    {
      csl = num1;
      snl = num3;
      csr = num2;
      snr = num4;
    }
    if (num8 == 1)
      b1 = bdsvd.extsignbdsqr(1.0, csr) * bdsvd.extsignbdsqr(1.0, csl) * bdsvd.extsignbdsqr(1.0, f);
    if (num8 == 2)
      b1 = bdsvd.extsignbdsqr(1.0, snr) * bdsvd.extsignbdsqr(1.0, csl) * bdsvd.extsignbdsqr(1.0, g);
    if (num8 == 3)
      b1 = bdsvd.extsignbdsqr(1.0, snr) * bdsvd.extsignbdsqr(1.0, snl) * bdsvd.extsignbdsqr(1.0, h);
    ssmax = bdsvd.extsignbdsqr(ssmax, b1);
    ssmin = bdsvd.extsignbdsqr(ssmin, b1 * bdsvd.extsignbdsqr(1.0, f) * bdsvd.extsignbdsqr(1.0, h));
  }

19 Source : leastsquares.cs
with MIT License
from 1CM69

public static bool buildchebyshevleastsquaresconstrained(ref double[] x, ref double[] y, ref double[] w, double a, double b, int n, ref double[] xc, ref double[] yc, ref int[] dc, int nc, int m, ref double[] ctbl)
  {
    double[,] numArray1 = new double[0, 0];
    double[] numArray2 = new double[0];
    double[,] numArray3 = new double[0, 0];
    double[,] numArray4 = new double[0, 0];
    double[,] u = new double[0, 0];
    double[,] vt = new double[0, 0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] w1 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double[] numArray9 = new double[0];
    double[] numArray10 = new double[0];
    double[] numArray11 = new double[0];
    double[,] numArray12 = new double[0, 0];
    bool flag = true;
    double[,] a1 = new double[System.Math.Max(n, m + 1) + 1, m + 1 + 1];
    double[] numArray13 = new double[System.Math.Max(n, m + 1) + 1];
    for (int index1 = 1; index1 <= n; ++index1)
    {
      for (int index2 = 1; index2 <= m + 1; ++index2)
      {
        double num = 2.0 * (x[index1 - 1] - a) / (b - a) - 1.0;
        if (index2 == 1)
          a1[index1, index2] = 1.0;
        if (index2 == 2)
          a1[index1, index2] = num;
        if (index2 > 2)
          a1[index1, index2] = 2.0 * num * a1[index1, index2 - 1] - a1[index1, index2 - 2];
      }
    }
    for (int index1 = 1; index1 <= n; ++index1)
    {
      for (int index2 = 1; index2 <= m + 1; ++index2)
        a1[index1, index2] = w[index1 - 1] * a1[index1, index2];
    }
    for (int index1 = n + 1; index1 <= m + 1; ++index1)
    {
      for (int index2 = 1; index2 <= m + 1; ++index2)
        a1[index1, index2] = 0.0;
    }
    for (int index = 0; index <= n - 1; ++index)
      numArray13[index + 1] = w[index] * y[index];
    for (int index = n + 1; index <= m + 1; ++index)
      numArray13[index] = 0.0;
    n = System.Math.Max(n, m + 1);
    double[,] b1 = new double[m + 1 + 1, m + 1 + 1];
    double[] numArray14 = new double[m + 1 + 1];
    int num1;
    double[] work;
    if (nc == 0)
    {
      for (int index1 = 1; index1 <= m + 1; ++index1)
      {
        for (int index2 = 1; index2 <= m + 1; ++index2)
          b1[index1, index2] = 0.0;
        numArray14[index1] = 0.0;
      }
      for (int index = 1; index <= m + 1; ++index)
        b1[index, index] = 1.0;
      num1 = m + 1;
    }
    else
    {
      double[,] a2 = new double[nc + 1, m + 1 + 1];
      double[] numArray15 = new double[nc + 1];
      double[] numArray16 = new double[m + 1];
      double[] numArray17 = new double[m + 1];
      double[] numArray18 = new double[m + 1];
      for (int index1 = 0; index1 <= nc - 1; ++index1)
      {
        double num2 = 2.0 * (xc[index1] - a) / (b - a) - 1.0;
        for (int index2 = 0; index2 <= m; ++index2)
        {
          if (index2 == 0)
          {
            numArray16[index2] = 1.0;
            numArray17[index2] = 1.0;
            numArray18[index2] = 0.0;
          }
          if (index2 == 1)
          {
            numArray16[index2] = num2;
            numArray17[index2] = 2.0 * num2;
            numArray18[index2] = 1.0;
          }
          if (index2 > 1)
          {
            numArray16[index2] = 2.0 * num2 * numArray16[index2 - 1] - numArray16[index2 - 2];
            numArray17[index2] = 2.0 * num2 * numArray17[index2 - 1] - numArray17[index2 - 2];
            numArray18[index2] = (double) index2 * numArray17[index2 - 1];
          }
          if (dc[index1] == 0)
            a2[index1 + 1, index2 + 1] = numArray16[index2];
          if (dc[index1] == 1)
            a2[index1 + 1, index2 + 1] = numArray18[index2];
        }
        numArray15[index1 + 1] = yc[index1];
      }
      if (!svd.svddecomposition(a2, nc, m + 1, 2, 2, 2, ref w1, ref u, ref vt) || w1[1] == 0.0 | w1[nc] <= 5E-15 * System.Math.Sqrt((double) nc) * w1[1])
        return false;
      b1 = new double[m + 1 + 1, m + 1 - nc + 1];
      numArray14 = new double[m + 1 + 1];
      for (int index1 = 1; index1 <= m + 1 - nc; ++index1)
      {
        for (int index2 = 1; index2 <= m + 1; ++index2)
          b1[index2, index1] = vt[nc + index1, index2];
      }
      double[] numArray19 = new double[nc + 1];
      for (int index1 = 1; index1 <= nc; ++index1)
      {
        double num2 = 0.0;
        for (int index2 = 1; index2 <= nc; ++index2)
          num2 += u[index2, index1] * numArray15[index2];
        numArray19[index1] = num2 / w1[index1];
      }
      for (int index = 1; index <= m + 1; ++index)
        numArray14[index] = 0.0;
      for (int index1 = 1; index1 <= nc; ++index1)
      {
        double num2 = numArray19[index1];
        for (int index2 = 1; index2 <= m + 1; ++index2)
          numArray14[index2] = numArray14[index2] + num2 * vt[index1, index2];
      }
      for (int index1 = 1; index1 <= n; ++index1)
      {
        double num2 = 0.0;
        for (int index2 = 1; index2 <= m + 1; ++index2)
          num2 += a1[index1, index2] * numArray14[index2];
        numArray13[index1] = numArray13[index1] - num2;
      }
      num1 = m + 1 - nc;
      double[,] numArray20 = new double[n + 1, num1 + 1];
      work = new double[n + 1];
      blas.matrixmatrixmultiply(ref a1, 1, n, 1, m + 1, false, ref b1, 1, m + 1, 1, num1, false, 1.0, ref numArray20, 1, n, 1, num1, 0.0, ref work);
      blas.copymatrix(ref numArray20, 1, n, 1, num1, ref a1, 1, n, 1, num1);
    }
    if (!svd.svddecomposition(a1, n, num1, 1, 1, 2, ref w1, ref u, ref vt))
      return false;
    work = new double[num1 + 1];
    double[] numArray21 = new double[num1 + 1];
    for (int index = 1; index <= num1; ++index)
      work[index] = 0.0;
    for (int index1 = 1; index1 <= n; ++index1)
    {
      double num2 = numArray13[index1];
      for (int index2 = 1; index2 <= num1; ++index2)
        work[index2] = work[index2] + num2 * u[index1, index2];
    }
    for (int index = 1; index <= num1; ++index)
      work[index] = !(w1[index] != 0.0 & w1[index] > 5E-15 * System.Math.Sqrt((double) nc) * w1[1]) ? 0.0 : work[index] / w1[index];
    for (int index = 1; index <= num1; ++index)
      numArray21[index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = work[index1];
      for (int index2 = 1; index2 <= num1; ++index2)
        numArray21[index2] = numArray21[index2] + num2 * vt[index1, index2];
    }
    ctbl = new double[m + 2 + 1];
    for (int index1 = 1; index1 <= m + 1; ++index1)
    {
      double num2 = 0.0;
      for (int index2 = 1; index2 <= num1; ++index2)
        num2 += b1[index1, index2] * numArray21[index2];
      ctbl[index1 - 1] = num2 + numArray14[index1];
    }
    ctbl[m + 1] = a;
    ctbl[m + 2] = b;
    return flag;
  }

19 Source : reflections.cs
with MIT License
from 1CM69

public static void generatereflection(ref double[] x, int n, ref double tau)
  {
    if (n <= 1)
    {
      tau = 0.0;
    }
    else
    {
      double num1 = x[1];
      double val2 = 0.0;
      for (int index = 2; index <= n; ++index)
        val2 = System.Math.Max(System.Math.Abs(x[index]), val2);
      double d = 0.0;
      if (val2 != 0.0)
      {
        for (int index = 2; index <= n; ++index)
          d += AP.Math.Sqr(x[index] / val2);
        d = System.Math.Sqrt(d) * val2;
      }
      if (d == 0.0)
      {
        tau = 0.0;
      }
      else
      {
        double num2 = System.Math.Max(System.Math.Abs(num1), System.Math.Abs(d));
        double num3 = -(num2 * System.Math.Sqrt(AP.Math.Sqr(num1 / num2) + AP.Math.Sqr(d / num2)));
        if (num1 < 0.0)
          num3 = -num3;
        tau = (num3 - num1) / num3;
        double num4 = 1.0 / (num1 - num3);
        for (int index = 2; index <= n; ++index)
          x[index] = num4 * x[index];
        x[1] = num3;
      }
    }
  }

19 Source : reflections.cs
with MIT License
from 1CM69

public static void generatereflection(ref double[] x, int n, ref double tau)
  {
    if (n <= 1)
    {
      tau = 0.0;
    }
    else
    {
      double num1 = x[1];
      double val2 = 0.0;
      for (int index = 2; index <= n; ++index)
        val2 = System.Math.Max(System.Math.Abs(x[index]), val2);
      double d = 0.0;
      if (val2 != 0.0)
      {
        for (int index = 2; index <= n; ++index)
          d += AP.Math.Sqr(x[index] / val2);
        d = System.Math.Sqrt(d) * val2;
      }
      if (d == 0.0)
      {
        tau = 0.0;
      }
      else
      {
        double num2 = System.Math.Max(System.Math.Abs(num1), System.Math.Abs(d));
        double num3 = -(num2 * System.Math.Sqrt(AP.Math.Sqr(num1 / num2) + AP.Math.Sqr(d / num2)));
        if (num1 < 0.0)
          num3 = -num3;
        tau = (num3 - num1) / num3;
        double num4 = 1.0 / (num1 - num3);
        for (int index = 2; index <= n; ++index)
          x[index] = num4 * x[index];
        x[1] = num3;
      }
    }
  }

19 Source : rotations.cs
with MIT License
from 1CM69

public static void generaterotation(double f, double g, ref double cs, ref double sn, ref double r)
  {
    if (g == 0.0)
    {
      cs = 1.0;
      sn = 0.0;
      r = f;
    }
    else if (f == 0.0)
    {
      cs = 0.0;
      sn = 1.0;
      r = g;
    }
    else
    {
      double X1 = f;
      double X2 = g;
      r = System.Math.Sqrt(AP.Math.Sqr(X1) + AP.Math.Sqr(X2));
      cs = X1 / r;
      sn = X2 / r;
      if (!(System.Math.Abs(f) > System.Math.Abs(g) & cs < 0.0))
        return;
      cs = -cs;
      sn = -sn;
      r = -r;
    }
  }

19 Source : Math.cs
with MIT License
from 1CM69

public static double AbsComplex(Complex z)
    {
      double num1 = System.Math.Abs(z.x);
      double num2 = System.Math.Abs(z.y);
      double num3 = num1 > num2 ? num1 : num2;
      double num4 = num1 < num2 ? num1 : num2;
      if (num4 == 0.0)
        return num3;
      double num5 = num4 / num3;
      return num3 * System.Math.Sqrt(1.0 + num5 * num5);
    }

19 Source : blas.cs
with MIT License
from 1CM69

public static double vectornorm2(ref double[] x, int i1, int i2)
  {
    int num1 = i2 - i1 + 1;
    if (num1 < 1)
      return 0.0;
    if (num1 == 1)
      return System.Math.Abs(x[i1]);
    double num2 = 0.0;
    double d = 1.0;
    for (int index = i1; index <= i2; ++index)
    {
      if (x[index] != 0.0)
      {
        double num3 = System.Math.Abs(x[index]);
        if (num2 < num3)
        {
          d = 1.0 + d * AP.Math.Sqr(num2 / num3);
          num2 = num3;
        }
        else
          d += AP.Math.Sqr(num3 / num2);
      }
    }
    return num2 * System.Math.Sqrt(d);
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static double pythag2(double x, double y)
  {
    double val1 = System.Math.Abs(x);
    double val2 = System.Math.Abs(y);
    double num1 = System.Math.Max(val1, val2);
    double num2 = System.Math.Min(val1, val2);
    return num2 != 0.0 ? num1 * System.Math.Sqrt(1.0 + AP.Math.Sqr(num2 / num1)) : num1;
  }

19 Source : leastsquares.cs
with MIT License
from 1CM69

public static void buildgeneralleastsquares(ref double[] y, ref double[] w, ref double[,] fmatrix, int n, int m, ref double[] c)
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[] numArray4 = new double[0];
    double[] tau = new double[0];
    double[,] numArray5 = new double[0, 0];
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] d = new double[0];
    double[] e = new double[0];
    bool isupper = false;
    int val1 = n;
    int num1 = m;
    c = new double[num1 - 1 + 1];
    double[,] numArray6 = new double[num1 + 1, System.Math.Max(val1, num1) + 1];
    double[] numArray7 = new double[System.Math.Max(val1, num1) + 1];
    for (int index = 1; index <= val1; ++index)
      numArray7[index] = w[index - 1] * y[index - 1];
    for (int index = val1 + 1; index <= num1; ++index)
      numArray7[index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      int num2 = -1;
      for (int index2 = 1; index2 <= val1; ++index2)
        numArray6[index1, index2] = fmatrix[index2 + num2, index1 - 1];
    }
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      for (int index2 = val1 + 1; index2 <= num1; ++index2)
        numArray6[index1, index2] = 0.0;
    }
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      for (int index2 = 1; index2 <= val1; ++index2)
        numArray6[index1, index2] = numArray6[index1, index2] * w[index2 - 1];
    }
    int n1 = System.Math.Max(val1, num1);
    lq.lqdecomposition(ref numArray6, num1, n1, ref tau);
    lq.unpackqfromlq(ref numArray6, num1, n1, ref tau, num1, ref numArray2);
    double[,] numArray8 = new double[2, num1 + 1];
    for (int index = 1; index <= num1; ++index)
      numArray8[1, index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = 0.0;
      for (int index2 = 1; index2 <= n1; ++index2)
        num2 += numArray7[index2] * numArray2[index1, index2];
      numArray8[1, index1] = num2;
    }
    for (int index1 = 1; index1 <= num1 - 1; ++index1)
    {
      for (int index2 = index1 + 1; index2 <= num1; ++index2)
        numArray6[index1, index2] = numArray6[index2, index1];
    }
    for (int index1 = 2; index1 <= num1; ++index1)
    {
      for (int index2 = 1; index2 <= index1 - 1; ++index2)
        numArray6[index1, index2] = 0.0;
    }
    bidiagonal.tobidiagonal(ref numArray6, num1, num1, ref tauq, ref taup);
    bidiagonal.multiplybyqfrombidiagonal(ref numArray6, num1, num1, ref tauq, ref numArray8, 1, num1, true, false);
    bidiagonal.unpackptfrombidiagonal(ref numArray6, num1, num1, ref taup, num1, ref numArray3);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref numArray6, num1, num1, ref isupper, ref d, ref e);
    if (!bdsvd.bidiagonalsvddecomposition(ref d, e, num1, isupper, false, ref numArray8, 1, ref numArray2, 0, ref numArray3, num1))
    {
      for (int index = 0; index <= num1 - 1; ++index)
        c[index] = 0.0;
    }
    else
    {
      if (d[1] != 0.0)
      {
        for (int index = 1; index <= num1; ++index)
          numArray8[1, index] = d[index] <= 5E-15 * System.Math.Sqrt((double) num1) * d[1] ? 0.0 : numArray8[1, index] / d[index];
      }
      for (int index = 1; index <= num1; ++index)
        numArray7[index] = 0.0;
      for (int index1 = 1; index1 <= num1; ++index1)
      {
        double num2 = numArray8[1, index1];
        for (int index2 = 1; index2 <= num1; ++index2)
          numArray7[index2] = numArray7[index2] + num2 * numArray3[index1, index2];
      }
      for (int index = 1; index <= num1; ++index)
        c[index - 1] = numArray7[index];
    }
  }

19 Source : leastsquares.cs
with MIT License
from 1CM69

public static void buildsplineleastsquares(ref double[] x, ref double[] y, ref double[] w, double a, double b, int n, int m, ref double[] ctbl)
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[] numArray4 = new double[0];
    double[] tau = new double[0];
    double[,] numArray5 = new double[0, 0];
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] d = new double[0];
    double[] e = new double[0];
    bool isupper = false;
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    int val1 = n;
    int num1 = m;
    double[] x1 = new double[num1 - 1 + 1];
    double[] y1 = new double[num1 - 1 + 1];
    double[,] numArray8 = new double[num1 + 1, System.Math.Max(val1, num1) + 1];
    double[] numArray9 = new double[System.Math.Max(val1, num1) + 1];
    for (int index = 0; index <= num1 - 1; ++index)
      x1[index] = a + (b - a) * (double) index / (double) (num1 - 1);
    for (int index1 = 0; index1 <= num1 - 1; ++index1)
    {
      for (int index2 = 0; index2 <= num1 - 1; ++index2)
        y1[index2] = 0.0;
      y1[index1] = 1.0;
      spline3.buildcubicspline(x1, y1, num1, 0, 0.0, 0, 0.0, ref ctbl);
      for (int index2 = 0; index2 <= val1 - 1; ++index2)
        numArray8[index1 + 1, index2 + 1] = w[index2] * spline3.splineinterpolation(ref ctbl, x[index2]);
    }
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      for (int index2 = val1 + 1; index2 <= num1; ++index2)
        numArray8[index1, index2] = 0.0;
    }
    for (int index = 0; index <= val1 - 1; ++index)
      numArray9[index + 1] = w[index] * y[index];
    for (int index = val1 + 1; index <= num1; ++index)
      numArray9[index] = 0.0;
    int n1 = System.Math.Max(val1, num1);
    lq.lqdecomposition(ref numArray8, num1, n1, ref tau);
    lq.unpackqfromlq(ref numArray8, num1, n1, ref tau, num1, ref numArray2);
    double[,] numArray10 = new double[2, num1 + 1];
    for (int index = 1; index <= num1; ++index)
      numArray10[1, index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = 0.0;
      for (int index2 = 1; index2 <= n1; ++index2)
        num2 += numArray9[index2] * numArray2[index1, index2];
      numArray10[1, index1] = num2;
    }
    for (int index1 = 1; index1 <= num1 - 1; ++index1)
    {
      for (int index2 = index1 + 1; index2 <= num1; ++index2)
        numArray8[index1, index2] = numArray8[index2, index1];
    }
    for (int index1 = 2; index1 <= num1; ++index1)
    {
      for (int index2 = 1; index2 <= index1 - 1; ++index2)
        numArray8[index1, index2] = 0.0;
    }
    bidiagonal.tobidiagonal(ref numArray8, num1, num1, ref tauq, ref taup);
    bidiagonal.multiplybyqfrombidiagonal(ref numArray8, num1, num1, ref tauq, ref numArray10, 1, num1, true, false);
    bidiagonal.unpackptfrombidiagonal(ref numArray8, num1, num1, ref taup, num1, ref numArray3);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref numArray8, num1, num1, ref isupper, ref d, ref e);
    if (!bdsvd.bidiagonalsvddecomposition(ref d, e, num1, isupper, false, ref numArray10, 1, ref numArray2, 0, ref numArray3, num1))
    {
      for (int index1 = 1; index1 <= num1; ++index1)
      {
        d[index1] = 0.0;
        numArray10[1, index1] = 0.0;
        for (int index2 = 1; index2 <= num1; ++index2)
          numArray3[index1, index2] = index1 != index2 ? 0.0 : 1.0;
      }
      numArray10[1, 1] = 1.0;
    }
    for (int index = 1; index <= num1; ++index)
      numArray10[1, index] = d[index] <= 5E-15 * System.Math.Sqrt((double) num1) * d[1] ? 0.0 : numArray10[1, index] / d[index];
    for (int index = 1; index <= num1; ++index)
      numArray9[index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = numArray10[1, index1];
      for (int index2 = 1; index2 <= num1; ++index2)
        numArray9[index2] = numArray9[index2] + num2 * numArray3[index1, index2];
    }
    for (int index = 0; index <= num1 - 1; ++index)
      y1[index] = numArray9[index + 1];
    spline3.buildcubicspline(x1, y1, num1, 0, 0.0, 0, 0.0, ref ctbl);
  }

19 Source : leastsquares.cs
with MIT License
from 1CM69

public static void buildchebyshevleastsquares(ref double[] x, ref double[] y, ref double[] w, double a, double b, int n, int m, ref double[] ctbl)
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[] numArray4 = new double[0];
    double[] tau = new double[0];
    double[,] numArray5 = new double[0, 0];
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] d = new double[0];
    double[] e = new double[0];
    bool isupper = false;
    int val1 = n;
    int index1 = m + 1;
    double[,] numArray6 = new double[index1 + 1, System.Math.Max(val1, index1) + 1];
    double[] numArray7 = new double[System.Math.Max(val1, index1) + 1];
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      for (int index3 = 1; index3 <= val1; ++index3)
      {
        double num = 2.0 * (x[index3 - 1] - a) / (b - a) - 1.0;
        if (index2 == 1)
          numArray6[index2, index3] = 1.0;
        if (index2 == 2)
          numArray6[index2, index3] = num;
        if (index2 > 2)
          numArray6[index2, index3] = 2.0 * num * numArray6[index2 - 1, index3] - numArray6[index2 - 2, index3];
      }
    }
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      for (int index3 = 1; index3 <= val1; ++index3)
        numArray6[index2, index3] = w[index3 - 1] * numArray6[index2, index3];
    }
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      for (int index3 = val1 + 1; index3 <= index1; ++index3)
        numArray6[index2, index3] = 0.0;
    }
    for (int index2 = 0; index2 <= val1 - 1; ++index2)
      numArray7[index2 + 1] = w[index2] * y[index2];
    for (int index2 = val1 + 1; index2 <= index1; ++index2)
      numArray7[index2] = 0.0;
    int n1 = System.Math.Max(val1, index1);
    lq.lqdecomposition(ref numArray6, index1, n1, ref tau);
    lq.unpackqfromlq(ref numArray6, index1, n1, ref tau, index1, ref numArray2);
    double[,] numArray8 = new double[2, index1 + 1];
    for (int index2 = 1; index2 <= index1; ++index2)
      numArray8[1, index2] = 0.0;
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      double num = 0.0;
      for (int index3 = 1; index3 <= n1; ++index3)
        num += numArray7[index3] * numArray2[index2, index3];
      numArray8[1, index2] = num;
    }
    for (int index2 = 1; index2 <= index1 - 1; ++index2)
    {
      for (int index3 = index2 + 1; index3 <= index1; ++index3)
        numArray6[index2, index3] = numArray6[index3, index2];
    }
    for (int index2 = 2; index2 <= index1; ++index2)
    {
      for (int index3 = 1; index3 <= index2 - 1; ++index3)
        numArray6[index2, index3] = 0.0;
    }
    bidiagonal.tobidiagonal(ref numArray6, index1, index1, ref tauq, ref taup);
    bidiagonal.multiplybyqfrombidiagonal(ref numArray6, index1, index1, ref tauq, ref numArray8, 1, index1, true, false);
    bidiagonal.unpackptfrombidiagonal(ref numArray6, index1, index1, ref taup, index1, ref numArray3);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref numArray6, index1, index1, ref isupper, ref d, ref e);
    if (!bdsvd.bidiagonalsvddecomposition(ref d, e, index1, isupper, false, ref numArray8, 1, ref numArray2, 0, ref numArray3, index1))
    {
      for (int index2 = 1; index2 <= index1; ++index2)
      {
        d[index2] = 0.0;
        numArray8[1, index2] = 0.0;
        for (int index3 = 1; index3 <= index1; ++index3)
          numArray3[index2, index3] = index2 != index3 ? 0.0 : 1.0;
      }
      numArray8[1, 1] = 1.0;
    }
    for (int index2 = 1; index2 <= index1; ++index2)
      numArray8[1, index2] = d[index2] <= 5E-15 * System.Math.Sqrt((double) index1) * d[1] ? 0.0 : numArray8[1, index2] / d[index2];
    for (int index2 = 1; index2 <= index1; ++index2)
      numArray7[index2] = 0.0;
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      double num = numArray8[1, index2];
      for (int index3 = 1; index3 <= index1; ++index3)
        numArray7[index3] = numArray7[index3] + num * numArray3[index2, index3];
    }
    ctbl = new double[index1 + 1 + 1];
    for (int index2 = 1; index2 <= index1; ++index2)
      ctbl[index2 - 1] = numArray7[index2];
    ctbl[index1] = a;
    ctbl[index1 + 1] = b;
  }

19 Source : GCodeParser.cs
with MIT License
from 3RD-Dimension

static void Parse(string line, int lineNumber)
		{
			MatchCollection matches = GCodeSplitter.Matches(line);

			List<Word> Words = new List<Word>(matches.Count);

			foreach (Match match in matches)
			{
				Words.Add(new Word() { Command = match.Groups[1].Value[0], Parameter = double.Parse(match.Groups[2].Value, Constants.DecimalParseFormat) });
			}

			for (int i = 0; i < Words.Count; i++)
			{
				if (Words[i].Command == 'N')
				{
					Words.RemoveAt(i--);
					continue;
				}

				if (IgnoreAxes.Contains(Words[i].Command) && Properties.Settings.Default.IgnoreAdditionalAxes)
				{
					Words.RemoveAt(i--);
					continue;
				}

				if (!ValidWords.Contains(Words[i].Command))
				{
					Warnings.Add($"ignoring unknown word (letter): \"{Words[i]}\". (line {lineNumber})");
					Words.RemoveAt(i--);
					continue;
				}

				if (Words[i].Command != 'F')
					continue;

				State.Feed = Words[i].Parameter;
				if (State.Unit == ParseUnit.Imperial)
					State.Feed *= 25.4;
				Words.RemoveAt(i--);
				continue;
			}

			for (int i = 0; i < Words.Count; i++)
			{
				if (Words[i].Command == 'M')
				{
					int param = (int)Words[i].Parameter;

					if (param != Words[i].Parameter || param < 0)
						throw new ParseException("M code can only have positive integer parameters", lineNumber);

					Commands.Add(new MCode() { Code = param, LineNumber = lineNumber });

					Words.RemoveAt(i);
					i--;
					continue;
				}

				if (Words[i].Command == 'S')
				{
					double param = Words[i].Parameter;

					if (param < 0)
						Warnings.Add($"spindle speed must be positive. (line {lineNumber})");

					Commands.Add(new Spindle() { Speed = Math.Abs(param), LineNumber = lineNumber });

					Words.RemoveAt(i);
					i--;
					continue;
				}

				if (Words[i].Command == 'G' && !MotionCommands.Contains(Words[i].Parameter))
				{
					#region UnitPlaneDistanceMode

					double param = Words[i].Parameter;

					if (param == 90)
					{
						State.DistanceMode = ParseDistanceMode.Absolute;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 91)
					{
						State.DistanceMode = ParseDistanceMode.Incremental;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 90.1)
					{
						State.ArcDistanceMode = ParseDistanceMode.Absolute;
						Words.RemoveAt(i);
						continue;
					}
					if (param == 91.1)
					{
						State.ArcDistanceMode = ParseDistanceMode.Incremental;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 21)
					{
						State.Unit = ParseUnit.Metric;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 20)
					{
						State.Unit = ParseUnit.Imperial;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 17)
					{
						State.Plane = ArcPlane.XY;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 18)
					{
						State.Plane = ArcPlane.ZX;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 19)
					{
						State.Plane = ArcPlane.YZ;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 4)
					{
						if (Words.Count >= 2 && Words[i + 1].Command == 'P')
						{
							if (Words[i + 1].Parameter < 0)
								Warnings.Add($"dwell time must be positive. (line {lineNumber})");

							Commands.Add(new Dwell() { Seconds = Math.Abs(Words[i + 1].Parameter), LineNumber = lineNumber });
							Words.RemoveAt(i + 1);
							Words.RemoveAt(i);
							i--;
							continue;
						}
					}

					Warnings.Add($"ignoring unknown command G{param}. (line {lineNumber})");
					Words.RemoveAt(i--);
					#endregion
				}
			}

			if (Words.Count == 0)
				return;

			int MotionMode = State.LastMotionMode;

			if (Words.First().Command == 'G')
			{
				MotionMode = (int)Words.First().Parameter;
				State.LastMotionMode = MotionMode;
				Words.RemoveAt(0);
			}

			if (MotionMode < 0)
				throw new ParseException("no motion mode active", lineNumber);

			double UnitMultiplier = (State.Unit == ParseUnit.Metric) ? 1 : 25.4;

			Vector3 EndPos = State.Position;

			if (State.DistanceMode == ParseDistanceMode.Incremental && State.PositionValid.Any(isValid => !isValid))
			{
				throw new ParseException("incremental motion is only allowed after an absolute position has been established (eg. with \"G90 G0 X0 Y0 Z5\")", lineNumber);
			}

			if ((MotionMode == 2 || MotionMode == 3) && State.PositionValid.Any(isValid => !isValid))
			{
				throw new ParseException("arcs (G2/G3) are only allowed after an absolute position has been established (eg. with \"G90 G0 X0 Y0 Z5\")", lineNumber);
			}

			#region FindEndPos
			{
				int Incremental = (State.DistanceMode == ParseDistanceMode.Incremental) ? 1 : 0;

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'X')
						continue;
					EndPos.X = Words[i].Parameter * UnitMultiplier + Incremental * EndPos.X;
					Words.RemoveAt(i);
					State.PositionValid[0] = true;
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'Y')
						continue;
					EndPos.Y = Words[i].Parameter * UnitMultiplier + Incremental * EndPos.Y;
					Words.RemoveAt(i);
					State.PositionValid[1] = true;
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'Z')
						continue;
					EndPos.Z = Words[i].Parameter * UnitMultiplier + Incremental * EndPos.Z;
					Words.RemoveAt(i);
					State.PositionValid[2] = true;
					break;
				}
			}
			#endregion

			if (MotionMode != 0 && State.Feed <= 0)
			{
				throw new ParseException("feed rate undefined", lineNumber);
			}

			if (MotionMode == 1 && State.PositionValid.Any(isValid => !isValid))
			{
				Warnings.Add($"a feed move is used before an absolute position is established, height maps will not be applied to this motion. (line {lineNumber})");
			}

			if (MotionMode <= 1)
			{
				if (Words.Count > 0)
					Warnings.Add($"motion command must be last in line (ignoring unused words {string.Join(" ", Words)} in block). (line {lineNumber})");

				Line motion = new Line();
				motion.Start = State.Position;
				motion.End = EndPos;
				motion.Feed = State.Feed;
				motion.Rapid = MotionMode == 0;
				motion.LineNumber = lineNumber;
				State.PositionValid.CopyTo(motion.PositionValid, 0);

				Commands.Add(motion);
				State.Position = EndPos;
				return;
			}

			double U, V;

			bool IJKused = false;

			switch (State.Plane)
			{
				default:
					U = State.Position.X;
					V = State.Position.Y;
					break;
				case ArcPlane.YZ:
					U = State.Position.Y;
					V = State.Position.Z;
					break;
				case ArcPlane.ZX:
					U = State.Position.Z;
					V = State.Position.X;
					break;
			}

			#region FindIJK
			{
				int ArcIncremental = (State.ArcDistanceMode == ParseDistanceMode.Incremental) ? 1 : 0;

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'I')
						continue;

					switch (State.Plane)
					{
						case ArcPlane.XY:
							U = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.X;
							break;
						case ArcPlane.YZ:
							throw new ParseException("current plane is YZ, I word is invalid", lineNumber);
						case ArcPlane.ZX:
							V = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.X;
							break;
					}

					IJKused = true;
					Words.RemoveAt(i);
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'J')
						continue;

					switch (State.Plane)
					{
						case ArcPlane.XY:
							V = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Y;
							break;
						case ArcPlane.YZ:
							U = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Y;
							break;
						case ArcPlane.ZX:
							throw new ParseException("current plane is ZX, J word is invalid", lineNumber);
					}

					IJKused = true;
					Words.RemoveAt(i);
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'K')
						continue;

					switch (State.Plane)
					{
						case ArcPlane.XY:
							throw new ParseException("current plane is XY, K word is invalid", lineNumber);
						case ArcPlane.YZ:
							V = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Z;
							break;
						case ArcPlane.ZX:
							U = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Z;
							break;
					}

					IJKused = true;
					Words.RemoveAt(i);
					break;
				}
			}
			#endregion

			#region ResolveRadius
			for (int i = 0; i < Words.Count; i++)
			{
				if (Words[i].Command != 'R')
					continue;

				if (IJKused)
					throw new ParseException("both IJK and R notation used", lineNumber);

				if (State.Position == EndPos)
					throw new ParseException("arcs in R-notation must have non-coincident start and end points", lineNumber);

				double Radius = Words[i].Parameter * UnitMultiplier;

				if (Radius == 0)
					throw new ParseException("radius can't be zero", lineNumber);

				double A, B;

				switch (State.Plane)
				{
					default:
						A = EndPos.X;
						B = EndPos.Y;
						break;
					case ArcPlane.YZ:
						A = EndPos.Y;
						B = EndPos.Z;
						break;
					case ArcPlane.ZX:
						A = EndPos.Z;
						B = EndPos.X;
						break;
				}

				A -= U;     //(AB) = vector from start to end of arc along the axes of the current plane
				B -= V;

				//see grbl/gcode.c
				double h_x2_div_d = 4.0 * (Radius * Radius) - (A * A + B * B);
				if (h_x2_div_d < 0)
				{
					throw new ParseException("arc radius too small to reach both ends", lineNumber);
				}

				h_x2_div_d = -Math.Sqrt(h_x2_div_d) / Math.Sqrt(A * A + B * B);

				if (MotionMode == 3 ^ Radius < 0)
				{
					h_x2_div_d = -h_x2_div_d;
				}

				U += 0.5 * (A - (B * h_x2_div_d));
				V += 0.5 * (B + (A * h_x2_div_d));

				Words.RemoveAt(i);
				break;
			}
			#endregion

			if (Words.Count > 0)
				Warnings.Add($"motion command must be last in line (ignoring unused words {string.Join(" ", Words)} in block). (line {lineNumber})");

			Arc arc = new Arc();
			arc.Start = State.Position;
			arc.End = EndPos;
			arc.Feed = State.Feed;
			arc.Direction = (MotionMode == 2) ? ArcDirection.CW : ArcDirection.CCW;
			arc.U = U;
			arc.V = V;
			arc.LineNumber = lineNumber;
			arc.Plane = State.Plane;

			Commands.Add(arc);
			State.Position = EndPos;
			return;
		}

19 Source : GameTest.cs
with MIT License
from 734843327

public Vector2d VectorDirectionNew(Vector2d start, Vector2d end){
        Vector2d result;
        double deltaX;
        double deltaY;
        deltaX = end.y - start.y;
        deltaY = end.x - start.x;
        result.x = deltaX / Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));
        result.y = deltaY / Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));
        return result;
      
    }

19 Source : gps2bd.cs
with MIT License
from 734843327

private static double transformLon(double lat, double lon)
        {
            double ret = 300.0 + lat + 2.0 * lon + 0.1 * lat * lat + 0.1 * lat * lon + 0.1 * Math.Sqrt(Math.Abs(lat));
            ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;
            ret += (20.0 * Math.Sin(lat * pi) + 40.0 * Math.Sin(lat / 3.0 * pi)) * 2.0 / 3.0;
            ret += (150.0 * Math.Sin(lat / 12.0 * pi) + 300.0 * Math.Sin(lat / 30.0 * pi)) * 2.0 / 3.0;
            return ret;
        }

19 Source : Mathd.cs
with MIT License
from 734843327

public static double Sqrt(double d) {
            return Math.Sqrt(d);
        }

19 Source : GameTest.cs
with MIT License
from 734843327

public Vector2d changeCoordinateSystem(Vector2d point, float angle)
    {
        Vector2d result;
        double deltaX;
        double deltaY;
        angle = angle * 3.14159265f / 180;//角度化弧度
        deltaX = point.y * Mathd.Cos(angle) + point.x * Mathd.Sin(angle);
        deltaY = point.x * Mathd.Cos(angle) - point.y * Mathd.Sin(angle);
        //Debug.Log("delta:" + deltaX.ToString() + "   " + deltaY.ToString());
        result.y = deltaX / Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));
        result.x = deltaY / Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));
        return result;
    }

19 Source : gps2bd.cs
with MIT License
from 734843327

public static double[] gcj2bd(double lat, double lon)
        {
            double x = lon, y = lat;
            double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi);
            double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi);
            double bd_lon = z * Math.Cos(theta) + 0.0065;
            double bd_lat = z * Math.Sin(theta) + 0.006;
            return new double[] { bd_lat, bd_lon };
        }

19 Source : gps2bd.cs
with MIT License
from 734843327

public static double[] bd2gcj(double lat, double lon)
        {
            double x = lon - 0.0065, y = lat - 0.006;
            double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi);
            double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * x_pi);
            double gg_lon = z * Math.Cos(theta);
            double gg_lat = z * Math.Sin(theta);
            return new double[] { gg_lat, gg_lon };
        }

19 Source : gps2bd.cs
with MIT License
from 734843327

public static double[] wgs2gcj(double lat, double lon)
        {
            double dLat = transformLat(lon - 105.0, lat - 35.0);
            double dLon = transformLon(lon - 105.0, lat - 35.0);
            double radLat = lat / 180.0 * pi;
            double magic = Math.Sin(radLat);
            magic = 1 - ee * magic * magic;
            double sqrtMagic = Math.Sqrt(magic);
            dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
            dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);
            double mgLat = lat + dLat;
            double mgLon = lon + dLon;
            double[] loc = { mgLat, mgLon };
            return loc;
        }

19 Source : gps2bd.cs
with MIT License
from 734843327

private static double transformLat(double lat, double lon)
        {
            double ret = -100.0 + 2.0 * lat + 3.0 * lon + 0.2 * lon * lon + 0.1 * lat * lon + 0.2 * Math.Sqrt(Math.Abs(lat));
            ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;
            ret += (20.0 * Math.Sin(lon * pi) + 40.0 * Math.Sin(lon / 3.0 * pi)) * 2.0 / 3.0;
            ret += (160.0 * Math.Sin(lon / 12.0 * pi) + 320 * Math.Sin(lon * pi / 30.0)) * 2.0 / 3.0;
            return ret;
        }

19 Source : CloudSection.cs
with GNU Lesser General Public License v3.0
from 9and3

public PointCloud SectionCloud(PointCloud cloud, List<Plane> planes,  double tol = 0.001, bool project = false) {

            bool[] flags = new bool[cloud.Count];
            int[] cID = new int[cloud.Count];

          

            int count = 1;
            foreach (Plane plane in planes) {

                   double[] eq = plane.GetPlaneEquation();
                   double denom = 1 / Math.Sqrt(eq[0] * eq[0] + eq[1] * eq[1] + eq[2] * eq[2]);


                System.Threading.Tasks.Parallel.For(0, cloud.Count, i => {
                    // for (int i = 0; i < cloud_.Count; i++) {

                    if (flags[i]) return;

                    if (Math.Abs(FastPlaneToPt(denom, eq[0], eq[1], eq[2], eq[3], cloud[i].Location)) <= tol) {
                        flags[i] = true;
                        cID[i] = count;
                    }


                });

                count++;
            }

            int cc = 0;
            List<int> idList = new List<int>();
            for (int i = 0; i < cloud.Count; i++) {
                //bool f = inverse ? !flags[i] : flags[i];
                if (flags[i]) {
                    idList.Add(i);
                    cc++;
                }
            }

            int[] idArray = idList.ToArray();
            Point3d[] points = new Point3d[cc];
            Vector3d[] normals = new Vector3d[cc];
            Color[] colors = new Color[cc];

            System.Threading.Tasks.Parallel.For(0, idArray.Length, i => {


                int id = idArray[i];
                var p = cloud[(int)id];
                points[i] = p.Location;
                normals[i] = p.Normal;
                colors[i] = p.Color;

            });

            PointCloud croppedCloud = new PointCloud();
            croppedCloud.AddRange(points, normals, colors);

            //PointCloud croppedCloud = new PointCloud();
            //for (int i = 0; i < cloud.Count; i++) {
            //    //bool f = inverse ? !flags[i] : flags[i];
            //    bool f =  flags[i];
            //    if (f) {
            //        if (cloud.ContainsNormals) {
            //            croppedCloud.Add(cloud[i].Location, cloud[i].Normal, cloud[i].Color);
            //        } else {
            //            croppedCloud.Add(cloud[i].Location, cloud[i].Color);
            //        }
            //    }
            //}


            if (project) {
               // if (planes.Count == 1) {
                    croppedCloud.Transform(Rhino.Geometry.Transform.PlanarProjection(planes[0]));
                //} else {

                //    for (int i = 0; i < cloud.Count; i++) {

                //    }
                }
                return croppedCloud;

            }

19 Source : AccelCalculator.cs
with MIT License
from a1xd

public static double Magnitude(int x, int y)
        {
            if (x == 0)
            {
                return Math.Abs(y);
            }

            if (y == 0)
            {
                return Math.Abs(x);
            }

            return Math.Sqrt(x * x + y * y);
        }

19 Source : AccelCalculator.cs
with MIT License
from a1xd

public static double Magnitude(double x, double y)
        {
            if (x == 0)
            {
                return Math.Abs(y);
            }

            if (y == 0)
            {
                return Math.Abs(x);
            }

            return Math.Sqrt(x * x + y * y);
        }

19 Source : Perlin.cs
with Apache License 2.0
from A7ocin

void normalize2(ref float x, ref float y)
	{
	   float s;
	
		s = (float)Math.Sqrt(x * x + y * y);
		x = y / s;
		y = y / s;
	}

19 Source : Perlin.cs
with Apache License 2.0
from A7ocin

void normalize3(ref float x, ref float y, ref float z)
	{
		float s;
		s = (float)Math.Sqrt(x * x + y * y + z * z);
		x = y / s;
		y = y / s;
		z = z / s;
	}

19 Source : PerformanceTest.cs
with Apache License 2.0
from aadreja

void WriteStatus(string replacedle, Dictionary<string, Dictionary<int, long>> timings)
        {
            WriteLine(replacedle, ConsoleColor.Yellow);
            foreach (var item in timings)
            {
                double mean = item.Value.Values.Average();
                double variance = 0;

                Write(item.Key + "\t\t");
                foreach (var it in item.Value)
                {
                    Write(it.Value + "\t");
                    variance += Math.Pow((it.Value - mean), 2);
                }
                variance = variance / item.Value.Values.Count;

                Write(item.Value.Values.Average() + "\t");
                Write(Math.Sqrt(variance) + "\t");

                WriteLine("");
            }
        }

19 Source : P2PManager.cs
with MIT License
from absurd-joy

void ReadTimeSyncMessage(ulong remoteID, byte[] msg)
		{
			if (!m_remoteSentTimeCache.ContainsKey(remoteID))
			{
				SendTimeSyncMessage(remoteID);
				return;
			}

			int offset = 1;
			float remoteTime = UnpackFloat(msg, ref offset);
			float now = Time.realtimeSinceStartup;
			float latency = (now - m_remoteSentTimeCache[remoteID]) / 2;
			float remoteTimeOffset = now - (remoteTime + latency);

			m_remoteSyncTimeCache[remoteID].Add(remoteTimeOffset);

			if (m_remoteSyncTimeCache[remoteID].Count < TIME_SYNC_MESSAGE_COUNT)
			{
				SendTimeSyncMessage(remoteID);
			}
			else
			{
				if (PlatformManager.MyID < remoteID)
				{
					// this client started the sync, need to send one last message to
					// the remote so they can finish their sync calculation
					SendTimeSyncMessage(remoteID);
				}

				// sort the times and remember the median
				m_remoteSyncTimeCache[remoteID].Sort();
				float median = m_remoteSyncTimeCache[remoteID][TIME_SYNC_MESSAGE_COUNT/2];

				// calucate the mean and standard deviation
				double mean = 0;
				foreach (var time in m_remoteSyncTimeCache[remoteID])
				{
					mean += time;
				}
				mean /= TIME_SYNC_MESSAGE_COUNT;

				double std_dev = 0;
				foreach (var time in m_remoteSyncTimeCache[remoteID])
				{
					std_dev += (mean-time)*(mean-time);
				}
				std_dev = Math.Sqrt(std_dev)/TIME_SYNC_MESSAGE_COUNT;

				// time delta is the mean of the values less than 1 standard deviation from the median
				mean = 0;
				int meanCount = 0;
				foreach (var time in m_remoteSyncTimeCache[remoteID])
				{
					if (Math.Abs(time-median) < std_dev)
					{
						mean += time;
						meanCount++;
					}
				}
				mean /= meanCount;
				Debug.LogFormat("Time offset to {0} is {1}", remoteID, mean);

				m_remoteSyncTimeCache.Remove(remoteID);
				m_remoteSentTimeCache.Remove(remoteID);
				m_remotePlayers[remoteID].remoteTimeOffset = (float)mean;

				// now that times are synchronized, lets try to coordinate the
				// start time for the match
				OfferMatchStartTime();
			}
		}

19 Source : CreateAWaterfall3DChart.xaml.cs
with MIT License
from ABTSoftware

private void FillDataSeries(WaterfallDataSeries3D<double> dataSeries, int sliceCount, int pointsPerSlice)
        {
            var count = pointsPerSlice * 2;
            var re = new double[count];
            var im = new double[count];

            for (int sliceIndex = 0; sliceIndex < sliceCount; ++sliceIndex)
            {
                for (var i = 0; i < count; i++)
                {
                    re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    im[i] = -10;
                }

                _transform.run(re, im);

                var scaleCoef = Math.Pow(1.5, sliceIndex * 0.3) / Math.Pow(1.5, sliceCount * 0.3);
                for (var pointIndex = 0; pointIndex < pointsPerSlice; pointIndex++)
                {
                    var mag = Math.Sqrt(re[pointIndex] * re[pointIndex] + im[pointIndex] * im[pointIndex]);
                    var yVal = _random.Next(10,20) * Math.Log10(mag / pointsPerSlice);
                    yVal = (yVal < -25 || yVal > -5)
                        ? (yVal < -25) ? -25 : _random.Next(-6, -3)
                        : yVal;

                    dataSeries[sliceIndex, pointIndex] = -yVal * scaleCoef;
                }
            }
        }

19 Source : SurfaceMeshContours.xaml.cs
with MIT License
from ABTSoftware

private IDataSeries3D FillSeries(int index, int width, int height)
        {
            double angle = Math.PI*2*index/30;

            int w = width, h = height;

            var dataSeries = new UniformGridDataSeries3D<double>(w, h)
            {
                StepX = 0.01,
                StepZ = 0.01,
            };

            for (int x = 0; x < 200; x++)
            {
                for (int y = 0; y < 200; y++)
                {
                    var v = (1 + Math.Sin(x*0.04 + angle))*50 + (1 + Math.Sin(y*0.1 + angle))*50*(1 + Math.Sin(angle*2));
                    var cx = w/2;
                    var cy = h/2;
                    var r = Math.Sqrt((x - cx)*(x - cx) + (y - cy)*(y - cy));
                    var exp = Math.Max(0, 1 - r*0.008);
                    var zValue = v*exp;

                    dataSeries[y, x] = zValue;
                }
            }

            return dataSeries;
        }

19 Source : RealtimeWaterfall3DChart.xaml.cs
with MIT License
from ABTSoftware

private double[] GenerateDataRow()
        {
            var generatedRow = new double[_pointsPerSlice];

            // Randomly introduce changes in amplitude
            _tick++;

            if (_tick == 2)
            {
                _tick = 0;
                _step = _random.Next(10, 20);
            }

            for (int i = 0; i < _transformSize; i++)
            {
                double noise = _random.Next(-100, 100) * 0.002;

                // Compute a sinusoidal based waveform with some varying frequency and random amplitude 
                double y = _step * 2 * Math.Sin(2 * Math.PI * 0.1 * t) + noise;
                y += Math.Sin(2 * Math.PI * 0.2 * t);

                _real[i] = y;
                _imaginary[i] = 0;

                t += dt;
            }

            // Do an FFT
            _transform.run(_real, _imaginary);

            // Convert FFT back to magnitude (required for a meaningful output in our test data)
            for (int i = 0; i < _pointsPerSlice; i++)
            {
                double magnitude = Math.Sqrt(_real[i] * _real[i] + _imaginary[i] * _imaginary[i]);
                generatedRow[i] = Math.Log10(magnitude);
            }

            return generatedRow;
        }

19 Source : CreateRealTime3DUniformMeshChart.xaml.cs
with MIT License
from ABTSoftware

private void OnStart()
        {
            if (!IsLoaded) return;

            string whatData = (string)DataCombo.SelectedItem;
            int w = 0, h = 0;
            if (whatData == "3D Sinc 10 x 10") w = h = 10;
            if (whatData == "3D Sinc 50 x 50") w = h = 50;
            if (whatData == "3D Sinc 100 x 100") w = h = 100;
            if (whatData == "3D Sinc 500 x 500") w = h = 500;
            if (whatData == "3D Sinc 1k x 1k") w = h = 1000;

            lock (_syncRoot)
            {
                OnStop();
            }

            var dataSeries = new UniformGridDataSeries3D<double>(w, h)
            {
                StartX = 0, 
                StartZ = 0, 
                StepX = 10 / (w - 1d), 
                StepZ = 10 / (h - 1d),
                SeriesName = "Realtime Surface Mesh",
            };

            var frontBuffer = dataSeries.InternalArray;
            var backBuffer = new GridData<double>(w, h).InternalArray;

            int frames = 0;            
            _timer = new Timer();
            _timer.Interval = 20;
            _timer.Elapsed += (s, arg) =>
            {
                lock (_syncRoot)
                {
                    double wc = w*0.5, hc = h*0.5;
                    double freq = Math.Sin(frames++*0.1)*0.1 + 0.1;

                    // Each set of dataSeries[i,j] schedules a redraw when the next Render event fires. Therefore, we suspend updates so that we can update the chart once
                    // Data generation (Sin, Sqrt below) is expensive. We parallelize it by using Parallel.For for the outer loop
                    //  Equivalent of "for (int j = 0; j < h; j++)"
                    // This will result in more CPU usage, but we wish to demo the performance of the actual rendering, not the slowness of generating test data! :)
                    Parallel.For(0, h, i =>
                    {
                        var buf = frontBuffer;
                        for (int j = 0; j < w; j++)
                        {
                            // 3D Sinc function from http://www.mathworks.com/matlabcentral/cody/problems/1305-creation-of-2d-sinc-surface
                            // sin(pi*R*freq)/(pi*R*freq)
                            // R is distance from centre

                            double radius = Math.Sqrt((wc - i)*(wc - i) + (hc - j)*(hc - j));
                            var d = Math.PI*radius*freq;
                            var value = Math.Sin(d)/d;
                            buf[i][j] = double.IsNaN(value) ? 1.0 : value;
                        }
                    });

                    using (dataSeries.SuspendUpdates(false, true))
                    {
                        dataSeries.CopyFrom(frontBuffer);
                        var temp = backBuffer;
                        backBuffer = frontBuffer;
                        frontBuffer = temp;
                    }
                }
            };
            SurfaceMesh.DataSeries = dataSeries;
            _timer.Start();
            StartButton.IsEnabled = false;
            PauseButton.IsEnabled = true;
        }

19 Source : ViewModel3DFactory.cs
with MIT License
from ABTSoftware

private static WaterfallDataSeries3D<double> GereplacederfallDataSeries()
        {
            var pointsPerSlice = 100;
            var sliceCount = 20;

            var logBase = 10;
            var slicePositions = new double[sliceCount];
            for (int i = 0; i < sliceCount; ++i)
            {
                slicePositions[i] = i;
            }

            var dataSeries = new WaterfallDataSeries3D<double>(pointsPerSlice, slicePositions);
            dataSeries.StartX = 10;
            dataSeries.StepX = 1;

            _transform.init((uint)Math.Log(pointsPerSlice, 2));

            var count = pointsPerSlice * 2;
            var re = new double[count];
            var im = new double[count];

            for (int sliceIndex = 0; sliceIndex < sliceCount; ++sliceIndex)
            {
                for (var i = 0; i < count; i++)
                {
                    re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    im[i] = -10;
                }

                _transform.run(re, im);

                var scaleCoef = Math.Pow(1.5, sliceIndex * 0.3) / Math.Pow(1.5, sliceCount * 0.3);
                for (var pointIndex = 0; pointIndex < pointsPerSlice; pointIndex++)
                {
                    var mag = Math.Sqrt(re[pointIndex] * re[pointIndex] + im[pointIndex] * im[pointIndex]);
                    var yVal = _random.Next(10, 20) * Math.Log10(mag / pointsPerSlice);
                    yVal = (yVal < -25 || yVal > -5)
                        ? (yVal < -25) ? -25 : _random.Next(-6, -3)
                        : yVal;

                    dataSeries[sliceIndex, pointIndex] = -yVal * scaleCoef;
                }
            }

            return dataSeries;
        }

19 Source : SeriesCustomTooltips3DChart.xaml.cs
with MIT License
from ABTSoftware

private void Initialize()
        {
            var xyzDataSeries3D = new XyzDataSeries3D<double>();

            for (int i = 0, pointIndex = 0; i < Count; i++)
            {
                var m1 = _random.Next(2) == 0 ? -1 : 1;
                var m2 = _random.Next(2) == 0 ? -1 : 1;
                var x1 = _random.NextDouble() * m1;
                var x2 = _random.NextDouble() * m2;

                if (x1 * x1 + x2 * x2 > 1) continue;

                var x = 2 * x1 * Math.Sqrt(1 - x1 * x1 - x2 * x2);
                var y = 2 * x2 * Math.Sqrt(1 - x1 * x1 - x2 * x2);
                var z = 1 - 2 * (x1 * x1 + x2 * x2);

                // Append an XYZ Point with random color
                // Set the PointMetadata.Tag which we bind to in the View 
                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(GetRandomColor(), 3.0f, false, 
                    string.Format("PointMetadata Index {0}", ++pointIndex)));
            }

            SciChart.RenderableSeries[0].DataSeries = xyzDataSeries3D;
        }

19 Source : CubicSpline.cs
with MIT License
from ABTSoftware

public static void FitGeometric(double[] x, double[] y, int nOutputPoints, out double[] xs, out double[] ys)
        {
            // Compute distances
            int n = x.Length;
            double[] dists = new double[n]; // replacedulative distance
            dists[0] = 0;
            double totalDist = 0;

            for (int i = 1; i < n; i++)
            {
                double dx = x[i] - x[i - 1];
                double dy = y[i] - y[i - 1];
                double dist = (double)Math.Sqrt(dx * dx + dy * dy);
                totalDist += dist;
                dists[i] = totalDist;
            }

            // Create 'times' to interpolate to
            double dt = totalDist / (nOutputPoints - 1);
            double[] times = new double[nOutputPoints];
            times[0] = 0;

            for (int i = 1; i < nOutputPoints; i++)
            {
                times[i] = times[i - 1] + dt;
            }

            // Spline fit both x and y to times
            CubicSpline xSpline = new CubicSpline();
            xs = xSpline.FitAndEval(dists, x, times);

            CubicSpline ySpline = new CubicSpline();
            ys = ySpline.FitAndEval(dists, y, times);
        }

19 Source : SplineLineRenderableSeries.cs
with MIT License
from ABTSoftware

public override HitTestInfo HitTest(Point rawPoint, double hitTestRadius, bool interpolate = false)
            {
                var nearestBaseHitResult = base.HitTest(rawPoint, hitTestRadius, interpolate);

                // No spline? Fine - return base implementation
                if (!RenderableSeries.IsSplineEnabled || RenderableSeries._splineSeries == null || RenderableSeries.CurrentRenderPreplacedData == null)
                    return nearestBaseHitResult;

                var nearestHitResult = new HitTestInfo();

                // Get the coordinateCalculators. See 'Converting Pixel Coordinates to Data Coordinates' doreplacedentation for coordinate transforms
                var xCalc = RenderableSeries.CurrentRenderPreplacedData.XCoordinateCalculator;

                // Compute the X,Y data value at the mouse location
                var xDataPointAtMouse = xCalc.GetDataValue(RenderableSeries.CurrentRenderPreplacedData.IsVerticalChart ? rawPoint.Y : rawPoint.X);

                // Find the index in the spline interpolated data that is nearest to the X-Data point at mouse
                // NOTE: This replacedumes the data is sorted in ascending direction and a binary search would be faster ... 
                int foundIndex = RenderableSeries.FindIndex(RenderableSeries._splineSeries, xDataPointAtMouse);

                if (foundIndex != -1)
                {
                    nearestHitResult.IsWithinDataBounds = true;

                    // Find the nearest data point to the mouse 
                    var xDataPointNearest = RenderableSeries._splineSeries[foundIndex].X;
                    var yDataPointNearest = RenderableSeries._splineSeries[foundIndex].Y;
                    nearestHitResult.XValue = xDataPointNearest;
                    nearestHitResult.YValue = yDataPointNearest;

                    // Compute the X,Y coordinates (pixel coords) of the nearest data point to the mouse
                    nearestHitResult.HitTestPoint = nearestHitResult.HitTestPoint = RenderableSeries.GetCoordinatesFor(xDataPointNearest, yDataPointNearest);

                    // Determine if mouse-location is within 7.07 pixels of the nearest data point
                    var distance = Math.Pow(rawPoint.X - nearestHitResult.HitTestPoint.X, 2) +
                                   Math.Pow(rawPoint.Y - nearestHitResult.HitTestPoint.Y, 2);
                    distance = Math.Sqrt(distance);

                    var baseDistance = Math.Pow(rawPoint.X - nearestBaseHitResult.HitTestPoint.X, 2) +
                                       Math.Pow(rawPoint.Y - nearestBaseHitResult.HitTestPoint.Y, 2);
                    baseDistance = Math.Sqrt(baseDistance);

                    nearestHitResult.Ireplaced = distance <= DefaultHitTestRadius || baseDistance <= DefaultHitTestRadius;
                    nearestHitResult.IsVerticalHit = true;
                    nearestHitResult.DataSeriesIndex = nearestBaseHitResult.DataSeriesIndex;

                    if (RenderableSeries.DataSeries.HasMetadata)
                        nearestHitResult.Metadata = RenderableSeries.DataSeries.Metadata[nearestHitResult.DataSeriesIndex];

                    // Returning a HitTestResult with Ireplaced = true / IsVerticalHit signifies to the Rollovermodifier & TooltipModifier to show a tooltip at this location
                    return nearestHitResult;
                }
                else
                {
                    // Returning HitTestInfo.Empty signifies to the RolloverModifier & TooltipModifier there is nothing to show here
                    return HitTestInfo.Empty;
                }
            }

19 Source : ContoursExampleView.xaml.cs
with MIT License
from ABTSoftware

private IDataSeries CreateSeries(int index, int width, int height, double cpMax)
        {
            var w = width;
            var h = height;

            var angle = Math.PI * 2 * index / 30;
            var data = new double[h, w];
            var smallValue = 0d;
            
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Sin(x * 0.04 + angle)) * 50 +
                            (1 + Math.Sin(y * 0.1 + angle)) * 50 * (1 + Math.Sin(angle * 2));
                    
                    var cx = w / 2;
                    var cy = h / 2;
                    
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    var zValue = (v * exp);
                    
                    data[y, x] = (zValue > cpMax) ? cpMax : zValue;
                    data[y, x] += smallValue;
                }

                smallValue += 0.001;
            }

            return new UniformHeatmapDataSeries<int, int, double>(data, 0, 1, 0, 1);
        }

19 Source : UniformHeatmapAndPaletteProvider.xaml.cs
with MIT License
from ABTSoftware

private IDataSeries CreateSeries()
        {
            double angle = Math.Round(Math.PI * 2 * 1 / 30, 3);
            int w = 300, h = 200;
            var data = new double[h, w];
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Round(Math.Sin(x * 0.04 + angle), 3)) * 50 + (1 + Math.Round(Math.Sin(y * 0.1 + angle), 3)) * 50 * (1 + Math.Round(Math.Sin(angle * 2), 3));
                    var cx = 150; var cy = 100;
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    data[y, x] = (v * exp + _random.NextDouble() * 50);
                }

            var xStart = new DateTime(2017, 1, 13, 0, 0, 0);
            var xStep = DateTime.MinValue.AddDays(1).AddHours(6).AddMinutes(30);
            return new UniformHeatmapDataSeries<DateTime, int, double>(data, xStart, xStep, 0, 2) { SeriesName = "UniformHeatmap" };
        }

19 Source : UniformHeatmapPeakDetection.xaml.cs
with MIT License
from ABTSoftware

private double[,] GetSpectrogramBuffer()
        {
            const int yCount = 100;
            const int xCount = 4_096;
            var spectrogramBuffer = new double[yCount, xCount];

            var random = new Random();
            var transform = new FFT2();
            transform.init(12);

            var re = new double[xCount];
            var im = new double[xCount];
            for (int y = 0; y < yCount; y++)
            {
                for (int i = 0; i < xCount; i++)
                {
                    re[i] = 2d * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) -
                            2d * random.NextDouble();
                    im[i] = -10;
                }

                transform.run(re, im);

                for (int i = 0; i < xCount; i++)
                {
                    var mag = Math.Sqrt(re[i] * re[i] + im[i] * im[i]);
                    im[i] = i;

                    spectrogramBuffer[y, i] = 20 * Math.Log10(mag / xCount);
                }
            }

            return spectrogramBuffer;
        }

19 Source : AudioDataAnalyzer.cs
with MIT License
from ABTSoftware

private void ComputeDbValues(Complex[] compl, double[] tgt)
        {
            for (int i = 0; i < FftDataPoints; i++)
            {
                var c = compl[i];
                double mag = Math.Sqrt(c.X * c.X + c.Y * c.Y);
                var db = 20 * Math.Log10(mag);
                tgt[i] = db;
            }
        }

19 Source : WaterfallChart.xaml.cs
with MIT License
from ABTSoftware

private XyDataSeries<double, double> UpdateXyDataSeries()
        {
            var doubleSeries = new XyDataSeries<double, double>();

            var _re = new double[1024];
            var _im = new double[1024];

            for (var i = 0; i < 1024; i++)
            {
                _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                         5 * Math.Sin(2 * Math.PI * i / 10) +
                         2.0 * _random.NextDouble();
                _im[i] = -10;
            }

            _transform.run(_re, _im);
            var _re2 = new double[500];
            var _im2 = new double[500];
            for (var i = 0; i < 500; i++)
            {
                var mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                var yVal = 20 * Math.Log10(mag / 500);
                _re2[i] = (yVal < -25 || yVal > -5)
                    ? (yVal < -25) ? -25 : _random.Next(-6, -3)
                    : yVal;

                _im2[i] = i;
            }
            _re2[0] = -25;
            doubleSeries.Append(_im2, _re2);

            return doubleSeries;
        }

19 Source : HeatMapExampleView.xaml.cs
with MIT License
from ABTSoftware

private IDataSeries CreateSeries(int index, int width, int height, double cpMin, double cpMax)
        {
            var seed = SeriesAnimationBase.GlobalEnableAnimations ? (Environment.TickCount << index) : 0;
            var random = new Random(seed);
            double angle = Math.Round(Math.PI * 2 * index, 3) / seriesPerPeriod;
            int w = width, h = height;
            var data = new double[h, w];
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Round(Math.Sin(x * 0.04 + angle), 3)) * 50 + (1 + Math.Round(Math.Sin(y * 0.1 + angle), 3)) * 50 * (1 + Math.Round(Math.Sin(angle * 2), 3));
                    var cx = w / 2; var cy = h / 2;
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    var zValue = (v * exp + random.NextDouble() * 50);
                    data[y, x] = (zValue > cpMax) ? cpMax : zValue;
                }
            return new UniformHeatmapDataSeries<int, int, double>(data, 0, 1, 0, 1);
        }

19 Source : Person.cs
with MIT License
from ABTSoftware

public void UpdatePosition(double deltaT)
        {
            //Constrain target to (0,0)-(1,1)
            Point target2 = new Point(To01(Target.X), To01(Target.Y));
            double distance = PointUtil.Distance(target2, Pos);
            if (distance < Speed*deltaT)
            {
                Pos = target2;
            }
            else
            {
                // Get the velocity vector
                Point velocity = new Point((target2.X - Pos.X), (target2.Y - Pos.Y));

                // Normalize the vector
                double length = Math.Sqrt(velocity.X*velocity.X + velocity.Y*velocity.Y);
                velocity = new Point(velocity.X / length, velocity.Y / length);

                // Compute updated position 
                var newPos = new Point(Pos.X + velocity.X*deltaT, Pos.Y + velocity.Y*deltaT);
                Pos = newPos;
            }
        }

19 Source : Victim.cs
with MIT License
from ABTSoftware

public sealed override void CalculateTarget()
        {            
            Point aggressorPos = Aggressor.Pos;
            Point defenderPos = Defender.Pos;
            Point threatAxis = new Point((aggressorPos.X - Pos.X), (aggressorPos.Y - Pos.Y));
            Point flightAxis = new Point(-threatAxis.Y, threatAxis.X); // 90 degrees to Threat        

            double length = Math.Sqrt(flightAxis.X * flightAxis.X + flightAxis.Y * flightAxis.Y);
            if (length == 0 || defenderPos == aggressorPos)
            {
                Target = defenderPos;
            }
            else
            {
                Point safeVector = new Point((defenderPos.X - aggressorPos.X), (defenderPos.Y - aggressorPos.Y));
                double denom = (flightAxis.X*safeVector.Y - flightAxis.Y*safeVector.X);
                double q = denom == 0 ? 1 : (safeVector.X*threatAxis.Y - safeVector.Y*threatAxis.X)/denom;
                if (q < 1 || double.IsNaN(q))
                {
                    q = 1; // Make sure we're at least *behind* the defender, rather than just in line
                }
                Target = new Point(Pos.X + q * flightAxis.X, Pos.Y + q*flightAxis.Y);
            }
        }

19 Source : SpectrogramDemoView.xaml.cs
with MIT License
from ABTSoftware

private void UpdateXyDataSeries()
        {
            lock (this)
            {               
                for (int i = 0; i < 1024; i++)
                {
                    _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    _im[i] = -10;
                }

                _transform.run(_re, _im);
                for (int i = 0; i < 1024; i++)
                {
                    double mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                    _re[i] = 20 * Math.Log10(mag / 1024);
                    _im[i] = i;
                }

                _xyDataSeries.Clear();
                _xyDataSeries.Append(_im, _re);             
            }
        }

19 Source : SpectrumAnalyzerExampleViewModel.cs
with MIT License
from ABTSoftware

private void UpdateData()
        {
            lock (this)
            {                
                for (int i = 0; i < Count; i++)
                {
                    _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                            5.0 * Math.Sin(2 * Math.PI * i / 10) +
                            2.0 * _random.NextDouble();
                    _im[i] = IsFrequencyDomain ? 0.0 : i;
                }

                if (IsFrequencyDomain)
                {
                    _transform.run(_re, _im);
                    for (int i = 0; i < Count; i++)
                    {
                        double mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                        _re[i] = 20 * Math.Log10(mag / Count);
                        _im[i] = i;
                    }
                }                

                _dataSeries.SeriesName = YAxisreplacedle;
                _dataSeries.Clear();
                _dataSeries.Append(_im, _re);
            }
        }

See More Examples