本文整理汇总了C#中Point.Distance方法的典型用法代码示例。如果您正苦于以下问题:C# Point.Distance方法的具体用法?C# Point.Distance怎么用?C# Point.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point.Distance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsDoubleClick
/// <summary>
/// Determines whether the last click is a double click.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="position">The position.</param>
/// <returns>True if the click was a double click.</returns>
internal static bool IsDoubleClick(object sender, Point position)
{
long clickTicks = DateTime.Now.Ticks;
long elapsedTicks = clickTicks - lastClickTicks;
long elapsedTime = elapsedTicks / TimeSpan.TicksPerMillisecond;
bool quickClick = elapsedTime <= DoubleClickSpeed;
bool senderMatch = lastSender != null && sender.Equals(lastSender.Target);
if (senderMatch && quickClick && position.Distance(lastPosition) <= MaxMoveDistance)
{
// Double click!
lastClickTicks = 0;
lastSender = null;
return true;
}
// Not a double click
lastClickTicks = clickTicks;
lastPosition = position;
if (!quickClick)
{
lastSender = new WeakReference(sender);
}
return false;
}
示例2: ClosestPoint
/// <summary>
/// Computes the closest point on this line segment to another point.
/// </summary>
/// <param name="p">The point to find the closest point to.</param>
/// <returns>
/// A Coordinate which is the closest point on the line segment to the point p.
/// </returns>
public static Point ClosestPoint(Point p, Point LineSegFrom, Point LineSegTo)
{
var factor = ProjectionFactor(p, LineSegFrom, LineSegTo);
if (factor > 0 && factor < 1)
return Project(p, LineSegFrom, LineSegTo);
var dist0 = LineSegFrom.Distance(p);
var dist1 = LineSegTo.Distance(p);
return dist0 < dist1 ? LineSegFrom : LineSegTo;
}
示例3: GetCentreToBoundaryDistance
public double GetCentreToBoundaryDistance(ILinearEquation line)
{
var relativeOrigin = new Point(0, 0);
var relativeBoundaryIntersection = GetRelativeIntersectionPoint(line);
double distanceToBoundary = relativeOrigin.Distance(relativeBoundaryIntersection);
return distanceToBoundary;
}
示例4: FromTwoPointsAndTwoLengths
public static Triangle FromTwoPointsAndTwoLengths(Point point1, Point point2, double l1, double l2)
{
double l3 = point1.Distance(point2);
double area = Triangle.AreaByLenghts(l1, l2, l3);
double angle = Math.Asin(2 * area / (l1 * l3));
Vector horizontal = point1.VectorTo(point1.AddX(1));
double angle0 = horizontal.AngleWith(point1.VectorTo(point2));
double x = l1 * Math.Cos(angle0 - angle);
double y = l1 * Math.Sin(angle0 - angle);
Point point3 = point1.AddX(x).AddY(y);
return new Triangle(point1, point2, point3);
}
示例5: func
private static int func(Point p1, Point p2, Point p3)
{
int h, t;
h = p1.Distance();
t = p2.x + h;
h += p2.Distance();
if (p3.y == t)
{
h += p3.Distance();
}
return h;
}
示例6: IsClosingALoop
private bool IsClosingALoop(LineString gpxLine, int currentIndex, double closestPointTolerance)
{
int indexOfLinePrefix = currentIndex - 1;
var currentCoordinatePoint = new Point(gpxLine[currentIndex]);
while (indexOfLinePrefix >= 0)
{
if (currentCoordinatePoint.Distance(new Point(gpxLine.Coordinates[indexOfLinePrefix])) >
closestPointTolerance)
{
break;
}
indexOfLinePrefix--;
}
if (indexOfLinePrefix < 0)
{
return false;
}
var distance = indexOfLinePrefix > 0
? currentCoordinatePoint.Distance(new LineString(gpxLine.Coordinates.Take(indexOfLinePrefix + 1).ToArray()))
: currentCoordinatePoint.Distance(new Point(gpxLine.Coordinates[indexOfLinePrefix]));
return distance < closestPointTolerance;
}
示例7: WithinDistance
/// <summary>
/// Determines if the polygon is within the specified distance from the point.
/// </summary>
/// <param name="polygon"></param>
/// <param name="point"></param>
/// <param name="distance"></param>
/// <returns></returns>
public static bool WithinDistance(this Polygon polygon, Point point, double distance)
{
if (Null(polygon, point))
return false;
return point.Distance(polygon) < distance;
}
示例8: Distance
/// <summary>
/// Calculates the shortest distance to the point.
/// </summary>
/// <param name="polygon"></param>
/// <param name="point"></param>
/// <returns></returns>
public static double Distance(this Polygon polygon, Point point)
{
AssertNotNull(polygon, point);
return point.Distance(polygon);
}
示例9: ElementNearestToPoint
Element ElementNearestToPoint(Point position, Element caller, out double minDistance, out ThumbPosition nearestThumbPosition)
{
minDistance = double.PositiveInfinity;
Element hitElement = null;
nearestThumbPosition = ThumbPosition.NotSet;
foreach (Element element in UnconnectedElements)
{
if(element == caller) continue;
foreach (ThumbPosition thumbPosition in element.AvailableIncomingConnectors)
{
Point elementLocation = element.GetCanvasThumbPosition(thumbPosition);
double distance = position.Distance(elementLocation);
if(distance < minDistance)
{
minDistance = distance;
hitElement = element;
nearestThumbPosition = thumbPosition;
}
}
}
return hitElement;
}
示例10: GetFeaturesInRange
public static IEnumerable<IFeature> GetFeaturesInRange(ICoordinate coordinate, IEnumerable<IFeature> features, double tolerance)
{
var minDistance = tolerance;
var point = new Point(coordinate);
return (from feature in features
where feature.Geometry != null // Distance method requires a defined Geometry
let distance = point.Distance(feature.Geometry)
where distance <= minDistance
select feature).ToList();
}
示例11: GetEndPoint
Point GetEndPoint(Point startPoint, int minSteps, int maxSteps, int maxSize)
{
Point endPoint = null;
var maxTryes = maxSteps * maxSteps;
var distance = 0;
do {
endPoint = new Point(random.Next(0, maxSize), random.Next(0, maxSize));
maxTryes--;
distance = startPoint.Distance(endPoint);
} while (maxTryes > 0 && (distance < minSteps || distance >= maxSteps));
if (maxTryes == 0) {
return null;
}
return endPoint;
}
示例12: GetNearestFeature
public static IFeature GetNearestFeature(ICoordinate coordinate, IEnumerable<IFeature> features, double tolerance)
{
var minDistance = tolerance;
IFeature minDistanceFeature = null;
var point = new Point(coordinate);
foreach (var feature in features)
{
if(feature.Geometry == null) continue;
var distance = point.Distance(feature.Geometry);
if (distance <= minDistance)
{
minDistance = distance;
minDistanceFeature = feature;
}
}
return minDistanceFeature;
}
示例13: Distance
public static double Distance(Point a, Point b)
{
return a.Distance(b);
}
示例14: Node
public Node(Point pos_, float G_, Point fromPos, Point toPos)
{
pos = pos_;
G = G_ + pos.Distance(fromPos);
H = pos.Distance(toPos);
F = G + H;
}
示例15: DistancePointLine
/// <summary>
/// Computes the distance from a point p to a line segment AB.
/// Note: NON-ROBUST!
/// </summary>
/// <param name="p">The point to compute the distance for.</param>
/// <param name="A">One point of the line.</param>
/// <param name="B">Another point of the line (must be different to A).</param>
/// <returns> The distance from p to line segment AB.</returns>
public static double DistancePointLine(Point p, Point A, Point B)
{
// if start == end, then use pt distance
if (A.Equals(B))
return p.Distance(A);
// otherwise use comp.graphics.algorithms Frequently Asked Questions method
/*(1) AC dot AB
r = ---------
||AB||^2
r has the following meaning:
r=0 Point = A
r=1 Point = B
r<0 Point is on the backward extension of AB
r>1 Point is on the forward extension of AB
0<r<1 Point is interior to AB
*/
double r = ((p.X - A.X) * (B.X - A.X) + (p.Y - A.Y) * (B.Y - A.Y))
/
((B.X - A.X) * (B.X - A.X) + (B.Y - A.Y) * (B.Y - A.Y));
if (r <= 0.0) return p.Distance(A);
if (r >= 1.0) return p.Distance(B);
/*(2)
(Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
s = -----------------------------
Curve^2
Then the distance from C to Point = |s|*Curve.
*/
double s = ((A.Y - p.Y) * (B.X - A.X) - (A.X - p.X) * (B.Y - A.Y))
/
((B.X - A.X) * (B.X - A.X) + (B.Y - A.Y) * (B.Y - A.Y));
return Math.Abs(s) * Math.Sqrt(((B.X - A.X) * (B.X - A.X) + (B.Y - A.Y) * (B.Y - A.Y)));
}