public void TestAbs() { var a = new Angle(-180); Assert.AreEqual(a.Degrees, -180); var b = a.Abs(); Assert.AreEqual(180, b.Degrees); }
public void TestAbs() { Angle a = new Angle(-180); Assert.AreEqual(a.Degrees, -180); Angle b = a.Abs(); Assert.AreEqual(b.Degrees, 180); }
public void MoveTo(Angle angle) { if (angle.Abs() < MaxPosition) { _targetposition = angle; } else { _targetposition = angle.Sign() * MaxPosition; } }
/// <summary> /// Get coordinates as a culture invariant string. /// </summary> /// <returns>The coordinates as culture invariant string</returns> public override string ToString() { var builder = new StringBuilder(); builder.Append(_mLatitude.Abs()); builder.Append(_mLatitude >= Angle.Zero ? 'N' : 'S'); builder.Append(';'); builder.Append(_mLongitude.Abs()); builder.Append(_mLongitude >= Angle.Zero ? 'E' : 'W'); builder.Append(';'); return(builder.ToString()); }
private static string FormatRudder(Angle angle) { var sb = new StringBuilder(); var abs = angle.Abs(); sb.Append(FormatBearing(abs)); if (abs >= Angle.FromDegrees(.5)) { sb.Append(" to the "); sb.Append(angle.Sign() > 0 ? "right" : "left"); } return(sb.ToString()); }
public void Abs() { var random = new Random(666); for (var i = 0; i < 100; i++) { var a = random.Next(120) - 60; var b = Math.Abs(a); var aa = Angle.FromDegree(a); var ab = Angle.Abs(aa); var expectedSin = Math.Sin(2 * Math.PI * b / 360); var expectedCos = Math.Cos(2 * Math.PI * b / 360); var actualSin = Math.Sin(ab.ToRadian()); var actualCos = Math.Cos(ab.ToRadian()); Assert.AreEqual(expectedSin, actualSin, delta); Assert.AreEqual(expectedCos, actualCos, delta); } }
/// <summary> /// Split a given Rotation-Amount from this Arc /// </summary> /// <param name="splitAngle"></param> /// <returns></returns> public IEnumerable <Arc> Split(Angle splitAngle) { var arcs = new List <Arc>(); splitAngle = Angle.Abs(splitAngle); if ((splitAngle > this.Angle)) { arcs.Add(this); // can't split... } else { /* split the arc */ //segment uno var split = new Arc(this.Radius, splitAngle, _base); split.Location = this.Location; split.Direction = this.Direction; //split.AngleDiff = this.AngleDiff; arcs.Add(split); //segment due Vector2 newBase; if (this.Direction == Direction.LEFT) { newBase = _base.GetRotated(splitAngle); } else { newBase = _base.GetRotated(-splitAngle); } split = new Arc(this.Radius, this.Angle - splitAngle, newBase); split.Location = this.GetPointOnArc(splitAngle); split.Direction = this.Direction; //split.AngleDiff = this.AngleDiff; arcs.Add(split); } return(arcs); }
/// <summary> /// Get the /// </summary> /// <param name="angle"></param> /// <returns></returns> public SpriteAnimationDirection GetDirection(Angle angle) { if (_Directions.ContainsKey(angle)) { return(_Directions[angle]); } else { Angle mindA = Angle.Complete; SpriteAnimationDirection closest = null; foreach (var entry in Directions) { Angle dA = (angle - entry.Key).Normalize(); if (dA.Abs() < mindA.Abs()) { closest = entry.Value; mindA = dA; } } return(closest); } }
private void FixedUpdate() { #region Wrap/Unwrap //Unwrap if (Count > 1) { if (!foundEdge) { FindEdge(); } else { DoUnwrapGeometry(); } //Determine if the edge is still 'holding onto' the rope. dot = Vector2.Dot(normal, pathNrml); angle = Geometry.HeadToTailAngle(Segment1, Segment2); if ( angle.Abs() > 170 && dot > 0 ) { Unwrap(); } } //Wrap if (Count > 0) { Vector2 toEndpoint = Point2 - Position; RaycastHit2D hit = Physics2D.Raycast(Position, toEndpoint, toEndpoint.magnitude - error1); if (hit) { Wrap(hit.point, hit.collider); } } #endregion #region Spiderman Physics if (connected) { distance = Vector2.Distance(Position, swingpoint); hasTension = (distance > length); if (hasTension) { #region G _perpendicular (Gp) //solving for the perpendicular component of gravity relative to the endpoint. float G = Physics2D.gravity.magnitude; float ThetaGE = Vector2.SignedAngle( swingpoint - (Vector2)transform.position, Physics2D.gravity ); float ThetaGR = Vector2.SignedAngle( Vector2.right, Physics2D.gravity ); float ThetaGpR = ThetaGR - ThetaGE + 90; ThetaGE *= Mathf.Deg2Rad; ThetaGpR *= Mathf.Deg2Rad; float Gpx = G * Mathf.Sin(ThetaGE) * Mathf.Cos(ThetaGpR); float Gpy = G * Mathf.Sin(ThetaGE) * Mathf.Sin(ThetaGpR); Vector2 Gp = new Vector2(Gpx, Gpy); #endregion Vector2 p = Vector2.Lerp(Position, swingpoint, (distance - length) / distance); Vector2 v = TangentVelocity(rigidbody, gameObject, swingpoint); v *= ((distance - length) / length) + 1.0f; v += Gp * Time.fixedDeltaTime; rigidbody.MovePosition((v * Time.fixedDeltaTime) + p); rigidbody.velocity = v; distance = length; } } else { hasTension = false; } #endregion }