BuildCoefficientsForLevels(int levels) { if (_realCoefficients[levels, 0] != null) { return; } int m = 1; for (int level = 1; level <= levels; level++, m <<= 1) { if (_realCoefficients[level, 0] != null) { continue; } double uRealFw = 1; double uRealBw = 1; double uImagFw = 0; double uImagBw = 0; double angle = Constants.Pi / m; double wRreal = Trig.Cosine(angle); double wImag = Trig.Sine(angle); double[] realForward = new double[m]; double[] imagForward = new double[m]; double[] realBackward = new double[m]; double[] imagBackward = new double[m]; for (int i = 0; i < m; i++) { realForward[i] = uRealFw; imagForward[i] = uImagFw; realBackward[i] = uRealBw; imagBackward[i] = uImagBw; double uwI = (uImagFw * wRreal) - (uRealFw * wImag); uRealFw = (uRealFw * wRreal) + (uImagFw * wImag); uImagFw = uwI; uwI = (uImagBw * wRreal) + (uRealBw * wImag); uRealBw = (uRealBw * wRreal) - (uImagBw * wImag); uImagBw = uwI; } _realCoefficients[level, 0] = realForward; _imagCoefficients[level, 0] = imagForward; _realCoefficients[level, 1] = realBackward; _imagCoefficients[level, 1] = imagBackward; } }
public void WeaponReady(Player player, PlayerSpriteDef psp) { var pb = this.world.PlayerBehavior; // Get out of attack state. if (player.Mobj.State == DoomInfo.States[(int)MobjState.PlayAtk1] || player.Mobj.State == DoomInfo.States[(int)MobjState.PlayAtk2]) { player.Mobj.SetState(MobjState.Play); } if (player.ReadyWeapon.Info is WeaponChainsaw && psp.State == DoomInfo.States[(int)MobjState.Saw]) { this.world.StartSound(player.Mobj, Sfx.SAWIDL, SfxType.Weapon); } // Check for weapon change. // If player is dead, put the weapon away. if (player.PendingWeapon != null || player.Health == 0) { // Change weapon. // Pending weapon should allready be validated. var newState = player.ReadyWeapon.GetComponent <WeaponComponent>().Info.DownState; pb.SetPlayerSprite(player, PlayerSprite.Weapon, newState); return; } // Check for fire. // The missile launcher and bfg do not auto fire. if ((player.Cmd.Buttons & TicCmdButtons.Attack) != 0) { if (!player.AttackDown || (!(player.ReadyWeapon.Info is WeaponRocketLauncher) && !(player.ReadyWeapon.Info is WeaponBfg))) { player.AttackDown = true; this.FireWeapon(player); return; } } else { player.AttackDown = false; } // Bob the weapon based on movement speed. var angle = (128 * player.Mobj.World.LevelTime) & Trig.FineMask; psp.Sx = Fixed.One + player.Bob * Trig.Cos(angle); angle &= Trig.FineAngleCount / 2 - 1; psp.Sy = WeaponBehavior.WeaponTop + player.Bob * Trig.Sin(angle); }
TransformBackward( double[] fftReal, double[] fftImag, out double[] samples) { if (fftReal.Length != fftImag.Length) { throw new ArgumentException(Properties.LocalStrings.ArgumentVectorsSameLengths); } if (Fn.CeilingToPowerOf2(fftReal.Length) != fftReal.Length) { throw new ArgumentException(Properties.LocalStrings.ArgumentPowerOfTwo, "samples"); } int length = fftReal.Length; int numSamples = length >> 1; double expSignConvention = (_convention & TransformationConvention.InverseExponent) > 0 ? -1d : 1d; double theta = -Constants.Pi / numSamples; double wtemp = Trig.Sine(0.5 * theta); double wpr = -2.0 * wtemp * wtemp; double wpi = expSignConvention * Trig.Sine(theta); double wr = 1.0 + wpr; double wi = wpi; samples = new double[length]; // TODO: may be 1 <--> 0 swapped? samples[1] = 0.5 * (fftReal[0] - fftReal[numSamples]); samples[0] = 0.5 * (fftReal[0] + fftReal[numSamples]); for (int i = 1, j = 2; j <= numSamples; i++, j += 2) { double h1Real = 0.5 * (fftReal[i] + fftReal[numSamples - i]); double h1Imag = 0.5 * (fftImag[i] - fftImag[numSamples - i]); double h2Real = -0.5 * (fftImag[i] + fftImag[numSamples - i]); double h2Imag = 0.5 * (fftReal[i] - fftReal[numSamples - i]); samples[j] = h1Real + (wr * h2Real) + (wi * h2Imag); samples[j + 1] = h1Imag + (wr * h2Imag) - (wi * h2Real); samples[length - j] = h1Real - (wr * h2Real) - (wi * h2Imag); samples[length + 1 - j] = -h1Imag + (wr * h2Imag) - (wi * h2Real); wr = ((wtemp = wr) * wpr) - (wi * wpi) + wr; wi = (wi * wpr) + (wtemp * wpi) + wi; } /* Transform odd and even vectors (packed as one complex vector) */ _fft.DiscreteFourierTransform(samples, false, _convention); }
[Test] public void ToRadians() { Assert.IsTrue(Compare.AlmostEqual(0.0174533, Trig.ToRadians(1))); Assert.IsTrue(Compare.AlmostEqual(0.575959, Trig.ToRadians(33))); Assert.IsTrue(Compare.AlmostEqual(1.29154, Trig.ToRadians(74))); Assert.IsTrue(Compare.AlmostEqual(1.55334, Trig.ToRadians(89))); Assert.IsTrue(Compare.AlmostEqual(1.5708, Trig.ToRadians(90))); Assert.IsTrue(Compare.AlmostEqual(1.58825, Trig.ToRadians(91))); Assert.IsTrue(Compare.AlmostEqual(2.14675, Trig.ToRadians(123))); Assert.IsTrue(Compare.AlmostEqual(3.45575, Trig.ToRadians(198))); Assert.IsTrue(Compare.AlmostEqual(4.45059, Trig.ToRadians(255))); Assert.IsTrue(Compare.AlmostEqual(5.46288, Trig.ToRadians(313))); }
[Test] public void ToDegrees() { Assert.IsTrue(Compare.AlmostEqual(1f, Trig.ToDegrees(0.0174533), 1e5)); Assert.IsTrue(Compare.AlmostEqual(33f, Trig.ToDegrees(0.575959), 1e5)); Assert.IsTrue(Compare.AlmostEqual(74f, Trig.ToDegrees(1.29154), 1e5)); Assert.IsTrue(Compare.AlmostEqual(89f, Trig.ToDegrees(1.55334), 1e5)); Assert.IsTrue(Compare.AlmostEqual(90f, Trig.ToDegrees(1.5708), 1e5)); Assert.IsTrue(Compare.AlmostEqual(91f, Trig.ToDegrees(1.58825), 1e5)); Assert.IsTrue(Compare.AlmostEqual(123f, Trig.ToDegrees(2.14675), 1e5)); Assert.IsTrue(Compare.AlmostEqual(198f, Trig.ToDegrees(3.45575), 1e5)); Assert.IsTrue(Compare.AlmostEqual(255f, Trig.ToDegrees(4.45059), 1e5)); Assert.IsTrue(Compare.AlmostEqual(313f, Trig.ToDegrees(5.46288), 1e5)); }
private Vector3 CreateVectorBelowLast() { var z = -1.0 + (1 + _maxZ) * _random.NextDouble(); _maxZ = z; var azimuth = 2 * Constants.Pi * _random.NextDouble(); var x = Math.Sqrt(1 - z * z) * Trig.Cosine(azimuth); var y = Math.Sqrt(1 - z * z) * Trig.Sine(azimuth); return(new Vector3(x, y, z)); }
/// <summary> /// Evaluates complex rotation coefficients if not already available. /// </summary> private void BuildCoefficientsForLevels(int levels) { if (realCoefficients[levels, 0] != null) { return; } int M = 1; double uRealFw, uImagFw, uRealBw, uImagBw, angle, wRreal, wImag, uwI; for (int level = 1; level <= levels; level++, M <<= 1) { if (realCoefficients[level, 0] != null) { continue; } uRealFw = uRealBw = 1; uImagFw = uImagBw = 0; angle = Constants.Pi / M; wRreal = Trig.Cosine(angle); wImag = Trig.Sine(angle); double[] realForward = new double[M]; double[] imagForward = new double[M]; double[] realBackward = new double[M]; double[] imagBackward = new double[M]; for (int i = 0; i < M; i++) { realForward[i] = uRealFw; imagForward[i] = uImagFw; realBackward[i] = uRealBw; imagBackward[i] = uImagBw; uwI = uImagFw * wRreal - uRealFw * wImag; uRealFw = uRealFw * wRreal + uImagFw * wImag; uImagFw = uwI; uwI = uImagBw * wRreal + uRealBw * wImag; uRealBw = uRealBw * wRreal - uImagBw * wImag; uImagBw = uwI; } realCoefficients[level, 0] = realForward; imagCoefficients[level, 0] = imagForward; realCoefficients[level, 1] = realBackward; imagCoefficients[level, 1] = imagBackward; } }
/// <summary> /// Creates a new instance of our receiving phone /// with default configuration and graphics. /// </summary> /// <returns>A new SimpleReceiver.</returns> private SimpleReceiver CreateReceivingPhone() { var earth = CentralBodiesFacet.GetFromContext().Earth; // Create a receiving phone with a gain of 100 and a noisefactor of 2 - adding 290 Kelvin worth of noise to the call. // Even though we are using a static location for our receiver, // it can easily be changed to a moving one by simply modifying the // LocationPoint to something else, for example a route generated // with the Route Design Library. double longitude = Trig.DegreesToRadians(77.5833); double latitude = Trig.DegreesToRadians(12.9833); var phone = new SimpleReceiver { Name = "Bangalore, India", LocationPoint = new PointCartographic(earth, new Cartographic(longitude, latitude, 0)), Gain = 100.0, NoiseFactor = 2.0, TargetFrequency = m_intendedSignal.TargetFrequency }; //Add a default marker phone.Extensions.Add(new MarkerGraphicsExtension(new MarkerGraphics { Texture = new ConstantGraphicsParameter <Texture2D>(m_phoneTexture) })); //Add a label based on the name and show just below the marker. var textGraphics = new TextGraphics { Color = new ConstantGraphicsParameter <Color>(Color.Yellow), Font = new ConstantGraphicsParameter <Font>(m_labelFont), Outline = new ConstantGraphicsParameter <bool>(true), OutlineColor = new ConstantGraphicsParameter <Color>(Color.Black), Text = new ConstantGraphicsParameter <string>(phone.Name), Origin = new ConstantGraphicsParameter <Origin>(Origin.TopCenter), PixelOffset = new ConstantGraphicsParameter <PointF>(new PointF(0, -m_phoneTexture.Template.Height / 2)), DisplayParameters = { MaximumDistance = new ConstantGraphicsParameter <double>(75000000.0) } }; if (TextureFilter2D.Supported(TextureWrap.ClampToEdge)) { textGraphics.TextureFilter = new ConstantGraphicsParameter <TextureFilter2D>(TextureFilter2D.NearestClampToEdge); } phone.Extensions.Add(new TextGraphicsExtension(textGraphics)); return(phone); }
/// <summary> /// Create a fan to visualize an azimuth-elevation mask. /// </summary> private void CreateAzimuthElevationMask() { // load terrain data for Mount St. Helens. string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath ?? "", "Data"); var terrain = new AGIProcessedDataTerrain(Path.Combine(dataPath, @"Terrain\StHelens.pdtt")); // Calculate the surface position at the center of the terrain double longitude = (terrain.BoundingExtent.WestLongitude + terrain.BoundingExtent.EastLongitude) / 2.0; double latitude = (terrain.BoundingExtent.NorthLatitude + terrain.BoundingExtent.SouthLatitude) / 2.0; Cartographic observerPosition = new Cartographic(longitude, latitude, terrain.GetHeight(longitude, latitude)); // Sample using 360 azimuth rays at 0.000275 degrees const int numberOfAzimuthSteps = 360; double stepSize = Trig.DegreesToRadians(0.000275); const double maxSearchAngle = 0.025; // Compute the mask. var mask = TerrainAzimuthElevationMask.Compute(terrain, observerPosition, numberOfAzimuthSteps, stepSize, maxSearchAngle); var locationPoint = new PointCartographic(m_earth, observerPosition); m_maskPlatform = new Platform { Name = "Azimuth Elevation Mask", LocationPoint = locationPoint, OrientationAxes = new AxesNorthEastDown(m_earth, locationPoint), }; // Set the identifier for the mask in the CZML document. m_maskPlatform.Extensions.Add(new IdentifierExtension("Mask")); // Attach the computed mask. m_maskPlatform.Extensions.Add(new AzimuthElevationMaskExtension(mask)); // Define the graphics of the mask. m_maskPlatform.Extensions.Add(new AzimuthElevationMaskGraphicsExtension(new AzimuthElevationMaskGraphics { ProjectionRange = 5000.0, Material = new StripeMaterialGraphics { EvenColor = Color.Blue, OddColor = Color.White, Repeat = 16.0, }, Projection = AzimuthElevationMaskGraphicsProjection.ProjectToRange, NumberOfRings = 8, Outline = true, OutlineColor = Color.Black, OutlineWidth = 2.0, })); }
/// <summary> /// Creates a new instance of our transmitting phone /// with default configuration and graphics. /// </summary> /// <returns>A new SimpleDigitalTransmitter.</returns> private SimpleDigitalTransmitter CreateTransmittingPhone() { var earth = CentralBodiesFacet.GetFromContext().Earth; // Create a new SimpleDigitalTransmitter and assign its basic properties. // Even though we are using a static location for our transmitter, // it can easily be changed to a moving one by simply modifying the // LocationPoint to something else, for example a route generated // with the Route Design Library. double longitude = Trig.DegreesToRadians(39.6333); double latitude = Trig.DegreesToRadians(11.1333); var phone = new SimpleDigitalTransmitter { Name = "Dessie, Ethiopia", LocationPoint = new PointCartographic(earth, new Cartographic(longitude, latitude, 0.0)), CarrierFrequency = m_intendedSignal.TargetFrequency, EffectiveIsotropicRadiatedPower = CommunicationAnalysis.FromDecibels(m_transmitPowerTrackBar.Value), DataRate = 50000.0 }; //Add a default marker phone.Extensions.Add(new MarkerGraphicsExtension(new MarkerGraphics { Texture = new ConstantGraphicsParameter <Texture2D>(m_phoneTexture) })); //Add a label based on the name and show just below the marker. var textGraphics = new TextGraphics { Color = new ConstantGraphicsParameter <Color>(Color.Yellow), Font = new ConstantGraphicsParameter <Font>(m_labelFont), Outline = new ConstantGraphicsParameter <bool>(true), OutlineColor = new ConstantGraphicsParameter <Color>(Color.Black), Text = new ConstantGraphicsParameter <string>(phone.Name), Origin = new ConstantGraphicsParameter <Origin>(Origin.TopCenter), PixelOffset = new ConstantGraphicsParameter <PointF>(new PointF(0, -m_phoneTexture.Template.Height / 2)), DisplayParameters = { MaximumDistance = new ConstantGraphicsParameter <double>(75000000.0) } }; if (TextureFilter2D.Supported(TextureWrap.ClampToEdge)) { textGraphics.TextureFilter = new ConstantGraphicsParameter <TextureFilter2D>(TextureFilter2D.NearestClampToEdge); } phone.Extensions.Add(new TextGraphicsExtension(textGraphics)); return(phone); }
public Vector3 CreateVectorAboveSweepline(IFixture fixture) { var sweepline = fixture.Create <Sweepline>(); var sweeplineZ = Trig.Cosine(sweepline.Colatitude); var randomZ = (sweeplineZ + (1 - sweeplineZ) * _random.NextDouble()); var randomAzimuth = Constants.Pi * _random.NextDouble(); var x = Math.Sqrt(1.0 - randomZ * randomZ) * Trig.Cosine(randomAzimuth); var y = Math.Sqrt(1.0 - randomZ * randomZ) * Trig.Sine(randomAzimuth); var z = randomZ; return(new Vector3(x, y, z)); }
/// <summary> /// Outplace Backward Transformation in one dimension. /// Size must be Power of Two. /// </summary> public void TransformBackward(double[] fftReal, double[] fftImag, out double[] samples) { if (fftReal.Length != fftImag.Length) { throw new ArgumentException(Resources.ArgumentVectorsSameLengths); } if (Fn.CeilingToPowerOf2(fftReal.Length) != fftReal.Length) { throw new ArgumentException(Resources.ArgumentPowerOfTwo, "samples"); } int length = fftReal.Length; int numSamples = length >> 1; double expSignConvention = (_convention & TransformationConvention.InverseExponent) > 0 ? -1d : 1d; double theta = -Constants.Pi / numSamples; double wtemp = Trig.Sine(0.5 * theta); double wpr = -2.0 * wtemp * wtemp; double wpi = expSignConvention * Trig.Sine(theta); double wr = 1.0 + wpr; double wi = wpi; samples = new double[length]; double h1r, h2i, h2r, h1i; // TODO: may be 1 <--> 0 swapped? samples[1] = 0.5 * (fftReal[0] - fftReal[numSamples]); samples[0] = 0.5 * (fftReal[0] + fftReal[numSamples]); for (int i = 1, j = 2; j <= numSamples; i++, j += 2) { h1r = 0.5 * (fftReal[i] + fftReal[numSamples - i]); h1i = 0.5 * (fftImag[i] - fftImag[numSamples - i]); h2r = -0.5 * (fftImag[i] + fftImag[numSamples - i]); h2i = 0.5 * (fftReal[i] - fftReal[numSamples - i]); samples[j] = h1r + wr * h2r + wi * h2i; samples[j + 1] = h1i + wr * h2i - wi * h2r; samples[length - j] = h1r - wr * h2r - wi * h2i; samples[length + 1 - j] = -h1i + wr * h2i - wi * h2r; wr = (wtemp = wr) * wpr - wi * wpi + wr; wi = wi * wpr + wtemp * wpi + wi; } // Transform odd and even vectors (packed as one complex vector) _fft.DiscreteFourierTransform(samples, false, _convention); }
static void Main(string[] args) { // 球坐标转为笛卡尔坐标 var spherical0 = new Spherical(Math.PI / 4, Math.PI / 8, 100.0); var cartesian0 = new Cartesian(spherical0); Console.WriteLine("球坐标:{0};笛卡尔坐标:{1}", spherical0, cartesian0); // 笛卡尔坐标归一化 UnitCartesian unitCartesian1 = cartesian0.Normalize(); Console.WriteLine("单位矢量笛卡尔坐标:{0}", unitCartesian1); // 地图坐标转为笛卡尔坐标 var cartographic2 = new Cartographic(Trig.DegreesToRadians(120), Trig.DegreesToRadians(30), 100); EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth; Cartesian cartesian2 = earth.Shape.CartographicToCartesian(cartographic2); Console.WriteLine("地图坐标:{0};笛卡尔坐标:{1}", cartographic2, cartesian2); // 笛卡尔坐标转为地图坐标 Cartographic cartographic3 = earth.Shape.CartesianToCartographic(cartesian2); Console.WriteLine("笛卡尔坐标:{0};地图坐标:{1}", cartesian2, cartographic3); // 新坐标系绕原坐标系z轴旋转90度,原向量(1,0,0) var vector4 = new Cartesian(1, 0, 0); var rotation4 = new ElementaryRotation(AxisIndicator.Third, Trig.DegreesToRadians(90)); Cartesian newVector4 = new Matrix3By3(rotation4).Multiply(vector4); Console.WriteLine("旋转前:{0};旋转后:{1}", vector4, newVector4); // 欧拉旋转 var vector5 = new Cartesian(1, 0, 0); double angle = Trig.DegreesToRadians(90); var euler = new EulerSequence(angle, angle, angle, EulerSequenceIndicator.Euler321); Cartesian newVector5 = new Matrix3By3(euler).Multiply(vector5); Console.WriteLine("旋转前:{0};旋转后:{1}", vector5, newVector5); // 偏航俯仰翻滚旋转 var vector6 = new Cartesian(1, 0, 0); double angle6 = Trig.DegreesToRadians(90); var ypr = new YawPitchRoll(angle, angle, angle, YawPitchRollIndicator.YPR); Cartesian newVector6 = new Matrix3By3(ypr).Multiply(vector6); Console.WriteLine("旋转前:{0};旋转后:{1}", vector6, newVector6); Console.Read(); }
public void pythagC() { Fix16 side_at0 = (Fix16)3; Fix16 side_bt0 = (Fix16)4; Fix16 expectedResult = 5; Assert.AreEqual(expectedResult, Trig.pythagC(side_at0, side_bt0)); Fix16 side_at1 = (Fix16)5; Fix16 side_bt1 = (Fix16)12; expectedResult = 13; Assert.AreEqual(expectedResult, Trig.pythagC(side_at1, side_bt1)); }
/// <summary> /// Looks for special lines in front of the player to activate. /// </summary> public void UseLines(Player player) { var pt = this.world.PathTraversal; this.useThing = player.Mobj; var angle = player.Mobj.Angle; var x1 = player.Mobj.X; var y1 = player.Mobj.Y; var x2 = x1 + MapInteraction.useRange.ToIntFloor() * Trig.Cos(angle); var y2 = y1 + MapInteraction.useRange.ToIntFloor() * Trig.Sin(angle); pt.PathTraverse(x1, y1, x2, y2, PathTraverseFlags.AddLines, this.useTraverseFunc); }
public void Drive(float amount) { bool neg = amount < 0 ? true : false; if (amount != 1 && amount != -1) { amount %= 1; } amount = Math.Abs(amount); amount *= accelSpeed; amount *= (neg ? -1 : 1); float rotDeg = Rotation - 90; Accelaration = new Vector2f((float)(Math.Cos(Trig.Rad(rotDeg)) * amount), (float)(Math.Sin(Trig.Rad(rotDeg)) * amount)); }
public void TestNumeratorDenominatorOfTernaryProduct() { Expression <Func <double, double> > lambda = x => 2 * x * Trig.Cosecant(x); Expression nominator = Elementary.Numerator(lambda.Body); Assert.AreEqual(ExpressionType.Multiply, nominator.NodeType); Assert.IsInstanceOfType(typeof(BinaryExpression), nominator); Assert.AreEqual("((2 * x) * Cosecant(x))", nominator.ToString()); Expression denominator = Elementary.Denominator(lambda.Body); Assert.AreEqual(ExpressionType.Constant, denominator.NodeType); Assert.IsInstanceOfType(typeof(ConstantExpression), denominator); Assert.AreEqual("1", denominator.ToString()); }
private int T5; // Flag to record that we have landed at the right runway public FlightCalcs() { // Set the flight starting point Q = 0.0; // Altitude V = 0.0; // Speed Y = 20000.0; // Range X = 2500.0; // Deviation B = Trig.DegRad(90.0); // Bearing (90 degrees) C = 0.0; // Glide Path T3 = 1; // On the runway //T4=0; // Haven't yet ever taken off T5 = 0; // Arrival flag //J=0 //I8=0 //H=100 }
public void isPointOnPlane_ReturnTrue_IfThePointLiesOnPlane() { Plane plane = new Plane(new Point() { 30, 45, 0 }, new Vector() { 30, 45, 0 }); Point pt = new Point() { 26.565905, 47.289396, 0.0 }; Trig.isPointOnPlane(pt, plane, 0.1).Should().BeTrue(); }
public void Test() { // Fixture setup var arcA = new Arc { Site = Utilities.SiteAt(45, -45) }; var arcB = new Arc { Site = Utilities.SiteAt(0, 0) }; var arcC = new Arc { Site = Utilities.SiteAt(45, 45) }; var circle = new CircleEvent(arcA, arcB, arcC); var a = arcA.Site.Position; var b = arcB.Site.Position; var c = arcC.Site.Position; var center = (a - b).CrossMultiply(c - b).Normalize(); var colatitudeOfCenter = Trig.InverseCosine(center[2]); var radius = Trig.InverseCosine(a.ScalarMultiply(center)); var isOnOutsideOfSphere = colatitudeOfCenter + radius <= Constants.Pi; var sign = isOnOutsideOfSphere ? 1 : -1; var expectedPriority = sign * (1 + Trig.Cosine(colatitudeOfCenter + radius)); // Exercise system var priority = circle.Priority; Debug.WriteLine(expectedPriority); Debug.WriteLine(Trig.RadianToDegree(colatitudeOfCenter)); Debug.WriteLine(Trig.RadianToDegree(radius)); // Verify outcome var failureString = String.Format( "Expected priority was {0}\nActual priority was {1}", expectedPriority, priority); Assert.True(Number.AlmostEqual(expectedPriority, priority, Tolerance), failureString); // Teardown }
public void Rotate(Vector3D rotationAmount) { var rotationAroundX = new Matrix3D(); rotationAroundX.Rotate(new Quaternion(Right, Trig.DegreeToRadian(rotationAmount.Y))); var rotationAroundY = new Matrix3D(); rotationAroundY.Rotate(new Quaternion(Up, Trig.DegreeToRadian(rotationAmount.X))); var rotationMatrix = Matrix3D.Multiply(rotationAroundX, rotationAroundY); Direction = Vector3D.Multiply(Direction, rotationMatrix); Up = Vector3D.Multiply(Up, rotationMatrix); UpdateSettings(); }
public ParticleGameObject(Vector2 position, Animation animation, int alpha, int alphaAccel, float rotation, float rotationAccel, float scale, float scaleAccel, float speed, float accel) : base(position, animation) { _alphaAccel = alphaAccel; _rotationAccel = rotationAccel; _scaleAccel = scaleAccel; this.rotation = rotation; this.color = color; this.scale = scale; velocity = Trig.getVelocity(rotation, speed); _accel = accel; _alpha = alpha; _alphaAccel = alphaAccel; }
public XyzPoint ToXyzPoint() { //var dec = DmsAngle.FromDecimal(Declination); //var b = Math.Sign(Declination) * // (Math.Abs(dec.Degrees) + dec.Minutes / 60.0 + dec.Seconds / 3600.0); var ra = Trig.DegreeToRadian(RightAscension); var dec = Trig.DegreeToRadian(Declination); return(new XyzPoint { X = Distance * Math.Cos(dec) * Math.Cos(ra), Y = Distance * Math.Cos(dec) * Math.Sin(ra), Z = Distance * Math.Sin(dec) }); }
/// <summary> /// Shoot a missile from the source. /// For players. /// </summary> public void SpawnPlayerMissile(Mobj source, MobjType type) { var hs = this.world.Hitscan; // See which target is to be aimed at. var angle = source.Angle; var slope = hs.AimLineAttack(source, angle, Fixed.FromInt(16 * 64)); if (hs.LineTarget == null) { angle += new Angle(1 << 26); slope = hs.AimLineAttack(source, angle, Fixed.FromInt(16 * 64)); if (hs.LineTarget == null) { angle -= new Angle(2 << 26); slope = hs.AimLineAttack(source, angle, Fixed.FromInt(16 * 64)); } if (hs.LineTarget == null) { angle = source.Angle; slope = Fixed.Zero; } } var x = source.X; var y = source.Y; var z = source.Z + Fixed.FromInt(32); var missile = this.SpawnMobj(x, y, z, type); if (missile.Info.SeeSound != 0) { this.world.StartSound(missile, missile.Info.SeeSound, SfxType.Misc); } missile.Target = source; missile.Angle = angle; missile.MomX = new Fixed(missile.Info.Speed) * Trig.Cos(angle); missile.MomY = new Fixed(missile.Info.Speed) * Trig.Sin(angle); missile.MomZ = new Fixed(missile.Info.Speed) * slope; this.CheckMissileSpawn(missile); }
public void EdgeLengths_OnACube_ShouldCalculateTheCorrectLengths (IPolyhedron polyhedron) { // Fixture setup var correctLength = Math.Sqrt(3) * Trig.InverseCosine(1.0 / 3.0); var expected = Enumerable.Repeat(correctLength, 24).ToList(); // Exercise system var edgeLengths = FaceIndexedTableFactory.EdgeLengths(polyhedron); var actual = edgeLengths.SelectMany(list => list).ToList(); // Verify outcome TestUtilities.WriteExpectedAndActual(expected, actual); Assert.True(TestUtilities.UnorderedEquals(expected, actual, TestUtilities.RelativeAccuracy)); // Teardown }
public static IEnumerable <Point> FindPointsInCirclesNearestTargets(int pointCount, IEnumerable <Circle> starts, IEnumerable <Point> targets, IEnumerable <Circle> avoids) { if (pointCount <= 0) { return(new Point[] { }); } var avoidEdgedStarts = avoids.SelectMany(c => Trig.CalcOuterEdgeOfCircle(c)) .Where(p => starts.Any(c => c.IsInRange(p))); var potentialStarts = starts.SelectMany(c => Trig.CalcInnerEdgeOfCircle(c)) .Concat(avoidEdgedStarts) .Where(p => p.IsOnBoard()) .Where(p => !avoids.Any(c => c.IsInRange(p))) .Distinct(); return(potentialStarts.MinByValue(pointCount, p => targets.Min(t => Trig.Distance(p, t)))); }
public void PointAt_ShouldReturnAPointWithTheSameAzimuthAsTheArgument (Arc arc, Vector3 vector, Sweepline sweepline) { // Fixture setup // Exercise system var point = arc.PointAt(vector, sweepline); // Verify outcome var argumentAzimuth = Trig.InverseTangentFromRational(vector.Y, vector.X); var resultAzimuth = Trig.InverseTangentFromRational(point.Y, point.X); var failureString = String.Format("Argument azimuth was {0} \nResult azimuth was {1}", argumentAzimuth, resultAzimuth); Assert.True(Number.AlmostEqual(argumentAzimuth, resultAzimuth, Tolerance), failureString); // Teardown }
public void Vectors_ShouldAllBeAboveSweepline(List <Vector3> vectors, Sweepline anonymousSweepline) { // Fixture setup // Exercise system // Verify outcome var expectedResult = Trig.Cosine(anonymousSweepline.Colatitude); foreach (var vector in vectors) { var result = vector[2]; var failureString = String.Format("Had Z {0}, expected Z was {1}", result, expectedResult); Assert.True(result >= expectedResult, failureString); } // Teardown }
public void TestExponential() { // exp(0) = 1 Complex zero = Complex.Zero; Complex expZero = zero.Exponential(); Assert.That(expZero.Real, Is.EqualTo(1d), "Re{exp(0)} = 1"); Assert.That(expZero.Imag, Is.EqualTo(0d), "Im{exp(0)} = 0"); // exp(1) = e Complex one = Complex.One; Complex expOne = one.Exponential(); Assert.That(expOne.Real, Is.EqualTo(Constants.E), "Re{exp(1)} = e"); Assert.That(expOne.Imag, Is.EqualTo(0d), "Im{exp(1)} = 0"); // exp(i) = cos(1) + sin(1) * i Complex I = Complex.I; Complex expI = I.Exponential(); Assert.That(expI.Real, Is.EqualTo(Trig.Cosine(1d)), "Re{exp(i)} = cos(1)"); Assert.That(expI.Imag, Is.EqualTo(Trig.Sine(1d)), "Im{exp(i)} = sin(1)"); // exp(-1) = 1/e Complex mOne = -Complex.One; Complex expMOne = mOne.Exponential(); Assert.That(expMOne.Real, Is.EqualTo(1.0 / Constants.E), "Re{exp(-1)} = 1/e"); Assert.That(expMOne.Imag, Is.EqualTo(0d), "Im{exp(-1)} = 0"); // exp(-i) = cos(1) - sin(1) * i Complex mI = -Complex.I; Complex expMI = mI.Exponential(); Assert.That(expMI.Real, Is.EqualTo(Trig.Cosine(1d)), "Re{exp(-i)} = cos(1)"); Assert.That(expMI.Imag, Is.EqualTo(-Trig.Sine(1d)), "Im{exp(-i)} = -sin(1)"); // exp(i+1) = e * cos(1) + e * sin(1) * i Complex onePlusI = Complex.One + Complex.I; Complex expOnePlusI = onePlusI.Exponential(); Assert.That(expOnePlusI.Real, Is.EqualTo(Constants.E * Trig.Cosine(1d)), "Re{exp(i+1)} = e * cos(1)"); Assert.That(expOnePlusI.Imag, Is.EqualTo(Constants.E * Trig.Sine(1d)), "Im{exp(i+1)} = e * sin(1)"); }
public void PointAt_ShouldReturnAPointEquidistantFromTheSweeplineAndTheFocus (Arc arc, Vector3 vector, Sweepline sweepline) { // Fixture setup var focus = arc.Site.Position; // Exercise system var point = arc.PointAt(vector, sweepline); // Verify outcome var distanceToFocus = Trig.InverseCosine(point.ScalarMultiply(focus)); var distanceToSweepline = Math.Abs(sweepline.Colatitude - Trig.InverseCosine(point.Z)); var failureString = String.Format("Distance to focus was {0}\nDistance to sweepline was {1}", distanceToFocus, distanceToSweepline); Assert.True(Number.AlmostEqual(distanceToFocus, distanceToSweepline, Tolerance), failureString); // Teardown }