System.Math.Sin(double)

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

3823 Examples 7

19 View Source File : SynchronizeMouseAcrossChartsViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateDataSeries()
        {
            const int count = 1000;

            var ds = new UniformXyDataSeries<double>();

            for (int i = 0; i < count; i++)
            {
                ds.Append(count * Math.Sin(Math.Round(i * Math.PI, 3) * 0.1) / i);
            }

            return ds;
        }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public DoubleSeries GetDampedSinewave(int pad, double amplitude, double phase, double dampingFactor, int pointCount, int freq = 10)
        {
            var doubleSeries = new DoubleSeries();

            for (int i = 0; i < pad; i++)
            {
                double time = 10 * i / (double)pointCount;
                doubleSeries.Add(new XYPoint() { X = time });
            }

            for (int i = pad, j = 0; i < pointCount; i++, j++)
            {
                var xyPoint = new XYPoint();

                double time = 10 * i / (double)pointCount;
                double wn = 2 * Math.PI / (pointCount / (double)freq);

                xyPoint.X = time;
                xyPoint.Y = amplitude * Math.Sin(j * wn + phase);
                doubleSeries.Add(xyPoint);

                amplitude *= 1.0 - dampingFactor;
            }

            return doubleSeries;
        }

19 View Source File : CreateRealTime3DUniformMeshChart.xaml.cs
License : MIT License
Project Creator : 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 View Source File : RealtimeFifoChartView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnNewData(object sender, EventArgs e)
        {
            // Compute our three series values
            double y1 = 3.0 * Math.Sin(2 * Math.PI * 1.4 * t) + _random.NextDouble() * 0.5;
            double y2 = 2.0 * Math.Cos(2 * Math.PI * 0.8 * t) + _random.NextDouble() * 0.5;
            double y3 = 1.0 * Math.Sin(2 * Math.PI * 2.2 * t) + _random.NextDouble() * 0.5;

            // Suspending updates is optional, and ensures we only get one redraw
            // once all three dataseries have been appended to
            using (sciChart.SuspendUpdates())
            {
                // Append x,y data to previously created series
                series0.Append(y1);
                series1.Append(y2);
                series2.Append(y3);
            }

            // Increment current time
            t += dt;
        }

19 View Source File : CreateAPointLine3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var xyzDataSeries3D = new XyzDataSeries3D<double>();

            var random = new Random(0);

            for (var i = 0; i < Count; i++)
            {
                var x = 5*Math.Sin(i);
                var y = i;
                var z = 5*Math.Cos(i);

                Color? randomColor = Color.FromArgb(0xFF, (byte) random.Next(50, 255), (byte) random.Next(50, 255), (byte) random.Next(50, 255));
                var scale = (float) ((random.NextDouble() + 0.5)*3.0);

                xyzDataSeries3D.Append(x, y, z, new PointMetadata3D(randomColor, scale));
            }

            PointLineSeries3D.DataSeries = xyzDataSeries3D;
        }

19 View Source File : DatapointMarkersView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void DatapointMarkersViewLoaded(object sender, RoutedEventArgs e)
        {
            var seriesA = new UniformXyDataSeries<double>(0d, 1d);
            var seriesB = new UniformXyDataSeries<double>(0d, 1d);

            seriesA.SeriesName = "Sinewave A";
            seriesB.SeriesName = "Sinewave B";

            double count = 100.0;
            double k = 2 * Math.PI / 30.0;
            for (int i = 0; i < (int)count; i++)
            {
                var phi = k * i;
                seriesA.Append((1.0 + i / count) * Math.Sin(phi));
                seriesB.Append((0.5 + i / count) * Math.Sin(phi));
            }

            sciChart.RenderableSeries[0].DataSeries = seriesA;
            sciChart.RenderableSeries[1].DataSeries = seriesB;
        }

19 View Source File : SpectrumAnalyzerExampleViewModel.cs
License : MIT License
Project Creator : 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);
            }
        }

19 View Source File : gps2bd.cs
License : MIT License
Project Creator : 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 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public DoubleSeries GetSquirlyWave()
        {
            var doubleSeries = new DoubleSeries();
            var rand = new Random(0);

            const int COUNT = 1000;
            for (int i = 0; i < COUNT; i++)            
            {
                var xyPoint = new XYPoint();

                var time = i / (double)COUNT;
                xyPoint.X = time;
                xyPoint.Y = time * Math.Sin(2 * Math.PI * i / (double)COUNT) +
                             0.2 * Math.Sin(2 * Math.PI * i / (COUNT / 7.9)) +
                             0.05 * (rand.NextDouble() - 0.5) +
                             1.0;

                doubleSeries.Add(xyPoint);
            }

            return doubleSeries;
        }

19 View Source File : gps2bd.cs
License : MIT License
Project Creator : 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 View Source File : ContoursExampleView.xaml.cs
License : MIT License
Project Creator : 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 View Source File : CreateRealTime3DGeoidChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

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

            int countU, countV;
            switch (DataCombo.SelectedIndex)
            {
                case 0:
                    countU = countV = 10;
                    break;
                case 1:
                    countU = countV = 50;
                    break;
                case 2:
                    countU = countV = 100;
                    break;
                case 3:
                    countU = countV = 500;
                    break;
                case 4:
                    countU = countV = 1000;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            lock (_syncRoot)
            {
                OnStop();
            }

            BitmapImage bitmapImage = new BitmapImage();

            // Load image from resources
            bitmapImage.BeginInit();
            bitmapImage.CacheOption = BitmapCacheOption.OnDemand;
            bitmapImage.CreateOptions = BitmapCreateOptions.DelayCreation;
            bitmapImage.DecodePixelWidth = countU;
            bitmapImage.DecodePixelHeight = countV;
            bitmapImage.UriSource = new Uri("pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Images/globe_heightmap.png");
            bitmapImage.EndInit();

            // Creating Geo height (displacement) map
            var geoHeightMap = new double[countU, countV];
            int nStride = (bitmapImage.PixelWidth * bitmapImage.Format.BitsPerPixel + 7) / 8;
            int bytsPerPixel = bitmapImage.Format.BitsPerPixel / 8;
            byte[] pixelByteArray = new byte[bitmapImage.PixelWidth * nStride];
            bitmapImage.CopyPixels(pixelByteArray, nStride, 0);
            for (int v = 0; v < countV; v++)
            {
                for (var u = 0; u < countU; u++)
                {
                    int pixelIndex = v * nStride + u * bytsPerPixel;
                    var offset = pixelByteArray[pixelIndex] / 255.0f;
                    geoHeightMap[v, u] = offset;
                }
            }

            var dataSeries = new EllipsoidDataSeries3D<double>(countU, countV)
            {
                SeriesName = "Geo Mesh",
                A = 6,
                B = 6,
                C = 6
            };

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

            int frames = 0;
            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(20);
            _timer.Tick += (s, arg) =>
            {
                lock (_syncRoot)
                {
                    double heightOffsetsScale = sliderHeightOffsetsScale.Value;
                    double freq = (Math.Sin(frames++*0.1) + 1.0) / 2.0;

                    // Each set of geoHeightMap[i,j] schedules a redraw when the next Render event fires. Therefore, we suspend updates so that we can update the chart once
                    // We parallelize it by using Parallel.For for the outer loop
                    //  Equivalent of "for (int j = 0; j < countU; 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, countV, i =>
                    {
                        var buf = frontBuffer;
                        for (int j = 0; j < countU; j++)
                        {
                            // Rotate (offset) J index
                            int rj = j + frames;
                            if (rj >= countU)
                            {
                                rj -= countU * (rj / countU);
                            }

                            buf[i][j] = geoHeightMap[i, rj] + Math.Pow(geoHeightMap[i, rj], freq * 10.0) * heightOffsetsScale;
                        }
                    });

                    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 View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : ab4d

private void CreateSceneObjects()
        {
            // NOTE: For VR all units must be in meters
            
            var rootVisual3D = new ModelVisual3D();

            // NOTE that the size of the scene will affect the quality of the shadows (bigger scene requite bigger shadow map)
            var floorBox = new BoxVisual3D()
            {
                CenterPosition = new Point3D(0, -0.5, 0),
                Size = new Size3D(10, 1, 10),                  // 10 x 1 x 10 meters
                Material = new DiffuseMaterial(Brushes.Green)
            };

            rootVisual3D.Children.Add(floorBox);

            double centerX = 0;
            double centerZ = 0;
            double circleRadius = 3;
            double boxesHeight = 1.3;

            var grayMaterial = new DiffuseMaterial(Brushes.Gray);
            var goldMaterial = new MaterialGroup();
            goldMaterial.Children.Add(new DiffuseMaterial(Brushes.Gold));
            goldMaterial.Children.Add(new SpecularMaterial(Brushes.White, 16));

            // Create spheres on top of boxes that are organized in a circle
            for (int a = 0; a < 360; a += 36)
            {
                double rad = SharpDX.MathUtil.DegreesToRadians(a + 18);
                double x = Math.Sin(rad) * circleRadius + centerX;
                double z = Math.Cos(rad) * circleRadius + centerZ;

                var boxVisual3D = new BoxVisual3D()
                {
                    CenterPosition = new Point3D(x, boxesHeight * 0.5, z),
                    Size = new Size3D(0.2, boxesHeight, 0.2),
                    Material = grayMaterial
                };

                var sphereVisual3D = new SphereVisual3D()
                {
                    CenterPosition = new Point3D(x, boxesHeight + 0.1, z),
                    Radius = 0.1,
                    Material = goldMaterial
                };

                rootVisual3D.Children.Add(boxVisual3D);
                rootVisual3D.Children.Add(sphereVisual3D);
            }


            // Read dragon model from obj file into Model3D object
            string dragonFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\dragon_vrip_res3.obj");

            var readerObj = new Ab3d.ReaderObj();
            var dragonModel3D = readerObj.ReadModel3D(dragonFileName);

            // Scale the model
            dragonModel3D.Transform = new ScaleTransform3D(10, 10, 10);

            Ab3d.Utilities.ModelUtils.ChangeMaterial(dragonModel3D, newMaterial: goldMaterial, newBackMaterial: null);

            // Add it to the scene
            var modelVisual3D = new ModelVisual3D();
            modelVisual3D.Content = dragonModel3D;

            rootVisual3D.Children.Add(modelVisual3D);


            // Add another box that will represet a base for the dragon model
            var dragonBaseBox = new BoxVisual3D()
            {
                CenterPosition = new Point3D(0, 0.27, 0),
                Size = new Size3D(2.2, 0.54, 1),
                Material = grayMaterial
            };

            rootVisual3D.Children.Add(dragonBaseBox);

            _viewport3D.Children.Clear();
            _viewport3D.Children.Add(rootVisual3D);
        }

19 View Source File : UniformHeatmapPeakDetection.xaml.cs
License : MIT License
Project Creator : 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 View Source File : gps2bd.cs
License : MIT License
Project Creator : 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 View Source File : RolloverFeedback.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void RolloverFeedbackLoaded(object sender, RoutedEventArgs e)
        {
            sciChartSurface.YAxis.GrowBy = new DoubleRange(0.2, 0.2);

            var seriesA = new UniformXyDataSeries<double>();
            var seriesB = new UniformXyDataSeries<double>();
            var seriesC = new UniformXyDataSeries<double>();

            seriesA.SeriesName = "Sinewave A";
            seriesB.SeriesName = "Sinewave B";
            seriesC.SeriesName = "Sinewave C";

            double count = 100.0;
            double k = 2 * Math.PI / 30.0;
            for (int i = 0; i < (int)count; i++)
            {
                var phi = k * i;
                seriesA.Append((1.0 + i / count) * Math.Sin(phi));
                seriesB.Append((0.5 + i / count) * Math.Sin(phi));
                seriesC.Append(i / count * Math.Sin(phi));
            }

            sciChartSurface.RenderableSeries[0].DataSeries = seriesA;
            sciChartSurface.RenderableSeries[1].DataSeries = seriesB;
            sciChartSurface.RenderableSeries[2].DataSeries = seriesC;
        }

19 View Source File : SurfaceMeshContours.xaml.cs
License : MIT License
Project Creator : 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 View Source File : UniformDataManager.cs
License : MIT License
Project Creator : ABTSoftware

public static void GeneratereplacedogData(float[] buffer)
        {
            var count = buffer.Length;
            var freq = count / 100;

            var amp = 1d;
            var phase = 0d;

            for (int i = 0, j = 0; i < count; i++, j++)
            {
                var wn = 2 * Math.PI / (count / (double)freq);
                buffer[i] = (float)(amp * Math.Sin(j * wn + phase));
            }
        }

19 View Source File : leastsquares.cs
License : MIT License
Project Creator : 1CM69

public static void buildlinearleastsquares(ref double[] x, ref double[] y, int n, ref double a, ref double b)
  {
    double num1 = (double) n;
    double num2 = 0.0;
    double num3 = 0.0;
    double num4 = 0.0;
    double num5 = 0.0;
    for (int index = 0; index <= n - 1; ++index)
    {
      num3 += x[index];
      num2 += AP.Math.Sqr(x[index]);
      num4 += y[index];
      num5 += x[index] * y[index];
    }
    double num6 = System.Math.Atan2(2.0 * num3, num2 - num1) / 2.0;
    double X1 = System.Math.Cos(num6);
    double X2 = System.Math.Sin(num6);
    double num7 = AP.Math.Sqr(X1) * num1 + AP.Math.Sqr(X2) * num2 - 2.0 * X2 * X1 * num3;
    double num8 = AP.Math.Sqr(X2) * num1 + AP.Math.Sqr(X1) * num2 + 2.0 * X2 * X1 * num3;
    double num9 = System.Math.Abs(num7) <= System.Math.Abs(num8) ? System.Math.Abs(num8) : System.Math.Abs(num7);
    double num10 = X1 * num4 - X2 * num5;
    double num11 = X2 * num4 + X1 * num5;
    double num12 = System.Math.Abs(num7) <= num9 * 5E-16 * 1000.0 ? 0.0 : num10 / num7;
    double num13 = System.Math.Abs(num8) <= num9 * 5E-16 * 1000.0 ? 0.0 : num11 / num8;
    a = X1 * num12 + X2 * num13;
    b = -(X2 * num12) + X1 * num13;
  }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

private double GetFourierYValue(double amplitude, double phaseShift, int index, int count)
        {
            double wn = 2 * Math.PI / (count / 10);

            return Math.PI * amplitude *
                   (Math.Sin(index * wn + phaseShift) +
                    (0.33 * Math.Sin(index * 3 * wn + phaseShift)) +
                    (0.20 * Math.Sin(index * 5 * wn + phaseShift)) +
                    (0.14 * Math.Sin(index * 7 * wn + phaseShift)) +
                    (0.11 * Math.Sin(index * 9 * wn + phaseShift)) +
                    (0.09 * Math.Sin(index * 11 * wn + phaseShift)));
        }

19 View Source File : ViewModel3DFactory.cs
License : MIT License
Project Creator : 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 View Source File : CreateAWaterfall3DChart.xaml.cs
License : MIT License
Project Creator : 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 View Source File : rotations.cs
License : MIT License
Project Creator : 1CM69

private static void testrotations()
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[,] numArray4 = new double[0, 0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double[] numArray9 = new double[0];
    int num1 = 1000;
    double val2_1 = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      int num2 = 2 + AP.Math.RandomInteger(50);
      int num3 = 2 + AP.Math.RandomInteger(50);
      bool isforward = AP.Math.RandomReal() > 0.5;
      int num4 = System.Math.Max(num2, num3);
      double[,] a1 = new double[num2 + 1, num3 + 1];
      double[,] a2 = new double[num2 + 1, num3 + 1];
      double[,] a3 = new double[num2 + 1, num3 + 1];
      double[,] a4 = new double[num2 + 1, num3 + 1];
      double[] c1 = new double[num2 - 1 + 1];
      double[] s1 = new double[num2 - 1 + 1];
      double[] c2 = new double[num3 - 1 + 1];
      double[] s2 = new double[num3 - 1 + 1];
      double[] work = new double[num4 + 1];
      for (int index2 = 1; index2 <= num2; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
        {
          a1[index2, index3] = 2.0 * AP.Math.RandomReal() - 1.0;
          a2[index2, index3] = a1[index2, index3];
          a3[index2, index3] = a1[index2, index3];
          a4[index2, index3] = a1[index2, index3];
        }
      }
      for (int index2 = 1; index2 <= num2 - 1; ++index2)
      {
        double num5 = 2.0 * System.Math.PI * AP.Math.RandomReal();
        c1[index2] = System.Math.Cos(num5);
        s1[index2] = System.Math.Sin(num5);
      }
      for (int index2 = 1; index2 <= num3 - 1; ++index2)
      {
        double num5 = 2.0 * System.Math.PI * AP.Math.RandomReal();
        c2[index2] = System.Math.Cos(num5);
        s2[index2] = System.Math.Sin(num5);
      }
      rotations.applyrotationsfromtheleft(isforward, 1, num2, 1, num3, ref c1, ref s1, ref a1, ref work);
      for (int index2 = 1; index2 <= num3; ++index2)
        rotations.applyrotationsfromtheleft(isforward, 1, num2, index2, index2, ref c1, ref s1, ref a2, ref work);
      double val1_1 = 0.0;
      for (int index2 = 1; index2 <= num2; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          val1_1 = System.Math.Max(val1_1, System.Math.Abs(a1[index2, index3] - a2[index2, index3]));
      }
      double val2_2 = System.Math.Max(val1_1, val2_1);
      rotations.applyrotationsfromtheright(isforward, 1, num2, 1, num3, ref c2, ref s2, ref a3, ref work);
      for (int index2 = 1; index2 <= num2; ++index2)
        rotations.applyrotationsfromtheright(isforward, index2, index2, 1, num3, ref c2, ref s2, ref a4, ref work);
      double val1_2 = 0.0;
      for (int index2 = 1; index2 <= num2; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          val1_2 = System.Math.Max(val1_2, System.Math.Abs(a3[index2, index3] - a4[index2, index3]));
      }
      val2_1 = System.Math.Max(val1_2, val2_2);
    }
    Console.Write("TESTING ROTATIONS");
    Console.WriteLine();
    Console.Write("Preplaced count ");
    Console.Write("{0,0:d}", (object) num1);
    Console.WriteLine();
    Console.Write("Error is ");
    Console.Write("{0,5:E3}", (object) val2_1);
    Console.WriteLine();
  }

19 View Source File : UniformColumn3D.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var uniformDataSeries = new UniformGridDataSeries3D<double>(CountX, CountZ)
            {
                StepX = 7,
                StepZ = 130,
                StartX = 9,
                StartZ = 295,
                SeriesName = "Column 3D Data",
            };

            for (var x = 0; x < CountX; x++)
            {
                for (var z = 0; z < CountZ; z++)
                {
                    var y = Math.Sin(x * 0.25) / ((z + 1) * 2);
                    uniformDataSeries[z, x] = y;
                }
            }

            //Trace.WriteLine(uniformDataSeries.To2DArray().ToStringArray2D());
            SciChart.RenderableSeries[0].DataSeries = uniformDataSeries;
        }

19 View Source File : AccelCalculator.cs
License : MIT License
Project Creator : a1xd

public static (double, double) GetRotVector(Profile settings) =>
            (Math.Cos(settings.rotation), Math.Sin(settings.rotation));

19 View Source File : SeriesTooltips3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private Point3D RotateAroundZ(Point3D point, double angle)
        {
            var x = point.X * Math.Cos(angle) - point.Y * Math.Sin(angle);
            var y = point.X * Math.Sin(angle) + point.Y * Math.Cos(angle);

            return new Point3D(x, y, point.Z);
        }

19 View Source File : ViewModel3DFactory.cs
License : MIT License
Project Creator : ABTSoftware

private static UniformGridDataSeries3D<double> GetSurfaceMeshDataSeries()
        {
            var meshDataSeries = new UniformGridDataSeries3D<double>(80, 25) { StepX = 1, StepZ = 1 };

            for (int x = 0; x < 80; x++)
            {
                for (int z = 0; z < 25; z++)
                {
                    var s = DataManager.Instance.GetGaussianRandomNumber(100, 100);
                    double y = Math.Sin(x * 0.2 * s) / ((z + 1) * 2);
                    y = y >= 0 ? y : 0;
                    meshDataSeries[z, x] = y * Math.Abs(s);
                }
            }

            return meshDataSeries;
        }

19 View Source File : OculusDemoForm.cs
License : MIT License
Project Creator : ab4d

private void CreateSceneObjects()
        {
            // NOTE: For VR all units must be in meters

            var rootVisual3D = new ModelVisual3D();

            // NOTE that the size of the scene will affect the quality of the shadows (bigger scene requite bigger shadow map)
            var floorBox = new BoxVisual3D()
            {
                CenterPosition = new Point3D(0, -0.5, 0),
                Size = new Size3D(10, 1, 10),                  // 10 x 1 x 10 meters
                Material = new DiffuseMaterial(Brushes.Green)
            };

            rootVisual3D.Children.Add(floorBox);

            double centerX = 0;
            double centerZ = 0;
            double circleRadius = 3;
            double boxesHeight = 1.3;

            var grayMaterial = new DiffuseMaterial(Brushes.Gray);
            var goldMaterial = new MaterialGroup();
            goldMaterial.Children.Add(new DiffuseMaterial(Brushes.Gold));
            goldMaterial.Children.Add(new SpecularMaterial(Brushes.White, 16));

            // Create spheres on top of boxes that are organized in a circle
            for (int a = 0; a < 360; a += 36)
            {
                double rad = SharpDX.MathUtil.DegreesToRadians(a + 18);
                double x = Math.Sin(rad) * circleRadius + centerX;
                double z = Math.Cos(rad) * circleRadius + centerZ;

                var boxVisual3D = new BoxVisual3D()
                {
                    CenterPosition = new Point3D(x, boxesHeight * 0.5, z),
                    Size = new Size3D(0.2, boxesHeight, 0.2),
                    Material = grayMaterial
                };

                var sphereVisual3D = new SphereVisual3D()
                {
                    CenterPosition = new Point3D(x, boxesHeight + 0.1, z),
                    Radius = 0.1,
                    Material = goldMaterial
                };

                rootVisual3D.Children.Add(boxVisual3D);
                rootVisual3D.Children.Add(sphereVisual3D);
            }


            // Read dragon model from obj file into Model3D object
            string dragonFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\dragon_vrip_res3.obj");

            var readerObj = new Ab3d.ReaderObj();
            var dragonModel3D = readerObj.ReadModel3D(dragonFileName);

            // Scale the model
            dragonModel3D.Transform = new ScaleTransform3D(10, 10, 10);

            Ab3d.Utilities.ModelUtils.ChangeMaterial(dragonModel3D, newMaterial: goldMaterial, newBackMaterial: null);

            // Add it to the scene
            var modelVisual3D = new ModelVisual3D();
            modelVisual3D.Content = dragonModel3D;

            rootVisual3D.Children.Add(modelVisual3D);


            // Add another box that will represet a base for the dragon model
            var dragonBaseBox = new BoxVisual3D()
            {
                CenterPosition = new Point3D(0, 0.27, 0),
                Size = new Size3D(2.2, 0.54, 1),
                Material = grayMaterial
            };

            rootVisual3D.Children.Add(dragonBaseBox);

            _mainViewport3D.Children.Clear();
            _mainViewport3D.Children.Add(rootVisual3D);
        }

19 View Source File : RealTimeCursors.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnNewData(object sender, EventArgs e)
        {
            // Compute our three series values
            double y1 = 3.0 * Math.Sin(2 * Math.PI * 1.4 * t * 0.02);
            double y2 = 2.0 * Math.Cos(2 * Math.PI * 0.8 * t * 0.02);
            double y3 = 1.0 * Math.Sin(2 * Math.PI * 2.2 * t * 0.02);

            // Suspending updates is optional, and ensures we only get one redraw
            // once all three dataseries have been appended to
            using (sciChartSurface.SuspendUpdates())
            {
                // Append x,y data to previously created series
                _series0.Append(y1);
                _series1.Append(y2);
                _series2.Append(y3);
            }

            // Increment current time
            t += dt;
        }

19 View Source File : gps2bd.cs
License : MIT License
Project Creator : 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 View Source File : UniformHeatmapAndPaletteProvider.xaml.cs
License : MIT License
Project Creator : 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 View Source File : CircularProgressBar.xaml.cs
License : MIT License
Project Creator : Abdesol

private void SetPosition(Ellipse ellipse, double offset,
            double posOffSet, double step)
        {
            ellipse.SetValue(Canvas.LeftProperty, 50.0
                + Math.Sin(offset + posOffSet * step) * 10.0);

            ellipse.SetValue(Canvas.TopProperty, 50
                + Math.Cos(offset + posOffSet * step) * 10.0);
        }

19 View Source File : WaterfallChart.xaml.cs
License : MIT License
Project Creator : 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 View Source File : DefaultCaptchaImageGenerator.cs
License : MIT License
Project Creator : 1992w

private void AdjustRippleEffect(Bitmap baseMap)
        {
            short nWave = 6;
            int nWidth = baseMap.Width;
            int nHeight = baseMap.Height;

            Point[,] pt = new Point[nWidth, nHeight];

            for (int x = 0; x < nWidth; ++x)
            {
                for (int y = 0; y < nHeight; ++y)
                {
                    var xo = nWave * Math.Sin(2.0 * 3.1415 * y / 128.0);
                    var yo = nWave * Math.Cos(2.0 * 3.1415 * x / 128.0);

                    var newX = x + xo;
                    var newY = y + yo;

                    if (newX > 0 && newX < nWidth)
                    {
                        pt[x, y].X = (int)newX;
                    }
                    else
                    {
                        pt[x, y].X = 0;
                    }


                    if (newY > 0 && newY < nHeight)
                    {
                        pt[x, y].Y = (int)newY;
                    }
                    else
                    {
                        pt[x, y].Y = 0;
                    }
                }
            }

            Bitmap bSrc = (Bitmap)baseMap.Clone();

            BitmapData bitmapData = baseMap.LockBits(new Rectangle(0, 0, baseMap.Width, baseMap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int scanline = bitmapData.Stride;

            IntPtr scan0 = bitmapData.Scan0;
            IntPtr srcScan0 = bmSrc.Scan0;

            unsafe
            {
                byte* p = (byte*)(void*)scan0;
                byte* pSrc = (byte*)(void*)srcScan0;

                int nOffset = bitmapData.Stride - baseMap.Width * 3;

                for (int y = 0; y < nHeight; ++y)
                {
                    for (int x = 0; x < nWidth; ++x)
                    {
                        var xOffset = pt[x, y].X;
                        var yOffset = pt[x, y].Y;

                        if (yOffset >= 0 && yOffset < nHeight && xOffset >= 0 && xOffset < nWidth)
                        {
                            if (pSrc != null)
                            {
                                p[0] = pSrc[yOffset * scanline + xOffset * 3];
                                p[1] = pSrc[yOffset * scanline + xOffset * 3 + 1];
                                p[2] = pSrc[yOffset * scanline + xOffset * 3 + 2];
                            }
                        }

                        p += 3;
                    }
                    p += nOffset;
                }
            }

            baseMap.UnlockBits(bitmapData);
            bSrc.UnlockBits(bmSrc);
            bSrc.Dispose();
        }

19 View Source File : HeatMapExampleView.xaml.cs
License : MIT License
Project Creator : 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 View Source File : UniformImpulseSeries3D.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var uniformDataSeries = new UniformGridDataSeries3D<double>(CountX, CountZ)
            {
                StepX = 7,
                StepZ = 130,
                StartX = 9,
                StartZ = 295,
                SeriesName = "Impulse Series 3D",
            };

            for (var x = 0; x < CountX; x++)
            {
                for (var z = 0; z < CountZ; z++)
                {
                    var y = Math.Sin(x * 0.25) / ((z + 1) * 2);
                    uniformDataSeries[z, x] = y;
                }
            }

            //Trace.WriteLine(uniformDataSeries.To2DArray().ToStringArray2D());
            ImpulseSeries3D.DataSeries = uniformDataSeries;

            PointMarkerCombo.SelectedIndex = 0;
        }

19 View Source File : SpectrogramDemoView.xaml.cs
License : MIT License
Project Creator : 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 View Source File : gps2bd.cs
License : MIT License
Project Creator : 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 View Source File : UseHighQualityRenderingViewModel.cs
License : MIT License
Project Creator : ABTSoftware

private IXyDataSeries<double, double> CreateDataSeries()
        {
            const int count = 1000;

            var dataSeries = new XyDataSeries<double>();

            for (int i = 0; i < count; i++)
            {
                dataSeries.Append(i, count * Math.Sin(i * Math.PI * 0.1) / i);
            }
            return dataSeries;
        }

19 View Source File : RealtimeWaterfall3DChart.xaml.cs
License : MIT License
Project Creator : 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 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public double GetGaussianRandomNumber(double mean, double stdDev)
        {
            double u1 = _random.NextDouble(); //these are uniform(0,1) random doubles
            double u2 = _random.NextDouble();
            double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                         Math.Sin(2.0 * Math.PI * u2); //random normal(0,1)
            double randNormal =
                         mean + stdDev * randStdNormal; //random normal(mean,stdDev^2)
            return randNormal;
        }

19 View Source File : GhostEmoteWheel.cs
License : MIT License
Project Creator : 0x0ade

public override void Render() {
            base.Render();

            string[] emotes = CelesteNetClientModule.Settings.Emotes;

            // Update can halt in the pause menu.

            if (Shown) {
                Angle = CelesteNetClientModule.Instance.JoystickEmoteWheel.Value.Angle();
                float angle = (float) ((Angle + Math.PI * 2f) % (Math.PI * 2f));
                float start = (-0.5f / emotes.Length) * 2f * (float) Math.PI;
                if (2f * (float) Math.PI + start < angle) {
                    // Angle should be start < angle < 0, but is (TAU + start) < angle < TAU
                    angle -= 2f * (float) Math.PI;
                }
                for (int i = 0; i < emotes.Length; i++) {
                    float min = ((i - 0.5f) / emotes.Length) * 2f * (float) Math.PI;
                    float max = ((i + 0.5f) / emotes.Length) * 2f * (float) Math.PI;
                    if (min <= angle && angle <= max) {
                        Selected = i;
                        break;
                    }
                }
            }

            time += Engine.RawDeltaTime;

            if (!Shown) {
                Selected = -1;
            }
            selectedTime += Engine.RawDeltaTime;
            if (PrevSelected != Selected) {
                selectedTime = 0f;
                PrevSelected = Selected;
            }

            float popupAlpha;
            float popupScale;

            popupTime += Engine.RawDeltaTime;
            if (Shown && !popupShown) {
                popupTime = 0f;
            } else if ((Shown && popupTime > 1f) ||
                (!Shown && popupTime < 1f)) {
                popupTime = 1f;
            }
            popupShown = Shown;

            if (popupTime < 0.1f) {
                float t = popupTime / 0.1f;
                // Pop in.
                popupAlpha = Ease.CubeOut(t);
                popupScale = Ease.ElasticOut(t);

            } else if (popupTime < 1f) {
                // Stay.
                popupAlpha = 1f;
                popupScale = 1f;

            } else {
                float t = (popupTime - 1f) / 0.2f;
                // Fade out.
                popupAlpha = 1f - Ease.CubeIn(t);
                popupScale = 1f - 0.2f * Ease.CubeIn(t);
            }

            float alpha = Alpha * popupAlpha;

            if (alpha <= 0f)
                return;

            if (Tracking == null)
                return;

            Level level = SceneAs<Level>();
            if (level == null)
                return;

            popupScale *= level.GetScreenScale();

            Vector2 pos = Tracking.Position;
            pos.Y -= 8f;

            pos = level.WorldToScreen(pos);

            float radius = BG.Width * 0.5f * 0.75f * popupScale;

            pos = pos.Clamp(
                0f + radius, 0f + radius,
                1920f - radius, 1080f - radius
            );

            // Draw.Circle(pos, radius, Color.Black * 0.8f * alpha * alpha, radius * 0.6f * (1f + 0.2f * (float) Math.Sin(time)), 8);
            BG.DrawCentered(
                pos,
                Color.White * alpha * alpha * alpha,
                Vector2.One * popupScale
            );

            Indicator.DrawCentered(
                pos,
                Color.White * alpha * alpha * alpha,
                Vector2.One * popupScale,
                Angle
            );

            float selectedScale = 1.2f - 0.2f * Calc.Clamp(Ease.CubeOut(selectedTime / 0.1f), 0f, 1f) + (float) Math.Sin(time * 1.8f) * 0.05f;

            for (int i = 0; i < emotes.Length; i++) {
                Line.DrawCentered(
                    pos,
                    Color.White * alpha * alpha * alpha,
                    Vector2.One * popupScale,
                    ((i + 0.5f) / emotes.Length) * 2f * (float) Math.PI
                );

                string emote = emotes[i];
                if (string.IsNullOrEmpty(emote))
                    continue;

                float a = (i / (float) emotes.Length) * 2f * (float) Math.PI;
                Vector2 emotePos = pos + new Vector2(
                    (float) Math.Cos(a),
                    (float) Math.Sin(a)
                ) * radius;

                if (GhostEmote.IsIcon(emote)) {
                    MTexture icon = GhostEmote.GetIcon(emote, Selected == i ? selectedTime : 0f);
                    if (icon == null)
                        continue;

                    Vector2 iconSize = new(icon.Width, icon.Height);
                    float iconScale = (GhostEmote.Size / Math.Max(iconSize.X, iconSize.Y)) * 0.24f * popupScale;

                    icon.DrawCentered(
                        emotePos,
                        Color.White * (Selected == i ? (Calc.BetweenInterval(selectedTime, 0.1f) ? 0.9f : 1f) : 0.7f) * alpha,
                        Vector2.One * (Selected == i ? selectedScale : 1f) * iconScale
                    );

                } else {
                    Vector2 textSize = CelesteNetClientFont.Measure(emote);
                    float textScale = (GhostEmote.Size / Math.Max(textSize.X, textSize.Y)) * 0.24f * popupScale;

                    CelesteNetClientFont.DrawOutline(
                        emote,
                        emotePos,
                        new(0.5f, 0.5f),
                        Vector2.One * (Selected == i ? selectedScale : 1f) * textScale,
                        (Selected == i ? (Calc.BetweenInterval(selectedTime, 0.1f) ? TextSelectColorA : TextSelectColorB) : Color.LightSlateGray) * alpha,
                        2f,
                        Color.Black * alpha * alpha * alpha
                    );
                }

19 View Source File : DataManager.cs
License : MIT License
Project Creator : ABTSoftware

public double[] GetDampedSinewaveYData(int pad, double amplitude, double phase, double dampingFactor, int pointCount, int freq = 10)
        {
            var yValues = new double[pointCount];

            for (int i = 0; i < pad; i++)
            {
                yValues[i] = 0;
            }

            for (int i = pad, j = 0; i < pointCount; i++, j++)
            {
                double wn = 2 * Math.PI / (pointCount / (double)freq);

                yValues[i] = amplitude * Math.Sin(j * wn + phase);

                amplitude *= 1.0 - dampingFactor;
            }

            return yValues;
        }

19 View Source File : RealtimeOrthogonalHeatmap3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnNewData(object sender, EventArgs e)
        {
            _tick++;
            if (_tick == 2)
            {
                _tick = 0;
                _step = _random.Next(0, 11);
            }

            var mreplacedVal = new double[100];

            for (int i = 0; i < 100; i++)
            {
                double y = _step * Math.Sin(((2 * Math.PI) * 0.4) * t) + _random.NextDouble() * 2;
                _yValues[i] = y;
                _tValues[i] = t;
                mreplacedVal[i] = y + 10;                

                t += dt;
            }

            var sortData = mreplacedVal.OrderByDescending(x => x);

            using (_series0.SuspendUpdates())
            using (_series1.SuspendUpdates())
            using (_series2.SuspendUpdates())
            {
                _series0.Append(_tValues, _yValues);
                _series1.PushRow(sortData.ToArray());
                _series2.PushRow(sortData.ToArray());
            }
        }

19 View Source File : Mathd.cs
License : MIT License
Project Creator : 734843327

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

19 View Source File : GhostEmote.cs
License : MIT License
Project Creator : 0x0ade

public override void Render() {
            base.Render();

            if (Scene is not Level level)
                return;

            float popupScale = PopupScale * level.GetScreenScale();

            MTexture icon = null;
            string text = null;

            if (IsIcon(Value))
                icon = GetIcon(Value, Time);
            else
                text = Value;

            float alpha = Alpha * PopupAlpha;

            if (alpha <= 0f || (icon == null && string.IsNullOrWhiteSpace(text)))
                return;

            if (Tracking == null)
                return;

            Vector2 pos = level.WorldToScreen(Position);

            if (Float)
                pos.Y -= (float) Math.Sin(Time * 2f) * 4f;

            if (icon != null) {
                Vector2 size = new(icon.Width, icon.Height);
                float scale = (Size / Math.Max(size.X, size.Y)) * 0.5f * popupScale;
                size *= scale;

                pos = pos.Clamp(
                    0f + size.X * 0.5f + 64f, 0f + size.Y * 1f + 64f,
                    1920f - size.X * 0.5f - 64f, 1080f - 64f
                );

                icon.DrawJustified(
                    pos,
                    new(0.5f, 1f),
                    Color.White * alpha,
                    Vector2.One * scale
                );

            } else {
                Vector2 size = CelesteNetClientFont.Measure(text);
                float scale = (Size / Math.Max(size.X, size.Y)) * 0.5f * popupScale;
                size *= scale;

                pos = pos.Clamp(
                    0f + size.X * 0.5f, 0f + size.Y * 1f,
                    1920f - size.X * 0.5f, 1080f
                );

                CelesteNetClientFont.DrawOutline(
                    text,
                    pos,
                    new(0.5f, 1f),
                    Vector2.One * scale,
                    Color.White * alpha,
                    2f,
                    Color.Black * alpha * alpha * alpha
                );
            }
        }

19 View Source File : TestGame.cs
License : Microsoft Public License
Project Creator : 0x0ade

protected override void Draw(GameTime gameTime)
		{
			GraphicsDevice.Clear(Color.White * (0.5f + 0.5f * (float) Math.Sin(gameTime.TotalGameTime.TotalSeconds)));

			base.Draw(gameTime);
		}

19 View Source File : Arc.cs
License : MIT License
Project Creator : 3RD-Dimension

public override Vector3 Interpolate(double ratio)
		{
			double angle = StartAngle + AngleSpan * ratio;

			Vector3 onPlane = new Vector3(U + (Radius * Math.Cos(angle)), V + (Radius * Math.Sin(angle)), 0);

			double helix = (Start + (ratio * Delta)).RollComponents(-(int)Plane).Z;

			onPlane.Z = helix;

			Vector3 interpolation = onPlane.RollComponents((int)Plane);

			return interpolation;
		}

19 View Source File : AccelCalculator.cs
License : MIT License
Project Creator : a1xd

private SimulatedMouseInput SimulateAngledInput(double angle, double magnitude)
        {
            SimulatedMouseInput mouseInputData;

            var moveX = Math.Round(magnitude * Math.Cos(angle), 4);
            var moveY = Math.Round(magnitude * Math.Sin(angle), 4);

            if (moveX == 0)
            {
                mouseInputData.x = 0;
                mouseInputData.y = (int)Math.Ceiling(moveY);
                mouseInputData.time = mouseInputData.y / moveY;
            }
            else if (moveY == 0)
            {
                mouseInputData.x = (int)Math.Ceiling(moveX);
                mouseInputData.y = 0;
                mouseInputData.time = mouseInputData.x / moveX;
            }
            else
            {
                var ratio =  moveY / moveX;
                int ceilX = 0;
                int ceilY = 0;
                double biggerX = 0;
                double biggerY = 0;
                double roundedBiggerX = 0;
                double roundedBiggerY = 0;
                double roundedRatio = -1;
                double factor = 10;

                while (Math.Abs(roundedRatio - ratio) > 0.01 &&
                    biggerX < 25000 &&
                    biggerY < 25000)
                {
                    roundedBiggerX = Math.Floor(biggerX);
                    roundedBiggerY = Math.Floor(biggerY);
                    ceilX = Convert.ToInt32(roundedBiggerX);
                    ceilY = Convert.ToInt32(roundedBiggerY);
                    roundedRatio =  ceilX > 0 ? ceilY / ceilX : -1;
                    biggerX = moveX * factor;
                    biggerY = moveY * factor;
                    factor *= 10;
                }

                var ceilMagnitude = Magnitude(ceilX, ceilY);
                var timeFactor = ceilMagnitude / magnitude;

                mouseInputData.x = ceilX;
                mouseInputData.y = ceilY;
                mouseInputData.time = timeFactor;

                if (mouseInputData.x == 1 && mouseInputData.time == 1)
                {
                    Console.WriteLine("Oops");
                }

            }

            mouseInputData.velocity = DecimalCheck(Velocity(mouseInputData.x, mouseInputData.y, mouseInputData.time));

            if (double.IsNaN(mouseInputData.velocity))
            {
                Console.WriteLine("oopsie");
            }

            mouseInputData.angle = angle;
            return mouseInputData;
        }

19 View Source File : SeriesTooltips3DChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private Point RotatePoint(Point point, double angle)
        {
            var x = point.X*Math.Cos(angle) - point.Y*Math.Sin(angle);
            var y = point.X*Math.Sin(angle) + point.Y*Math.Cos(angle);

            return new Point(x, y);
        }

See More Examples