# System.Math.Cos(double)

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

## 3254 Examples

19 View Source File : Trajectory.cs
Project Creator : ACEmulator

``````public static float ballistic_range(float speed, float gravity, float initial_height)
{
// Handling these cases is up to your project's coding standards
//Debug.replacedert(speed > 0 && gravity > 0 && initial_height >= 0, "fts.ballistic_range called with invalid data");
if (speed <= 0 || gravity <= 0 || initial_height < 0)
return 0.0f;

// Derivation
//   (1) x = speed * time * cos O
//   (2) z = initial_height + (speed * time * sin O) - (.5 * gravity*time*time)
//   (3) via quadratic: t = (speed*sin O)/gravity + sqrt(speed*speed*sin O + 2*gravity*initial_height)/gravity    [ignore smaller root]
//   (4) solution: range = x = (speed*cos O)/gravity * sqrt(speed*speed*sin O + 2*gravity*initial_height)    [plug t back into x=speed*time*cos O]
var angle = 45 * 0.0174533; // no air resistence, so 45 degrees provides maximum range
var cos = Math.Cos(angle);
var sin = Math.Sin(angle);

var range = (speed * cos / gravity) * (speed * sin + Math.Sqrt(speed * speed * sin * sin + 2 * gravity * initial_height));
return (float)range;
}``````

19 View Source File : RotationMatrices.cs
Project Creator : ActuarialIntelligence

``````private static _3Matrix RotateX(double x)
{
_3Vector r1 = new _3Vector(1, 0, 0),
r2 = new _3Vector(0, Math.Cos(-x), -Math.Sin(-x)),
r3 = new _3Vector(0, Math.Sin(-x), Math.Cos(-x));

return new _3Matrix(r1, r2, r3);
}``````

19 View Source File : RandomPricesDataSource.cs
Project Creator : ABTSoftware

``````private PriceBar GetNextRandomPriceBar()
{
double close = _lastPriceBar.Close;
double num = (_random.NextDouble() - 0.9) * _initialPriceBar.Close / 30.0;
double num2 = _random.NextDouble();
double num3 = _initialPriceBar.Close + _initialPriceBar.Close / 2.0 * Math.Sin(7.27220521664304E-06 * _currentTime) + _initialPriceBar.Close / 16.0 * Math.Cos(7.27220521664304E-05 * _currentTime) + _initialPriceBar.Close / 32.0 * Math.Sin(7.27220521664304E-05 * (10.0 + num2) * _currentTime) + _initialPriceBar.Close / 64.0 * Math.Cos(7.27220521664304E-05 * (20.0 + num2) * _currentTime) + num;
double num4 = Math.Max(close, num3);
double num5 = _random.NextDouble() * _initialPriceBar.Close / 100.0;
double high = num4 + num5;
double num6 = Math.Min(close, num3);
double num7 = _random.NextDouble() * _initialPriceBar.Close / 100.0;
double low = num6 - num7;
long volume = (long) (_random.NextDouble()*30000 + 20000);
DateTime openTime = _simulateDateGap ? EmulateDateGap(_lastPriceBar.DateTime) : _lastPriceBar.DateTime;
PriceBar candle = new PriceBar(closeTime, close, high, low, num3, volume);
_lastPriceBar = new PriceBar(candle.DateTime, candle.Open, candle.High, candle.Low, candle.Close, volume);
_currentTime += _candleIntervalMinutes * 60;
return candle;
}``````

19 View Source File : Particle.cs
Project Creator : ACEmulator

``````public void Update(ParticleType particleType, bool persistent, PhysicsPart part, AFrame parent)
{
var currentTime = PhysicsTimer.CurrentTime;
var elapsedTime = currentTime - LastUpdateTime;

if (persistent)
{
LastUpdateTime = currentTime;
}
else

switch (particleType)
{
case ParticleType.Still:
part.Pos.Frame.Origin = parent.Origin + Offset;
break;
case ParticleType.LocalVelocity:
case ParticleType.GlobalVelocity:
part.Pos.Frame.Origin = (lifetime * A) + parent.Origin + Offset;
break;
case ParticleType.ParabolicLVGA:
case ParticleType.ParabolicLVLA:
case ParticleType.ParabolicGVGA:
break;
case ParticleType.ParabolicLVGAGR:
case ParticleType.ParabolicLVLALR:
case ParticleType.ParabolicGVGAGR:
part.Pos.Frame = new AFrame(parent);
break;
case ParticleType.Swarm:
var swarm = (lifetime * A) + C + parent.Origin + Offset;
part.Pos.Frame.Origin.X = (float)Math.Cos(lifetime * B.X) + swarm.X;
part.Pos.Frame.Origin.Y = (float)Math.Sin(lifetime * B.Y) + swarm.Y;
part.Pos.Frame.Origin.Z = (float)Math.Cos(lifetime * B.Z) + swarm.Z;
break;
case ParticleType.Explode:
part.Pos.Frame.Origin = (lifetime * B + C * A.X) * lifetime + Offset + parent.Origin;
break;
case ParticleType.Implode:
part.Pos.Frame.Origin = ((float)Math.Cos(A.X * lifetime) * C) + (lifetime * lifetime * B) + parent.Origin + Offset;
break;
}

var interval = Math.Min(Lifetime / Lifespan, 1.0f);

var currentScale = StartScale + (FinalScale - StartScale) * interval;
var currentTrans = StartTrans + (FinalTrans - StartTrans) * interval;

part.GfxObjScale = new Vector3((float)currentScale);
part.SetTranslucency((float)currentTrans);
}``````

19 View Source File : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void Method2_AppendingDataValues()
{
var scatterData = new XyDataSeries<double, double>();
var lineData = new XyDataSeries<double, double>();
// Ensure that DataSeries are named for the legend
scatterData.SeriesName = "Cos(x)";
lineData.SeriesName = "Sin(x)";
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
// Start a timer to update our data
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// This time we will append, not update.
{
int i = lineData.Count;
// Append a new data point;
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
// ZoomExtents after appending data.
// Also see XAxis.AutoRange, and XAxis.VisibleRange for more options
sciChartSurface.ZoomExtents();
}
};
timer.Start();
}``````

19 View Source File : RealtimeFifoChartView.xaml.cs
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
{
// 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 : Particle.cs
Project Creator : ACEmulator

``````public bool Init(ParticleEmitterInfo info, PhysicsObj parent, int partIdx, AFrame pFrame, PhysicsPart part, Vector3 _offset, bool persistent, Vector3 a, Vector3 b, Vector3 c)
{
var currentTime = PhysicsTimer.CurrentTime;

LastUpdateTime = currentTime;
Birthtime = currentTime;

Lifespan = info.GetRandomLifespan();

if (partIdx == -1)
StartFrame = new AFrame(parent.Position.Frame);
else
StartFrame = new AFrame(parent.PartArray.Parts[partIdx].Pos.Frame);

Offset = StartFrame.LocalToGlobalVec(pFrame.Origin + _offset);

switch (info.ParticleType)
{
case ParticleType.Still:
break;
case ParticleType.LocalVelocity:
A = StartFrame.LocalToGlobalVec(a);
break;
case ParticleType.ParabolicLVGA:
A = StartFrame.LocalToGlobalVec(a);
B = b.Copy();
break;
case ParticleType.ParabolicLVGAGR:
case ParticleType.Swarm:
A = StartFrame.LocalToGlobalVec(a);
B = b.Copy();
C = c.Copy();
break;
case ParticleType.Explode:
A = a.Copy();
B = b.Copy();

var ra = Common.Random.RollDice(-(float)Math.PI, (float)Math.PI);
var po = Common.Random.RollDice(-(float)Math.PI, (float)Math.PI);
var rb = Math.Cos(po);

C.X = (float)(Math.Cos(ra) * c.X * rb);
C.Y = (float)(Math.Sin(ra) * c.Y * rb);
C.Z = (float)(Math.Sin(po) * c.Z * rb);

if (Vec.NormalizeCheckSmall(ref C))
C = Vector3.Zero;

break;
case ParticleType.Implode:
A = a.Copy();
B = b.Copy();
Offset *= c;
C = Offset;
break;
case ParticleType.ParabolicLVLA:
A = StartFrame.LocalToGlobalVec(a);
B = StartFrame.LocalToGlobalVec(b);
break;
case ParticleType.ParabolicLVLALR:
C = StartFrame.LocalToGlobalVec(c);
break;
case ParticleType.ParabolicGVGA:
B = b.Copy();
break;
case ParticleType.ParabolicGVGAGR:
C = c.Copy();
break;
case ParticleType.GlobalVelocity:
A = a.Copy();
break;
default:
A = a.Copy();
B = b.Copy();
C = c.Copy();
break;
}

StartScale = info.StartScale;
FinalScale = info.FinalScale;
StartTrans = info.StartTrans;
FinalTrans = info.FinalTrans;

part.GfxObjScale = new Vector3(StartScale, StartScale, StartScale);
part.SetTranslucency(StartTrans);

Update(info.ParticleType, persistent, part, StartFrame);

return false;
}``````

19 View Source File : AccelCalculator.cs
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 : MatrixHelper.cs

``````public static Matrix Rotation(double radians)
{
return new Matrix(cos, sin, -sin, cos, 0, 0);
}``````

19 View Source File : MainWindow.xaml.cs
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)
};

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

var grayMaterial = new DiffuseMaterial(Brushes.Gray);
var goldMaterial = new MaterialGroup();

// Create spheres on top of boxes that are organized in a circle
for (int a = 0; a < 360; a += 36)
{

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),
Material = goldMaterial
};

}

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

// 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;

// 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
};

_viewport3D.Children.Clear();
}``````

19 View Source File : Position.cs
Project Creator : ACEmulator

``````public Position InFrontOf(double distanceInFront, bool rotate180 = false)
{
float qw = RotationW; // north
float qz = RotationZ; // south

double x = 2 * qw * qz;
double y = 1 - 2 * qz * qz;

var dx = -1 * Convert.ToSingle(Math.Sin(heading) * distanceInFront);
var dy = Convert.ToSingle(Math.Cos(heading) * distanceInFront);

// move the Z slightly up and let gravity pull it down.  just makes things easier.
var bumpHeight = 0.05f;
if (rotate180)
{
var rotate = new Quaternion(0, 0, qz, qw) * Quaternion.CreateFromYawPitchRoll(0, 0, (float)Math.PI);
return new Position(LandblockId.Raw, PositionX + dx, PositionY + dy, PositionZ + bumpHeight, 0f, 0f, rotate.Z, rotate.W);
}
else
return new Position(LandblockId.Raw, PositionX + dx, PositionY + dy, PositionZ + bumpHeight, 0f, 0f, qz, qw);
}``````

19 View Source File : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void Method4_ScrollingAndAllowingZooming()
{
// Instantiate the ViewportManager here
double windowSize = 1000.0;
sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

// Create DataSeries with FifoCapacity
var scatterData = new XyDataSeries<double, double>() { SeriesName = "Cos(x)",  };
var lineData = new XyDataSeries<double, double>() { SeriesName = "Sin(x)",  };
// replacedign DataSeries to RenderableSeries
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
int i = 0;
// Start a timer to update our data
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// This time we will append, not update.
{
// Append a new data point;
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
i++;
}

};
timer.Start();
}``````

19 View Source File : SeriesTooltips3DChart.xaml.cs
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 : Trajectory.cs
Project Creator : ACEmulator

``````public static int SolveCubic(double c0, double c1, double c2, double c3, out double s0, out double s1, out double s2)
{
s0 = double.NaN;
s1 = double.NaN;
s2 = double.NaN;

int num;
double sub;
double A, B, C;
double sq_A, p, q;
double cb_p, D;

/* normal form: x^3 + Ax^2 + Bx + C = 0 */
A = c1 / c0;
B = c2 / c0;
C = c3 / c0;

/*  subsreplacedute x = y - A/3 to eliminate quadric term:  x^3 +px + q = 0 */
sq_A = A * A;
p = 1.0 / 3 * (-1.0 / 3 * sq_A + B);
q = 1.0 / 2 * (2.0 / 27 * A * sq_A - 1.0 / 3 * A * B + C);

/* use Cardano's formula */
cb_p = p * p * p;
D = q * q + cb_p;

if (IsZero(D))
{
if (IsZero(q)) /* one triple solution */
{
s0 = 0;
num = 1;
}
else /* one single and one double solution */
{
double u = Math.Pow(-q, 1.0 / 3.0);
s0 = 2 * u;
s1 = -u;
num = 2;
}
}
else if (D < 0) /* Casus irreducibilis: three real solutions */
{
double phi = 1.0 / 3 * Math.Acos(-q / Math.Sqrt(-cb_p));
double t = 2 * Math.Sqrt(-p);

s0 = t * Math.Cos(phi);
s1 = -t * Math.Cos(phi + Math.PI / 3);
s2 = -t * Math.Cos(phi - Math.PI / 3);
num = 3;
}
else /* one real solution */
{
double sqrt_D = Math.Sqrt(D);
double u = Math.Pow(sqrt_D - q, 1.0 / 3.0);
double v = -Math.Pow(sqrt_D + q, 1.0 / 3.0);

s0 = u + v;
num = 1;
}

/* resubsreplacedute */
sub = 1.0 / 3 * A;

if (num > 0) s0 -= sub;
if (num > 1) s1 -= sub;
if (num > 2) s2 -= sub;

return num;
}``````

19 View Source File : gps2bd.cs
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;
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 : Particle.cs
Project Creator : ACEmulator

``````public void Update(ParticleType particleType, bool persistent, PhysicsPart part, AFrame parent)
{
var currentTime = PhysicsTimer.CurrentTime;
var elapsedTime = currentTime - LastUpdateTime;

if (persistent)
{
LastUpdateTime = currentTime;
}
else

switch (particleType)
{
case ParticleType.Still:
part.Pos.Frame.Origin = parent.Origin + Offset;
break;
case ParticleType.LocalVelocity:
case ParticleType.GlobalVelocity:
part.Pos.Frame.Origin = (lifetime * A) + parent.Origin + Offset;
break;
case ParticleType.ParabolicLVGA:
case ParticleType.ParabolicLVLA:
case ParticleType.ParabolicGVGA:
part.Pos.Frame.Origin = (lifetime * lifetime * B / 2.0f) + (lifetime * A) + parent.Origin + Offset;
break;
case ParticleType.ParabolicLVGAGR:
case ParticleType.ParabolicLVLALR:
case ParticleType.ParabolicGVGAGR:
part.Pos.Frame = new AFrame(parent);
break;
case ParticleType.Swarm:
var swarm = (lifetime * A) + parent.Origin + Offset;
part.Pos.Frame.Origin.X = (float)Math.Cos(lifetime * B.X) * C.X + swarm.X;
part.Pos.Frame.Origin.Y = (float)Math.Sin(lifetime * B.Y) * C.Y + swarm.Y;
part.Pos.Frame.Origin.Z = (float)Math.Cos(lifetime * B.Z) * C.Z + swarm.Z;
break;
case ParticleType.Explode:
part.Pos.Frame.Origin = (lifetime * B + C * A.X) * lifetime + Offset + parent.Origin;
break;
case ParticleType.Implode:
part.Pos.Frame.Origin = ((float)Math.Cos(A.X * lifetime) * C) + (lifetime * lifetime * B) + parent.Origin + Offset;
break;
}

var interval = Math.Min(Lifetime / Lifespan, 1.0f);

var currentScale = StartScale + (FinalScale - StartScale) * interval;
var currentTrans = StartTrans + (FinalTrans - StartTrans) * interval;

part.GfxObjScale = new Vector3((float)currentScale);
part.SetTranslucency((float)currentTrans);
}``````

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

``````public DoubleSeries GenerateSpiral(double xCentre, double yCentre, double maxRadius, int count)
{
var doubleSeries = new DoubleSeries();
double x, y;
for (int i = 0; i < count; i++)
{
double sinX = Math.Sin(2*Math.PI*i*0.05);
double cosX = Math.Cos(2*Math.PI*i*0.05);
x = xCentre + radius * sinX;
doubleSeries.Add(new XYPoint() { X = x, Y = y});
}
return doubleSeries;
}``````

19 View Source File : SolarAnalysisManager.cs
Project Creator : acnicholas

``````public static XYZ GetSunDirectionalVector(View view, ProjectPosition projectPosition, out double azimuth)
{
var frame = sunSettings.ActiveFrame;
azimuth = sunSettings.GetFrameAzimuth(frame);
var alreplacedude = sunSettings.GetFrameAlreplacedude(frame);
azimuth += projectPosition.Angle;
var forward = new XYZ(
-Math.Sin(azimuth),
-Math.Cos(azimuth),
-Math.Tan(alreplacedude - GetAtmosphericRefraction(alreplacedude)));
return forward;
}``````

19 View Source File : Arc.cs
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 : RotationMatrices.cs
Project Creator : ActuarialIntelligence

``````private static _3Matrix RotateZ(double z)
{
_3Vector r1 = new _3Vector(Math.Cos(-z), -Math.Sin(-z), 0),
r2 = new _3Vector(Math.Sin(-z), Math.Cos(-z), 0),
r3 = new _3Vector(0, 0, 1);

return new _3Matrix(r1, r2, r3);
}``````

19 View Source File : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
var scatterData = new XyDataSeries<double, double>();
var lineData = new XyDataSeries<double, double>();

// NEW CODE HERE
// Ensure that DataSeries are named for the legend
scatterData.SeriesName = "Cos(x)";
lineData.SeriesName = "Sin(x)";
// END NEW CODE
for (int i = 0; i < 1000; i++)
{
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
}
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
}``````

19 View Source File : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void Method1_UpdatingDataValues()
{
var scatterData = new XyDataSeries<double, double>();
var lineData = new XyDataSeries<double, double>();

// Ensure that DataSeries are named for the legend
scatterData.SeriesName = "Cos(x)";
lineData.SeriesName = "Sin(x)";
for (int i = 0; i < 1000; i++)
{
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
}
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
// Start a timer to update our data
double phase = 0.0;
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// SuspendUpdates() ensures the chart is frozen
// while you do updates. This ensures best performance
{
for (int i = 0; i < 1000; i++)
{
// Updates the Y value at index i
lineData.Update(i, Math.Sin(i * 0.1 + phase));
scatterData.Update(i, Math.Cos(i * 0.1 + phase));
}
}
phase += 0.01;
};
timer.Start();
}``````

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

``````private void Method3_FifoScrollingUpdates()
{
// Create DataSeries with FifoCapacity
var scatterData = new XyDataSeries<double, double>() { SeriesName = "Cos(x)", FifoCapacity = 1000 };
var lineData = new XyDataSeries<double, double>() { SeriesName = "Sin(x)", FifoCapacity = 1000 };
// replacedign DataSeries to RenderableSeries
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
int i = 0;
// Start a timer to update our data
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// This time we will append, not update.
{
// Append a new data point;
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
// Set VisibleRange to last 1,000 points
sciChartSurface.XAxis.VisibleRange = new DoubleRange(i - 1000, i);
i++;
}

};
timer.Start();
}``````

19 View Source File : CircularProgressBar.xaml.cs
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 : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Instantiate the ViewportManager here
double windowSize = 1000.0;
sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

// Create DataSeries with FifoCapacity
var scatterData = new XyDataSeries<double, double>() { SeriesName = "Cos(x)",  };
var lineData = new XyDataSeries<double, double>() { SeriesName = "Sin(x)",  };
// replacedign DataSeries to RenderableSeries
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
mountainSeries.DataSeries = scatterData; // <-- NEW CODE HERE!
int i = 0;
// Start a timer to update our data
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// This time we will append, not update.
{
// Append a new data point;
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
// Every 100th datapoint, add an annotation
if (i % 100 == 0)
{
{
X1 = i,
Y1 = 0.0,
YAxisId = i % 200 == 0 ? AxisBase.DefaultAxisId : "Axis2"
});
// Optional: Don't forget to remove annotations which are out of range!
sciChartSurface.Annotations.RemoveWhere(x => x.X1.ToDouble() < i - 1000);
}
i++;
}

};
timer.Start();
}``````

19 View Source File : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Instantiate the ViewportManager here
double windowSize = 1000.0;
sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

// Create DataSeries with FifoCapacity
var scatterData = new XyDataSeries<double, double>() { SeriesName = "Cos(x)",  };
var lineData = new XyDataSeries<double, double>() { SeriesName = "Sin(x)",  };
// replacedign DataSeries to RenderableSeries
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
int i = 0;
// Start a timer to update our data
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// This time we will append, not update.
{
// Append a new data point;
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
// Every 100th datapoint, add an annotation
if (i % 100 == 0)
{
sciChartSurface.Annotations.Add(new InfoAnnotation() { X1 = i, Y1 = 0.0 });
// Optional: Don't forget to remove annotations which are out of range!
sciChartSurface.Annotations.RemoveWhere(x => x.X1.ToDouble() < i - 1000);
}
i++;
}

};
timer.Start();
}``````

19 View Source File : SeriesTooltips3DChart.xaml.cs
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);
}``````

19 View Source File : Particle.cs
Project Creator : ACEmulator

``````public bool Init(ParticleEmitterInfo info, PhysicsObj parent, int partIdx, AFrame pFrame, PhysicsPart part, Vector3 _offset, bool persistent, Vector3 a, Vector3 b, Vector3 c)
{
var currentTime = PhysicsTimer.CurrentTime;

LastUpdateTime = currentTime;
Birthtime = currentTime;

Lifespan = info.GetRandomLifespan();

if (partIdx == -1)
StartFrame = new AFrame(parent.Position.Frame);
else
StartFrame = new AFrame(parent.PartArray.Parts[partIdx].Pos.Frame);

Offset = StartFrame.LocalToGlobalVec(pFrame.Origin + _offset);

switch (info.ParticleType)
{
case ParticleType.Still:
break;
case ParticleType.LocalVelocity:
A = StartFrame.LocalToGlobalVec(a);
break;
case ParticleType.ParabolicLVGA:
B = StartFrame.LocalToGlobalVec(b);
break;
case ParticleType.ParabolicLVGAGR:
C = StartFrame.LocalToGlobalVec(c);
break;
case ParticleType.Swarm:
A = StartFrame.LocalToGlobalVec(a);
B = b;
C = c;
break;
case ParticleType.Explode:
A = a;
B = b;

var rb = Math.Cos(po);

C.X = (float)(Math.Cos(ra) * c.X * rb);
C.Y = (float)(Math.Sin(ra) * c.Y * rb);
C.Z = (float)(Math.Sin(po) * c.Z * rb);

if (Vec.NormalizeCheckSmall(ref C))
C = Vector3.Zero;

break;
case ParticleType.Implode:
A = a;
B = b;
Offset *= c;
C = Offset;
break;
case ParticleType.ParabolicLVLA:
A = StartFrame.LocalToGlobalVec(a);
B = StartFrame.LocalToGlobalVec(b);
break;
case ParticleType.ParabolicLVLALR:
C = StartFrame.LocalToGlobalVec(c);
break;
case ParticleType.ParabolicGVGA:
B = b;
break;
case ParticleType.ParabolicGVGAGR:
C = c;
break;
case ParticleType.GlobalVelocity:
A = a;
break;
default:
A = a;
B = b;
C = c;
break;
}

StartScale = info.StartScale;
FinalScale = info.FinalScale;
StartTrans = info.StartTrans;
FinalTrans = info.FinalTrans;

part.GfxObjScale = new Vector3(StartScale, StartScale, StartScale);
part.SetTranslucency(StartTrans);

Update(info.ParticleType, persistent, part, pFrame);

return false;
}``````

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

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

19 View Source File : AFrame.cs
Project Creator : ACEmulator

``````public void set_heading(float degrees)
{

var matrix = Matrix4x4.CreateFromQuaternion(Orientation);

}``````

19 View Source File : RealTimeCursors.xaml.cs
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
{
// 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 : Trajectory.cs
Project Creator : ACEmulator

``````public static int solve_ballistic_arc(Vector3 proj_pos, float proj_speed, Vector3 target, float gravity, out Vector3 s0, out Vector3 s1, out float t0, out float t1)
{
// Handling these cases is up to your project's coding standards
//Debug.replacedert(proj_pos != target && proj_speed > 0 && gravity > 0, "fts.solve_ballistic_arc called with invalid data");

// C# requires out variables be set
s0 = Vector3.Zero;
s1 = Vector3.Zero;
t0 = float.PositiveInfinity;
t1 = float.PositiveInfinity;

if (proj_pos == target || proj_speed <= 0 || gravity <= 0)
return 0;

// Derivation
//   (1) x = v*t*cos O
//   (2) z = v*t*sin O - .5*g*t^2
//
//   (3) t = x/(cos O*v)                                        [solve t from (1)]
//   (4) z = v*x*sin O/(cos O * v) - .5*g*x^2/(cos^2 O*v^2)     [plug t into z=...]
//   (5) z = x*tan O - g*x^2/(2*v^2*cos^2 O)                    [reduce; cos/sin = tan]
//   (6) z = x*tan O - (g*x^2/(2*v^2))*(1+tan^2 O)              [reduce; 1+tan O = 1/cos^2 O]
//   (7) 0 = ((-g*x^2)/(2*v^2))*tan^2 O + x*tan O - (g*x^2)/(2*v^2) - z    [re-arrange]
//   Quadratic! a*p^2 + b*p + c where p = tan O
//
//   (8) let gxv = -g*x*x/(2*v*v)
//   (9) p = (-x +- sqrt(x*x - 4gxv*(gxv - z)))/2*gxv           [quadratic formula]
//   (10) p = (v^2 +- sqrt(v^4 - g(g*x^2 + 2*z*v^2)))/gx        [multiply top/bottom by -2*v*v/x; move 4*v^4/x^2 into root]
//   (11) O = atan(p)

Vector3 diff = target - proj_pos;
Vector3 diffXY = new Vector3(diff.X, diff.Y, 0);
float groundDist = diffXY.Length();

float speed2 = proj_speed * proj_speed;
float speed4 = proj_speed * proj_speed * proj_speed * proj_speed;
float z = diff.Z;
float x = groundDist;
float gx = gravity * x;

float root = speed4 - gravity * (gravity * x * x + 2 * z * speed2);

// No solution
if (root < 0)
return 0;

root = (float)Math.Sqrt(root);

var lowAng = Math.Atan2(speed2 - root, gx);
var highAng = Math.Atan2(speed2 + root, gx);
int numSolutions = lowAng != highAng ? 2 : 1;

Vector3 groundDir = Vector3.Normalize(diffXY);
s0 = groundDir * (float)Math.Cos(lowAng) * proj_speed + Vector3.UnitZ * (float)Math.Sin(lowAng) * proj_speed;
if (numSolutions > 1)
s1 = groundDir * (float)Math.Cos(highAng) * proj_speed + Vector3.UnitZ * (float)Math.Sin(highAng) * proj_speed;

t0 = x / ((float)Math.Cos(lowAng) * proj_speed);
t1 = x / ((float)Math.Cos(highAng) * proj_speed);

return numSolutions;
}``````

19 View Source File : leastsquares.cs
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 : Trajectory.cs
Project Creator : ACEmulator

``````public static float ballistic_range(float speed, float gravity, float initial_height)
{
// Handling these cases is up to your project's coding standards
Debug.replacedert(speed > 0 && gravity > 0 && initial_height >= 0, "fts.ballistic_range called with invalid data");

// Derivation
//   (1) x = speed * time * cos O
//   (2) z = initial_height + (speed * time * sin O) - (.5 * gravity*time*time)
//   (3) via quadratic: t = (speed*sin O)/gravity + sqrt(speed*speed*sin O + 2*gravity*initial_height)/gravity    [ignore smaller root]
//   (4) solution: range = x = (speed*cos O)/gravity * sqrt(speed*speed*sin O + 2*gravity*initial_height)    [plug t back into x=speed*time*cos O]
var angle = 45 * 0.0174533; // no air resistence, so 45 degrees provides maximum range
var cos = Math.Cos(angle);
var sin = Math.Sin(angle);

var range = (speed * cos / gravity) * (speed * sin + Math.Sqrt(speed * speed * sin * sin + 2 * gravity * initial_height));
return (float)range;
}``````

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

``````public DoubleSeries GetButterflyCurve(int count=2000)
{
// From http://en.wikipedia.org/wiki/Butterfly_curve_%28transcendental%29
// x = sin(t) * (e^cos(t) - 2cos(4t) - sin^5(t/12))
// y = cos(t) * (e^cos(t) - 2cos(4t) - sin^5(t/12))
var temp = 0.01;
var doubleSeries = new DoubleSeries(count);
for (int i = 0; i < count; i++)
{
var t = i*temp;

double multiplier = Math.Pow(Math.E, Math.Cos(t)) - 2*Math.Cos(4*t) - Math.Pow(Math.Sin(t/12), 5);

double x = Math.Sin(t)*multiplier;
double y = Math.Cos(t) * multiplier;
doubleSeries.Add(new XYPoint {X = x, Y = y});
}
return doubleSeries;
}``````

19 View Source File : Trajectory.cs
Project Creator : ACEmulator

``````public static int solve_ballistic_arc(Vector3 proj_pos, float proj_speed, Vector3 target, float gravity, out Vector3 s0, out Vector3 s1, out float t0, out float t1)
{

// Handling these cases is up to your project's coding standards
Debug.replacedert(proj_pos != target && proj_speed > 0 && gravity > 0, "fts.solve_ballistic_arc called with invalid data");

// C# requires out variables be set
s0 = Vector3.Zero;
s1 = Vector3.Zero;
t0 = float.PositiveInfinity;
t1 = float.PositiveInfinity;

// Derivation
//   (1) x = v*t*cos O
//   (2) z = v*t*sin O - .5*g*t^2
//
//   (3) t = x/(cos O*v)                                        [solve t from (1)]
//   (4) z = v*x*sin O/(cos O * v) - .5*g*x^2/(cos^2 O*v^2)     [plug t into z=...]
//   (5) z = x*tan O - g*x^2/(2*v^2*cos^2 O)                    [reduce; cos/sin = tan]
//   (6) z = x*tan O - (g*x^2/(2*v^2))*(1+tan^2 O)              [reduce; 1+tan O = 1/cos^2 O]
//   (7) 0 = ((-g*x^2)/(2*v^2))*tan^2 O + x*tan O - (g*x^2)/(2*v^2) - z    [re-arrange]
//   Quadratic! a*p^2 + b*p + c where p = tan O
//
//   (8) let gxv = -g*x*x/(2*v*v)
//   (9) p = (-x +- sqrt(x*x - 4gxv*(gxv - z)))/2*gxv           [quadratic formula]
//   (10) p = (v^2 +- sqrt(v^4 - g(g*x^2 + 2*z*v^2)))/gx        [multiply top/bottom by -2*v*v/x; move 4*v^4/x^2 into root]
//   (11) O = atan(p)

Vector3 diff = target - proj_pos;
Vector3 diffXY = new Vector3(diff.X, diff.Y, 0);
float groundDist = diffXY.Length();

float speed2 = proj_speed * proj_speed;
float speed4 = proj_speed * proj_speed * proj_speed * proj_speed;
float z = diff.Z;
float x = groundDist;
float gx = gravity * x;

float root = speed4 - gravity * (gravity * x * x + 2 * z * speed2);

// No solution
if (root < 0)
return 0;

root = (float)Math.Sqrt(root);

var lowAng = Math.Atan2(speed2 - root, gx);
var highAng = Math.Atan2(speed2 + root, gx);
int numSolutions = lowAng != highAng ? 2 : 1;

Vector3 groundDir = diffXY.Normalize();
s0 = groundDir * (float)Math.Cos(lowAng) * proj_speed + Vector3.UnitZ * (float)Math.Sin(lowAng) * proj_speed;
if (numSolutions > 1)
s1 = groundDir * (float)Math.Cos(highAng) * proj_speed + Vector3.UnitZ * (float)Math.Sin(highAng) * proj_speed;

t0 = x / ((float)Math.Cos(lowAng) * proj_speed);
t1 = x / ((float)Math.Cos(highAng) * proj_speed);

return numSolutions;
}``````

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

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

19 View Source File : PlaceCoordinate.cs
Project Creator : acnicholas

``````private static XYZ ToMGA(ProjectPosition projectPosition, double x, double y, double z, bool useSurveyCoords)
{
if (!useSurveyCoords) {
return new XYZ(x / FeetToInches, y / FeetToInches, z / FeetToInches);
}

double xp, yp;
double ang = projectPosition.Angle;
double nx, ny;
xp = (x / FeetToInches) - projectPosition.EastWest;
yp = (y / FeetToInches) - projectPosition.NorthSouth;
nx = (xp * Math.Cos(-ang)) - (yp * Math.Sin(-ang));
ny = (xp * Math.Sin(-ang)) + (yp * Math.Cos(-ang));
return new XYZ(nx, ny, (-projectPosition.Elevation + z) / FeetToInches);
}``````

19 View Source File : FFT.cs
Project Creator : ABTSoftware

``````public void run(
double[] xRe,
double[] xIm,
bool inverse = false)
{
uint numFlies = m_N >> 1;	// Number of butterflies per sub-FFT
uint span = m_N >> 1;		// Width of the butterfly
uint spacing = m_N;			// Distance between start of sub-FFTs
uint wIndexStep = 3; 		// Increment for twiddle table index

// Copy data into linked complex number objects
// If it's an IFFT, we divide by N while we're at it
FFTElement x = m_X[0];
uint k = 0;
double scale = inverse ? 1.0 / m_N : 1.0;
while (x != null)
{
x.re = scale * xRe[k];
x.im = scale * xIm[k];
x = x.next;
k++;
}

// For each stage of the FFT
for (uint stage = 0; stage < m_logN; stage++)
{
// Compute a multiplier factor for the "twiddle factors".
// The twiddle factors are complex unit vectors spaced at
// regular angular intervals. The angle by which the twiddle
// factor advances depends on the FFT stage. In many FFT
// implementations the twiddle factors are cached, but because
// array lookup is relatively slow in C#, it's just
// as fast to compute them on the fly.
double wAngleInc = wIndexStep * 2.0 * Math.PI / m_N;
if (inverse == false)
wAngleInc *= -1;
double wMulRe = Math.Cos(wAngleInc);
double wMulIm = Math.Sin(wAngleInc);

for (uint start = 0; start < m_N; start += spacing)
{
FFTElement xTop = m_X[start];
FFTElement xBot = m_X[start + span];

double wRe = 1.0;
double wIm = 0.0;

// For each butterfly in this stage
for (uint flyCount = 0; flyCount < numFlies; ++flyCount)
{
// Get the top & bottom values
double xTopRe = xTop.re;
double xTopIm = xTop.im;
double xBotRe = xBot.re;
double xBotIm = xBot.im;

// Top branch of butterfly has addition
xTop.re = xTopRe + xBotRe;
xTop.im = xTopIm + xBotIm;

// Bottom branch of butterly has subtraction,
// followed by multiplication by twiddle factor
xBotRe = xTopRe - xBotRe;
xBotIm = xTopIm - xBotIm;
xBot.re = xBotRe * wRe - xBotIm * wIm;
xBot.im = xBotRe * wIm + xBotIm * wRe;

// Advance butterfly to next top & bottom positions
xTop = xTop.next;
xBot = xBot.next;

// Update the twiddle factor, via complex multiply
// by unit vector with the appropriate angle
// (wRe + j wIm) = (wRe + j wIm) x (wMulRe + j wMulIm)
double tRe = wRe;
wRe = wRe * wMulRe - wIm * wMulIm;
wIm = tRe * wMulIm + wIm * wMulRe;
}
}

numFlies >>= 1; 	// Divide by 2 by right shift
span >>= 1;
spacing >>= 1;
wIndexStep <<= 1;  	// Multiply by 2 by left shift
}

// The algorithm leaves the result in a scrambled order.
// Unscramble while copying values from the complex
// linked list elements back to the input/output vectors.
x = m_X[0];
while (x != null)
{
uint target = x.revTgt;
xRe[target] = x.re;
xIm[target] = x.im;
x = x.next;
}
}``````

19 View Source File : SolarAnalysisManager.cs
Project Creator : acnicholas

``````private bool RotateView(View view)
{
if (view.ViewType == ViewType.ThreeD) {
var forward = GetSunDirectionalVector(view, position, out var azimuth);
var up = forward.CrossProduct(new XYZ(Math.Cos(azimuth), -Math.Sin(azimuth), 0));

var v3d = (View3D)view;
if (v3d.IsLocked) {
return false;
}

using (var t = new Transaction(doc))
{
t.Start("Rotate View");
v3d.SetOrientation(new ViewOrientation3D(GetEyeLocation(view), up, forward));
if (v3d.CanBeLocked() && !v3d.Name.StartsWith("{", StringComparison.OrdinalIgnoreCase)) {
try {
v3d.SaveOrientationAndLock();
} catch (InvalidOperationException e) {
Debug.WriteLine(e.Message);
return false;
}
}

udoc.RefreshActiveView();
t.Commit();
}
}
else
{
return false;
}
return true;
}``````

19 View Source File : DefaultCaptchaImageGenerator.cs
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 : RotationMatrices.cs
Project Creator : ActuarialIntelligence

``````private static _3Matrix RotateY(double y)
{
_3Vector r1 = new _3Vector(Math.Cos(-y), 0, Math.Sin(-y)),
r2 = new _3Vector(0, 1, 0),
r3 = new _3Vector(-Math.Sin(-y), 0, Math.Cos(-y));

return new _3Matrix(r1, r2, r3);
}``````

19 View Source File : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Create XyDataSeries to host data for our charts
var scatterData = new XyDataSeries<double, double>();
var lineData = new XyDataSeries<double, double>();

for (int i = 0; i < 1000; i++)
{
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
}
// replacedign dataseries to RenderSeries
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
}``````

19 View Source File : OculusDemoForm.cs
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)
};

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

var grayMaterial = new DiffuseMaterial(Brushes.Gray);
var goldMaterial = new MaterialGroup();

// Create spheres on top of boxes that are organized in a circle
for (int a = 0; a < 360; a += 36)
{

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),
Material = goldMaterial
};

}

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

// 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;

// 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
};

_mainViewport3D.Children.Clear();
}``````

19 View Source File : GhostEmoteWheel.cs

``````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;
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(
);

// 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)

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 : rotations.cs
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 : gps2bd.cs
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 : CreateAPointLine3DChart.xaml.cs
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 : MainWindow.xaml.cs
Project Creator : ABTSoftware

``````private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Instantiate the ViewportManager here
double windowSize = 1000.0;
sciChartSurface.ViewportManager = new ScrollingViewportManager(windowSize);

// Create DataSeries with FifoCapacity
var scatterData = new XyDataSeries<double, double>() { SeriesName = "Cos(x)",  };
var lineData = new XyDataSeries<double, double>() { SeriesName = "Sin(x)",  };
// replacedign DataSeries to RenderableSeries
LineSeries.DataSeries = lineData;
ScatterSeries.DataSeries = scatterData;
int i = 0;
// Start a timer to update our data
var timer = new DispatcherTimer(DispatcherPriority.Render);
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Tick += (s, e) =>
{
// This time we will append, not update.
{
// Append a new data point;
lineData.Append(i, Math.Sin(i * 0.1));
scatterData.Append(i, Math.Cos(i * 0.1));
// Every 100th datapoint, add an annotation
if (i % 100 == 0)
{
{
X1 = i,
Y1 = 0.0,
YAxisId = i % 200 == 0 ? AxisBase.DefaultAxisId : "Axis2"
});
// Optional: Don't forget to remove annotations which are out of range!
sciChartSurface.Annotations.RemoveWhere(x => x.X1.ToDouble() < i - 1000);
}
i++;
}

};
timer.Start();
}``````

See More Examples