本文整理汇总了C#中Point.DistanceTo方法的典型用法代码示例。如果您正苦于以下问题:C# Point.DistanceTo方法的具体用法?C# Point.DistanceTo怎么用?C# Point.DistanceTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point.DistanceTo方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DistanceTo
public void DistanceTo()
{
var zero = new Point();
var p = new Point(3, 4);
Assert.AreEqual(5, zero.DistanceTo(p));
Assert.AreEqual(0, zero.DistanceTo(zero));
}
示例2: Main
public static void Main(string[] args)
{
var pt1 = new Point(0, 0);
var pt2 = new Point(3, 4);
var d = pt1.DistanceTo(pt2);
var circ = new Circle(3, 4, 5);
var d2 = pt1.DistanceTo(circ);
var d3 = circ.DistanceTo(pt2);
}
示例3: Main
static void Main(string[] args)
{
Point headquarters = new Point() { X = int.Parse(Console.ReadLine()),
Y = int.Parse(Console.ReadLine()) };
int distanceToBorder = int.Parse(Console.ReadLine()); // shooting range
int numPlanes = int.Parse(Console.ReadLine());
for (int i = 0; i < numPlanes; i++)
{
Point plane = new Point() { X = int.Parse(Console.ReadLine()),
Y = int.Parse(Console.ReadLine())};
double distanceToPlane = headquarters.DistanceTo(plane);
if (distanceToPlane <= distanceToBorder)
Console.WriteLine("You destroyed a plane at [{0},{1}]", plane.X, plane.Y);
}
}
示例4: TestShipLength
public void TestShipLength()
{
var point1 = new Point('E', 6, false, false);
var point2 = new Point('E', 6, false, false);
Assert.AreEqual(1, point1.DistanceTo(point2));
point1 = new Point('E', 6, false, false);
point2 = new Point('F', 6, false, false);
Assert.AreEqual(2, point1.DistanceTo(point2));
point1 = new Point('A', 1, false, false);
point2 = new Point('J', 1, false, false);
Assert.AreEqual(10, point1.DistanceTo(point2));
point1 = new Point('A', 1, false, false);
point2 = new Point('A', 10, false, false);
Assert.AreEqual(10, point1.DistanceTo(point2));
}
示例5: Main
static void Main()
{
// Points based on integers
Point<int> pti1 = new Point<int>();
Point<int> pti2 = new Point<int>(5, 3);
Console.WriteLine(pti1.DistanceTo(pti2));
// Points based on doubles
Point<double> ptd1 = new Point<double>(13.5, 15);
Point<double> ptd2 = new Point<double>(3.54, 5E-1);
Console.WriteLine(ptd2.DistanceTo(ptd1));
// Points based on strings
Point<string> pts1 = new Point<string>("34", "27");
Point<string> pts2 = new Point<string>("0", "0");
Console.WriteLine(pts1.DistanceTo(pts2));
}
示例6: FindStart
public Point FindStart(Point hint)
{
Point found = Point.Empty;
//Check all pixels
for (int x = 0; x < vinyl.Width; x++)
for (int y = 0; y < vinyl.Height; y++)
{
//Get which point to check
Point toCheck = new Point(x, y);
//Check if the point should not be ignored and has 1 surrounding point
if (!IgnoreColor(GetColor(toCheck)) && SurroundingPoints(toCheck) == 1)
//Check if the distance from the new point to the ceanter is greater
if (found.IsEmpty || toCheck.DistanceTo(hint) < found.DistanceTo(hint))
found = toCheck;
}
return found;
}
示例7: InitializePathfindingSearch
public void InitializePathfindingSearch(RectangleCharacter startPosition)
{
Point initp = new Point(WM, WM.Character.xPos, WM.Character.yPos);
Point aux = new Point(WM, 9999, 9999);
float dist = 99999999999;
foreach (Point p in WM.Mesh)
{
float auxd = initp.DistanceTo(p);
if (auxd <= dist)
{
aux = p;
dist = auxd;
}
}
Connection c = new Connection(WM, initp, aux);
c.categorie = c.SLIDEONPLATFORM;
initp.addConnection(c);
NodeRecord nri = new NodeRecord();
nri.node = initp;
nri.gValue = 0;
nri.hValue = 0;
nri.fValue = 0;
nri.Points = 0;
var bestNode = nri;
this.StartNode = initp;
this.InProgress = true;
this.TotalProcessedNodes = 0;
this.MaxOpenNodes = 0;
this.Open.Initialize();
this.Open.AddToOpen(bestNode);
this.Closed.Initialize();
}
示例8: Update
public void Update(GameTime gameTime)
{
Point endLocation = new Point(Game1.GRID_TILE_SIZE * GridLocation.X, Game1.GRID_TILE_SIZE * GridLocation.Y);
if (RealLocation != endLocation)
{
MoveAnimation.Update(gameTime);
int distance = endLocation.DistanceTo(RealLocation);
if (distance >= MOVE_SPEED)
{
int dX = (int)(MOVE_SPEED * (endLocation.X - RealLocation.X)) / distance;
int dY = (int)(MOVE_SPEED * (endLocation.Y - RealLocation.Y)) / distance;
RealLocation = new Point(RealLocation.X + dX, RealLocation.Y + dY);
}
else
{
RealLocation = endLocation;
}
}
}
示例9: TryGetCorner
private static bool TryGetCorner(Point intersectionPoint, Point cornerPoint, double radius, Func<Point, double, Circle> factory, out Circle corner)
{
if (intersectionPoint.DistanceTo(cornerPoint) < radius)
{
corner = factory(cornerPoint, radius);
return true;
}
corner = default(Circle);
return false;
}
示例10: GenerateContext
public void GenerateContext()
{
this.Context = new GameContext();
this.Context.Teams = Enumerable.Range(0, _players.Length)
.Select(teamId => new Team(teamId, _nbrDrones)).ToList();
var random = new Random();
var minZoneX = Zone.Radius;
var maxZoneX = GameContext.FieldWidth - 2 * Zone.Radius;
var minZoneY = Zone.Radius;
var maxZoneY = GameContext.FieldHeight - 2 * Zone.Radius;
int minDistanceBetweenZones = 300;
// zones
this.Context.Zones = new List<Zone>();
for(int i = 0; i < _nbrZones; i++)
{
Point zoneCenter;
do
{
zoneCenter = new Point(random.Next(minZoneX, maxZoneX), random.Next(minZoneY, maxZoneY));
} while(this.Context.Zones.Any(z => zoneCenter.DistanceTo(z.Center) < minDistanceBetweenZones));
this.Context.Zones.Add(new Zone(i, zoneCenter));
}
// drone starting points
_droneStartingPoints = new Point[_nbrDrones];
for(int i = 0; i < _droneStartingPoints.Length; i++)
_droneStartingPoints[i] = new Point(random.Next(GameContext.FieldWidth), random.Next(GameContext.FieldHeight));
}
示例11: DistanceToPoint
public double DistanceToPoint(Point destination)
{
return destination.DistanceTo(TopLeft);
}
示例12: IsFree
public bool IsFree(Point point)
{
foreach (Edge edge in edges)
if (point.DistanceTo(edge) < Util.Epsilon) return false;
return true;
}
示例13: TryMove
bool TryMove(Point start, Point end, double noTouch, out double success)
{
success = start.DistanceTo(end);
bool result = true;
Edge other = new Edge(start, end);
Point intersection;
foreach (Edge edge in edges)
if (edge.ComputeIntersection(other, out intersection) &&
intersection.Between(other.P1, other.P2))
{
success = Math.Min(success, start.DistanceTo(intersection) - noTouch);
result = false;
}
if (success < 0) success = 0;
return result;
}
示例14: OffsetPoint
//------------------------------------------------------------------------------
private void OffsetPoint(int j, ref int k, JoinType jointype, double eps)
{
sinA = (normals[k].X * normals[j].Y - normals[j].X * normals[k].Y);
if (sinA > 1.0) sinA = 1.0;
else if (sinA < -1.0) sinA = -1.0;
if (sinA * delta < 0)
{
var p1 = new Point((srcPoly[j].X + normals[k].X * delta), (srcPoly[j].Y + normals[k].Y * delta));
var p2 = new Point((srcPoly[j].X + normals[j].X * delta), (srcPoly[j].Y + normals[j].Y * delta));
destPoly.Add(p1);
if (p1.DistanceTo(srcPoly[j]) > eps)
destPoly.Add(srcPoly[j]);
if (p2.DistanceTo(srcPoly[j]) > eps)
destPoly.Add(p2);
}
else
{
switch (jointype)
{
case JoinType.Miter:
{
var r = 1 + (normals[j].X * normals[k].X +
normals[j].Y * normals[k].Y);
if (r >= miterLim) DoMiter(j, k, r);
else DoSquare(j, k);
break;
}
case JoinType.Square:
DoSquare(j, k);
break;
case JoinType.Round:
Do(j, k);
break;
}
}
k = j;
}