本文整理汇总了C#中ICoordinate.Distance方法的典型用法代码示例。如果您正苦于以下问题:C# ICoordinate.Distance方法的具体用法?C# ICoordinate.Distance怎么用?C# ICoordinate.Distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICoordinate
的用法示例。
在下文中一共展示了ICoordinate.Distance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
/// <summary>
///
/// </summary>
/// <param name="point"></param>
private void Add(ICoordinate point)
{
double dist = point.Distance(centroid);
if (dist < minDistance)
{
interiorPoint = new Coordinate(point);
minDistance = dist;
}
}
示例2: 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(ICoordinate p, ICoordinate A, ICoordinate 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)));
}
示例3: Equal
/// <summary>
///
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="tolerance"></param>
/// <returns></returns>
protected bool Equal(ICoordinate a, ICoordinate b, double tolerance)
{
if (tolerance == 0)
return a.Equals(b);
return a.Distance(b) <= tolerance;
}
示例4: FindSnapForVertex
/// <summary>
///
/// </summary>
/// <param name="pt"></param>
/// <param name="snapPts"></param>
/// <returns></returns>
private ICoordinate FindSnapForVertex(ICoordinate pt, ICoordinate[] snapPts)
{
foreach (ICoordinate coord in snapPts)
{
// if point is already equal to a src pt, don't snap
if (pt.Equals2D(coord))
return null;
if (pt.Distance(coord) < snapTolerance)
return coord;
}
return null;
}
示例5: AppendCoordinate
private void AppendCoordinate(ILineString lineString, ICoordinate worldPosition)
{
double worldDistance = MapControlHelper.ImageToWorld(Map, (int)ActualMinDistance);
ICoordinate coordinate;
if (TemporalEnd)
coordinate = lineString.Coordinates[lineString.Coordinates.Length - 2];
else
coordinate = lineString.Coordinates[lineString.Coordinates.Length - 1];
if (worldPosition.Distance(coordinate) > worldDistance)
{
// if distance is larger than marge add new coordinate at exact location. During drawing line
// you do not want to snap. For example a line should be able to pass very near a node.
// HACK: not nice to solve here. If autocurve do not add snapped point when dragging. If not auto
// curve use the actualSnapping value (=Snap)
ICoordinate SnapLocation = worldPosition;
if (!AutoCurve)
SnapLocation = Snap(worldPosition).Location;
if (TemporalEnd)
GeometryHelper.SetCoordinate(lineString, lineString.Coordinates.Length - 1, SnapLocation);
else
lineString = AppendCurvePoint(lineString, SnapLocation);
TemporalEnd = false;
}
else
{
ICoordinate SnapLocation = worldPosition;
if (!SupportShorties)
SnapLocation = Snap(worldPosition).Location;
if (TemporalEnd)
GeometryHelper.SetCoordinate(lineString, lineString.Coordinates.Length - 1, SnapLocation);
else
lineString = AppendCurvePoint(lineString, SnapLocation);
TemporalEnd = true;
}
newLineGeometry.Clear();
newLineGeometry.Add(lineString);
}