private void Selector_SelectionFinish(PointF arg1, PointF arg2) { lock (Locker) { var pp1 = Mapper.GetCoordinateLocation(arg1.X, arg1.Y).ToRectangularCoordinate().Polar; var pp2 = Mapper.GetCoordinateLocation(arg2.X, arg2.Y).ToRectangularCoordinate().Polar; var r1 = Mapper.GetCoordinateLocation(arg1.X, arg1.Y).ToRectangularCoordinate(); var r2 = Mapper.GetCoordinateLocation(arg2.X, arg2.Y).ToRectangularCoordinate(); WaveGateCoordinates wgc = new WaveGateCoordinates() { Id = currentWaveGateId++, P1 = r1, P2 = r2 }; PolarCoordinate p1 = new PolarCoordinate(r1); PolarCoordinate p2 = new PolarCoordinate(r2); var begin = Functions.FindSmallArcBeginAngle(p1.Az, p2.Az) - (Mapper as PolarRotateDecorator).RotateAngle; var end = Functions.FindSmallArcEndAngle(p1.Az, p2.Az) - (Mapper as PolarRotateDecorator).RotateAngle; WaveGate w = new WaveGate() { BeginAngle = begin, EndAngle = end, BeginDistance = Math.Min(p1.Dis, p2.Dis), EndDistance = Math.Max(p1.Dis, p2.Dis), Id = currentWaveGateId }; WaveGateSelected?.Invoke(this, w); LiveSectorRing ring = new LiveSectorRing() { Center = ReferenceSystem.ScreenOriginalPoint, ScrP1 = arg1, ScrP2 = arg2 }; Objects.Add(ring); waveGateMap.Add(ring, wgc); UpdateView(); } }
protected override void UpdateParameter() { var posOfPrevious = PolarCoordinate.FromOrthogonal(Input.MouseLeft.Previous - Parameters.RotationCenter.ToVector2()); var posOfCurrent = PolarCoordinate.FromOrthogonal(Input.MouseLeft.Current - Parameters.RotationCenter.ToVector2()); Parameters.RotationAngle = posOfCurrent.DifferenceOfAngle(posOfPrevious); }
/// <summary> /// Converts to Cartesian coordinates. /// </summary> /// <returns>CartesianCoordinate.</returns> public static CartesianCoordinate ToCartesian(PolarCoordinate coordinate) { double x = coordinate.Radius * Trig.Cos(coordinate.Azimuth.Radians); double y = coordinate.Radius * Trig.Sin(coordinate.Azimuth.Radians); return(new CartesianCoordinate(x, y, coordinate.Tolerance)); }
IEnumerator Start() { //Fire burst for (int i = 0; i < numBurstsPerWave; i++) { float radDelta = (2f * Mathf.PI) / numBulletsPerBurst; //Fire bullet float curAngle = 0; while (curAngle < 2 * Mathf.PI) { PolarCoordinate direction = new PolarCoordinate(1, curAngle); ParentedBullet newBullet = Instantiate(bulletPrefab, transform.position, new Quaternion()) as ParentedBullet; newBullet.damage = bulletDamage; newBullet.owningPlayer = owningPlayer; if (!GameManager.S.inGame) { newBullet.thisPlayer = thisPlayer; newBullet.SetColor(thisPlayer.playerColor); } newBullet.transform.SetParent(transform); newBullet.transform.position = gameObject.transform.position; newBullet.physics.actOnLocalSpace = true; newBullet.curState = BulletState.parented; newBullet.physics.velocity = bulletVelocity * direction.PolarToCartesian().normalized; curAngle += radDelta; } yield return(new WaitForSeconds(timeBetweenBursts)); } }
protected override void DrawDynamicElement(RenderTarget g) { //var opStep = 1.0f / shadeLen; //if (preDegree > degree) //{ // //shadeLen = 200; // shadeStep = 0.1f; //} //else if (preDegree < degree) //{ // shadeStep = -0.1f; // //shadeLen = 200; //} //else // shadeLen = 1; //for (int i = 0; i < shadeLen; i++) //{ // RectangularCoordinate p = new PolarCoordinate(degree + shadeStep * i, 0, ReferenceSystem.Right).Rectangular; // PointF endPoint = Mapper.GetScreenLocation(p.X, p.Y); // PointF beginPoint = Mapper.GetScreenLocation(0, 0); // antennaBrush.Opacity = 1 - i * opStep; // g.DrawLine(new Point2F(beginPoint.X, beginPoint.Y), new Point2F(endPoint.X, endPoint.Y), antennaBrush, 2); //} var r = new PolarCoordinate(degree, 0, ReferenceSystem.Right).Rectangular; var p1 = Mapper.GetScreenLocation(r.X, r.Y); g.DrawLine(p1.ToPoint2F(), ReferenceSystem.ScreenOriginalPoint.ToPoint2F(), antennaBrush, 2); }
IEnumerator FireBurstCoroutine() { if (owningPlayer == PlayerEnum.none) { Debug.LogError("Sine shot does not have owning player set"); yield break; } PolarCoordinate direction = new PolarCoordinate(1, target.position - gameObject.transform.position); float t = 0; for (int i = 0; i < bulletsPerBurst; i++) { t += Time.deltaTime; //Generate 2 waves GenerateBullet(direction, -1); GenerateBullet(direction, 1); yield return(new WaitForSeconds(0.02f)); } //Destroy this gameObject after the burst has been fired Destroy(gameObject); }
public void Constructor_Cases(double x, double y, double r, double φ) { PolarCoordinate pc = (new RectangularCoordinate(x, y)).ToPolar(); pc.R.AssertIsEqualTo(r); pc.Φ.AssertIsEqualTo(φ); }
void GenerateBullet(PolarCoordinate direction, int waveDirection) { SineBullet curBullet = bulletPrefab.GetPooledInstance <SineBullet>(); curBullet.owningPlayer = owningPlayer; if (!GameManager.S.inGame) { curBullet.SetColor(thisPlayer.playerColor); curBullet.thisPlayer = thisPlayer; } curBullet.transform.position = gameObject.transform.position; curBullet.GetComponent <PhysicsObj>().velocity = baseVelocity * direction.PolarToCartesian().normalized; //Make amplitude wider during aura mode if (masochistPlayer != null && masochistPlayer.masochistShip.damageMultiplier > 1) { curBullet.amplitude = amplitudeScalar; } else { curBullet.amplitude = 10f; } curBullet.ApplySineWave(waveDirection); }
/// <summary>Draws a circular shape.</summary> public void DrawEllipse(Pen pen, PolarCoordinate center, float radius) { // Translate the coordinate to the center PointD CenterPoint = ToPointD(center); PointD ControlCenterPoint = ToPointD(PolarCoordinate.Empty); // Calculate the bounding box for the ellipse double minX = ControlCenterPoint.X; double minY = ControlCenterPoint.Y; double maxX = ControlCenterPoint.X; double maxY = ControlCenterPoint.Y; for (int angle = 0; angle < 360; angle += 10) { PointD x = ToPointD(new PolarCoordinate(radius, new Angle(angle), Azimuth.North, PolarCoordinateOrientation.Clockwise)); minX = Math.Min(minX, x.X); minY = Math.Min(minY, x.Y); maxX = Math.Max(maxX, x.X); maxY = Math.Max(maxY, x.Y); } // Now translate the values by the center point double width = Math.Abs(maxX - minX); double height = Math.Abs(maxY - minY); #if PocketPC // gx.DrawEllipse(new PenX(pen.Color, pen.Width), // (float)(CenterPoint.X - (width * 0.5)), (float)(CenterPoint.Y - (height * 0.5)), (float)width, (float)height); g.DrawEllipse(pen, (int)(CenterPoint.X - (width * 0.5)), (int)(CenterPoint.Y - (height * 0.5)), (int)width, (int)height); #else g.DrawEllipse(pen, (float)(CenterPoint.X - (width * 0.5)), (float)(CenterPoint.Y - (height * 0.5)), (float)width, (float)height); #endif }
public void DrawCenteredString(string s, Font font, Brush brush, PolarCoordinate point, StringFormat format) { PointD StartPoint = ToPointD(point); SizeF StringSize = g.MeasureString(s, font); PointD NewStart = new PointD(StartPoint.X - StringSize.Width * 0.5, StartPoint.Y - StringSize.Height * 0.5); g.DrawString(s, font, brush, ToPointF(NewStart), format); }
public void Constructor_Default() { RectangularCoordinate rc = default; PolarCoordinate pc = rc.ToPolar(); pc.R.AssertIsEqualTo(0); pc.Φ.AssertIsEqualTo(0); }
Angle GetAngleOfMouse() { SuperspectiveRaycast raycast = Interact.instance.GetRaycastHits(); Vector3 mouseLocation = raycast.hitObject ? raycast.firstObjectHit.point : raycast.finalPosition; Vector3 localMouseLocation = transform.InverseTransformPoint(mouseLocation); return(PolarCoordinate.CartesianToPolar(localMouseLocation).angle); }
protected override void DrawDynamicElement(RenderTarget rt) { PolarCoordinate p = new PolarCoordinate(Model, 0, ReferenceSystem.Top); var r = p.Rectangular; var scrP = Mapper.GetScreenLocation(r.X, r.Y); rt.DrawLine(scrP.ToPoint2F(), ReferenceSystem.ScreenOriginalPoint.ToPoint2F(), LineBrush, 3); }
Angle AngleOfCamera(Camera cam) { Vector3 pillarToPoint = cam.transform.position - transform.position; PolarCoordinate polar = PolarCoordinate.CartesianToPolar(pillarToPoint); PolarCoordinate dimensionShiftPolar = PolarCoordinate.CartesianToPolar(pillar.DimensionShiftVector); return(dimensionShiftPolar.angle - polar.angle); }
protected override void DrawDynamicElement(RenderTarget rt) { var rotatedPoint = new PolarCoordinate(Model.Location.Az, Model.Location.El, Model.Location.Dis).Rectangular; var scrPoint = Mapper.GetScreenLocation(rotatedPoint.X, rotatedPoint.Y); Ellipse e = new Ellipse(scrPoint.ToPoint2F(), 3, 3); rt.FillEllipse(e, fillBrush); }
public void Test1_75Degrees() { // ARRANGE var testPoint = new PointF(.966F, .259F); var expectedResult = new PolarCoordinate(74.991, 1); // ACT & ASSERT ActAndAssertOnConversion(testPoint, expectedResult, PointF.Empty); }
public void Test1_90Degrees() { // ARRANGE var testPoint = new PointF(1F, 0F); var expectedResult = new PolarCoordinate(90.00, 1); // ACT & ASSERT ActAndAssertOnConversion(testPoint, expectedResult, PointF.Empty); }
public void Test1_60Degrees() { // ARRANGE var testPoint = new PointF(.866F, .5F); var expectedResult = new PolarCoordinate(59.999, 1); // ACT & ASSERT ActAndAssertOnConversion(testPoint, expectedResult, PointF.Empty); }
public void Test4_105Degrees() { // ARRANGE var testPoint = new PointF(.966F, -.259F); var expectedResult = new PolarCoordinate(105.009, 1.00); // ACT & ASSERT ActAndAssertOnConversion(testPoint, expectedResult, PointF.Empty); }
private Vector3 GetKnockbackDirection() { PolarCoordinate polarDirection = new PolarCoordinate(1, this.gameObject.transform.eulerAngles.z * Mathf.Deg2Rad); Debug.LogError("Polar Coordinate: " + polarDirection.ToString()); Debug.LogError("KnockbackDirection: " + polarDirection.PolarToCartesian().ToString()); return(polarDirection.PolarToCartesian()); }
public PolarCoordinate ToPolarCoordinate(PointD point) { //return point.Subtract(HalfWidth, HalfHeight).Divide(HorizontalScale, VerticalScale) // .ToPolarCoordinate().Rotate(pRotation.DecimalDegrees).ToOrientation(pOrigin, pOrientation); PointD value = point.Subtract(HalfWidth, HalfHeight).Divide(HorizontalScale, VerticalScale); PolarCoordinate value2 = PointDToPolarCoordinate(value); return(value2.Rotate(pRotation.DecimalDegrees).ToOrientation(pOrigin, pOrientation)); }
private void UpdateWallPosition(UnityEngine.Transform wallTransform, float radsOffset) { PolarCoordinate cameraPolar = CameraToPillar(); float colliderLength = wallTransform.lossyScale.z; PolarCoordinate oppositePolar = new PolarCoordinate(colliderLength / 2f, Angle.Radians(cameraPolar.angle.radians + radsOffset)); oppositePolar.y = wallTransform.position.y; wallTransform.position = oppositePolar.PolarToCartesian() + new Vector3(bottomOfPillar.x, 0, bottomOfPillar.z); }
private void AssertCheckRefPointResults(PointF startPoint, PointF refPoint, PolarCoordinate expectedResult) { // ACT var newPoint = startPoint.Offset(refPoint, 3); var actual = newPoint.GetPolarCoord(); // ASSERT Assert.IsTrue(expectedResult.Equals(actual), $"{expectedResult} <> Actual result: {actual}"); }
public void Test1_45Degrees() { // ARRANGE var testPoint = new Point(50, 50); var expectedResult = new PolarCoordinate(45.00, 70.711); // ACT & ASSERT ActAndAssertOnConversion(testPoint, expectedResult, PointF.Empty); }
public static void ToCartesian_Converts_Polar_Coordinate_to_Cartesian_Coordinate(double radius, double angleRadians, double expectedX, double expectedY) { PolarCoordinate coordinate = new PolarCoordinate(radius, angleRadians); CartesianCoordinate coordinateConverted = Cartesian2DPolarConverter.ToCartesian(coordinate); Assert.AreEqual(expectedX, coordinateConverted.X, Tolerance); Assert.AreEqual(expectedY, coordinateConverted.Y, Tolerance); }
public static void LimitPolar_Returns_Limit_As_Polar_Coordinate() { curveLimit.SetLimitByX(2); PolarCoordinate limit = curveLimit.LimitPolar(); PolarCoordinate expectedLimit = new PolarCoordinate(2.236068, 0.463648, Tolerance); Assert.AreEqual(expectedLimit, limit); }
public static void ToPolar_Converts_Cartesian_Coordinate_to_Polar_Coordinate(double x, double y, double expectedRadius, double expectedAngleRadians) { CartesianCoordinate coordinate = new CartesianCoordinate(x, y); PolarCoordinate coordinateConverted = Cartesian2DPolarConverter.ToPolar(coordinate); Assert.AreEqual(expectedRadius, coordinateConverted.Radius, Tolerance); Assert.AreEqual(expectedAngleRadians, coordinateConverted.Azimuth.Radians, Tolerance); }
public void Cast_PolarCoordinates() { var pc = new PolarCoordinate(3, 1); HypersphericalCoordinate hc = pc; hc.DimensionsCount.AssertIsEqualTo(2); hc.R.AssertIsEqualTo(3); hc.Angles.Span.Single().AssertIsEqualTo(1); }
IEnumerator FireBurstCoroutine() { if (owningPlayer == PlayerEnum.none) { Debug.LogError("Weave shot does not have owning player set"); yield break; } PolarCoordinate direction = new PolarCoordinate(1, target.position - gameObject.transform.position); PolarCoordinate shootDir1 = new PolarCoordinate(1, direction.angle + 90 * Mathf.Deg2Rad); PolarCoordinate shootDir2 = new PolarCoordinate(1, direction.angle - 90 * Mathf.Deg2Rad); //Weaves will span the 180 degree area that is perpendicular to the target float bulletSeparation = 180 / bulletsPerWeave * Mathf.Deg2Rad; int curDirection = 1; for (int i = 0; i < bulletsPerBurst; i++) { //Fire bullet from first weave Bullet curBullet = bulletPrefab.GetPooledInstance <Bullet>(); curBullet.owningPlayer = owningPlayer; if (!GameManager.S.inGame) { curBullet.SetColor(thisPlayer.playerColor); curBullet.thisPlayer = thisPlayer; } curBullet.transform.position = gameObject.transform.position; curBullet.GetComponent <PhysicsObj>().velocity = bulletVelocity * shootDir1.PolarToCartesian().normalized; //Fire bullet from second weave curBullet = bulletPrefab.GetPooledInstance <Bullet>(); curBullet.owningPlayer = owningPlayer; if (!GameManager.S.inGame) { curBullet.SetColor(thisPlayer.playerColor); curBullet.thisPlayer = thisPlayer; } curBullet.transform.position = gameObject.transform.position; curBullet.GetComponent <PhysicsObj>().velocity = bulletVelocity * shootDir2.PolarToCartesian().normalized; //Adjust the angles for the next bullets shootDir1.angle += bulletSeparation * curDirection; shootDir2.angle -= bulletSeparation * curDirection; //Reverse direction if (i % bulletsPerWeave == 0) { curDirection *= -1; } yield return(new WaitForSeconds(bulletDelay)); } //Destroy this gameObject after the burst has been fired Destroy(gameObject); }
/// <summary>Draws text rotated by the specified amount.</summary> public void DrawRotatedString(string s, Font font, Brush brush, PolarCoordinate point) { PointF h = ToPointF(point); g.RotateTransform(Convert.ToSingle(point.Theta.DecimalDegrees + pOrigin.DecimalDegrees - pRotation.DecimalDegrees), MatrixOrder.Append); g.TranslateTransform(h.X, h.Y, MatrixOrder.Append); g.DrawString(s, font, brush, PointF.Empty, pStringFormat); g.ResetTransform(); }
private bool InDownSection(PolarCoordinate value) { return value.Distance > ThumbstickThreshold && InDownDirection(value.Angle); }