CogMath DistancePointPolygon Method Cognex VisionPro 9.8 SR1
Returns the shortest distance from the given point to the given polygon. Also provides the closest point on the polygon.

Namespace: Cognex.VisionPro
Assembly: Cognex.VisionPro.Core (in Cognex.VisionPro.Core.dll) Version: 75.0.0.0
Syntax

public static double DistancePointPolygon(
	double x,
	double y,
	CogPolygon polygon,
	ICogImage image,
	out double polygonX,
	out double polygonY
)

Parameters

x
Type: System Double

The x-coordinate of the point.

y
Type: System Double

The y-coordinate of the point.

polygon
Type: Cognex.VisionPro CogPolygon

The polygon.

image
Type: Cognex.VisionPro ICogImage

An image that specifies the coordinate space to use.

polygonX
Type: System Double 

The x-coordinate of the nearest point on the polygon. If the point is on the polygon, this value is the same as x.

polygonY
Type: System Double 

The y-coordinate of the nearest point on the polygon. If the point is on the polygon, this value is the same as y.

Return Value

Type: Double

The shortest distance from PolygonA to PolygonB. If the nearest point is within PolygonA the distance is negative. If the polygons intersect, the distance is zero.

Exceptions

ExceptionCondition
ArgumentException

polygon is NULL.

CogSpaceTreeInvalidNameSyntaxException

At least one shape's selected space names is not a legal space name.

CogSpaceTreeNotUniqueException

At least one shape's selected space names is a nonqualified space name and more than one instance of it exists in image's coordinate space tree.

CogSpaceTreeNotInTreeException

At least one shape does not exist in image's coordinate space tree.

CogImageNoTreeException

The coordinate space tree is missing from image.

Remarks

Returns the shortest distance from the given point to the given polygon and optionally the closest point on the polygon. If the point is within the polygon (according to FillMode), the distance is negative.

If you supply a value for the image parameter, then polygon is mapped to the selected space of image before the measurement is computed and the result is expressed in that space. x and y are presumed to be expressed in the selected space of image.

If you do not supply a value for image, then polygon, x, and y are presumed to be in the same coordinate space.

If more than one point on the polygon has the same distance from (x, y), the returned point (polygonX, polygonY) is chosen arbitrarily among them.

See Also