本文整理汇总了C#中Coordinates.ToDegrees方法的典型用法代码示例。如果您正苦于以下问题:C# Coordinates.ToDegrees方法的具体用法?C# Coordinates.ToDegrees怎么用?C# Coordinates.ToDegrees使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coordinates
的用法示例。
在下文中一共展示了Coordinates.ToDegrees方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClosestInterconnect
/// <summary>
/// Get interconnect closest to our position and orientation
/// </summary>
/// <param name="point"></param>
/// <param name="heading"></param>
/// <returns></returns>
public ArbiterInterconnect ClosestInterconnect(Coordinates point, Coordinates heading)
{
ArbiterInterconnect closest = null;
double best = Double.MaxValue;
foreach (ArbiterInterconnect ai in this.ArbiterInterconnects.Values)
{
// get closest
double distance = ai.InterconnectPath.GetPoint(ai.InterconnectPath.GetClosestPoint(point)).DistanceTo(point);
// get heading of interconnect approximately
Coordinates interHeading = ai.FinalGeneric.Position - ai.InitialGeneric.Position;
if (distance < best && Math.Abs(interHeading.ToDegrees() - heading.ToDegrees()) < 45.0)
{
best = distance;
closest = ai;
}
}
return closest;
}
示例2: SetTurnDirection
public void SetTurnDirection(ArbiterInterconnect ai)
{
#region Turn Direction
if (ai.InitialGeneric is ArbiterWaypoint && ai.FinalGeneric is ArbiterWaypoint)
{
ArbiterWaypoint initWp = (ArbiterWaypoint)ai.InitialGeneric;
ArbiterWaypoint finWp = (ArbiterWaypoint)ai.FinalGeneric;
// check not uturn
if (!initWp.Lane.Way.Segment.Equals(finWp.Lane.Way.Segment) || initWp.Lane.Way.Equals(finWp.Lane.Way))
{
Coordinates iVec = initWp.PreviousPartition != null ? initWp.PreviousPartition.Vector().Normalize(1.0) : initWp.NextPartition.Vector().Normalize(1.0);
double iRot = -iVec.ArcTan;
Coordinates fVec = finWp.NextPartition != null ? finWp.NextPartition.Vector().Normalize(1.0) : finWp.PreviousPartition.Vector().Normalize(1.0);
fVec = fVec.Rotate(iRot);
double fDeg = fVec.ToDegrees();
double arcTan = Math.Atan2(fVec.Y, fVec.X) * 180.0 / Math.PI;
if (arcTan > 45.0)
ai.TurnDirection = ArbiterTurnDirection.Left;
else if (arcTan < -45.0)
ai.TurnDirection = ArbiterTurnDirection.Right;
else
ai.TurnDirection = ArbiterTurnDirection.Straight;
}
else
{
Coordinates iVec = initWp.PreviousPartition != null ? initWp.PreviousPartition.Vector().Normalize(1.0) : initWp.NextPartition.Vector().Normalize(1.0);
double iRot = -iVec.ArcTan;
Coordinates fVec = finWp.NextPartition != null ? finWp.NextPartition.Vector().Normalize(1.0) : finWp.PreviousPartition.Vector().Normalize(1.0);
fVec = fVec.Rotate(iRot);
double fDeg = fVec.ToDegrees();
double arcTan = Math.Atan2(fVec.Y, fVec.X) * 180.0 / Math.PI;
if (arcTan > 45.0 && arcTan < 135.0)
ai.TurnDirection = ArbiterTurnDirection.Left;
else if (arcTan < -45.0 && arcTan > -135.0)
ai.TurnDirection = ArbiterTurnDirection.Right;
else if (Math.Abs(arcTan) < 45.0)
ai.TurnDirection = ArbiterTurnDirection.Straight;
else
ai.TurnDirection = ArbiterTurnDirection.UTurn;
}
}
else
{
Coordinates iVec = new Coordinates();
double iRot = 0.0;
Coordinates fVec = new Coordinates();
double fDeg = 0.0;
if (ai.InitialGeneric is ArbiterWaypoint)
{
ArbiterWaypoint initWp = (ArbiterWaypoint)ai.InitialGeneric;
iVec = initWp.PreviousPartition != null ? initWp.PreviousPartition.Vector().Normalize(1.0) : initWp.NextPartition.Vector().Normalize(1.0);
iRot = -iVec.ArcTan;
}
else if (ai.InitialGeneric is ArbiterPerimeterWaypoint)
{
ArbiterPerimeterWaypoint apw = (ArbiterPerimeterWaypoint)ai.InitialGeneric;
Coordinates centerPoly = apw.Perimeter.PerimeterPolygon.CalculateBoundingCircle().center;
iVec = apw.Position - centerPoly;
iVec = iVec.Normalize(1.0);
iRot = -iVec.ArcTan;
}
if (ai.FinalGeneric is ArbiterWaypoint)
{
ArbiterWaypoint finWp = (ArbiterWaypoint)ai.FinalGeneric;
fVec = finWp.NextPartition != null ? finWp.NextPartition.Vector().Normalize(1.0) : finWp.PreviousPartition.Vector().Normalize(1.0);
fVec = fVec.Rotate(iRot);
fDeg = fVec.ToDegrees();
}
else if (ai.FinalGeneric is ArbiterPerimeterWaypoint)
{
ArbiterPerimeterWaypoint apw = (ArbiterPerimeterWaypoint)ai.FinalGeneric;
Coordinates centerPoly = apw.Perimeter.PerimeterPolygon.CalculateBoundingCircle().center;
fVec = centerPoly - apw.Position;
fVec = fVec.Normalize(1.0);
fVec = fVec.Rotate(iRot);
fDeg = fVec.ToDegrees();
}
double arcTan = Math.Atan2(fVec.Y, fVec.X) * 180.0 / Math.PI;
if (arcTan > 45.0)
ai.TurnDirection = ArbiterTurnDirection.Left;
else if (arcTan < -45.0)
ai.TurnDirection = ArbiterTurnDirection.Right;
else
ai.TurnDirection = ArbiterTurnDirection.Straight;
}
#endregion
}