CogMath DistancePointSegment Method Cognex VisionPro
Returns the shortest distance from the given point to the given line segment. Also provides the closest point on the line segment.

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

public static double DistancePointSegment(
	double x,
	double y,
	CogLineSegment segment,
	ICogImage image,
	out double segmentX,
	out double segmentY
)

Parameters

x
Type: System Double

The x-coordinate of the point.

y
Type: System Double

The y-coordinate of the point.

segment
Type: Cognex.VisionPro CogLineSegment

The line segment.

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. If the point is on the line segment, this value is the same as x.

segmentY
Type: System Double 

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

Return Value

Type: Double

The shortest distance from the point (x,y) to the line segment. If the point is on the line segment, the distance is zero.

Exceptions

ExceptionCondition
ArgumentException

segment 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 line segment and optionally the closest point on the line segment.

If you supply a value for the image parameter, then segment 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 segment, x, and y are presumed to be in the same coordinate space.

See Also