CogMath DistanceSegmentPolygon Method Cognex VisionPro 9.21 SR1
Returns the shortest distance from the given segment to the given polygon. Also provides the points on each shape that correspond to this shortest distance.

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

public static double DistanceSegmentPolygon(
	CogLineSegment segment,
	CogPolygon polygon,
	ICogImage image,
	out double segmentX,
	out double segmentY,
	out double polygonX,
	out double polygonY
)

Parameters

segment
Type: Cognex.VisionPro CogLineSegment

The line segment.

polygon
Type: Cognex.VisionPro CogPolygon

The polygon.

image
Type: Cognex.VisionPro ICogImage

An image that specifies the coordinate space to use.

segmentX
Type: System Double 

The x-coordinate of the nearest point on the line segment.

segmentY
Type: System Double 

The x-coordinate of the nearest point on the line segment.

polygonX
Type: System Double 

The x-coordinate of the nearest point on the polygon.

polygonY
Type: System Double 

The y-coordinate of the nearest point on the polygon.

Return Value

Type: Double

The shortest distance from segment to the polygon. If segment is inside the polygon, the distance is negative. If the segment is tangent or intersecting, 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 segment to the given polygon and optionally the points on each shape that correspond to this shortest distance. If segment 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. segment is presumed to be expressed in the selected space of image.

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

If more than one pair of points on the polygon and segment have the same distance, the returned (segmentX, segmentY) and (polygonX, polygonY) pair is chosen arbitrarily among them.

See Also