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

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

public static double DistanceSegmentLine(
	CogLineSegment segment,
	CogLine line,
	ICogImage image,
	out double segmentX,
	out double segmentY,
	out double lineX,
	out double lineY
)

Parameters

segment
Type: Cognex.VisionPro CogLineSegment

The line segment.

line
Type: Cognex.VisionPro CogLine

The line.

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 y-coordinate of the nearest point on the line segment.

lineX
Type: System Double 

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

lineY
Type: System Double 

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

Return Value

Type: Double

The shortest distance between the line and the line segment or zero if they are coincident or intersecting.

Exceptions

ExceptionCondition
ArgumentException

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

The following table describes how the relationship between line and segment affects the out parameters.

ConditionDistance(SegementX,segmentY)(lineX,lineY)

Parallel

The distance between segment and line.

A point on segment

A point on line

Non-intersecting

The shortest distance between segment and line.

The nearest point on segment

The nearest point on line

Coincident

0

(0,0)

(0,0)

Intersecting

0

(0,0)

(0,0)

If you supply a value for the image parameter, then segment and line are mapped to the selected space of image before the measurement is computed and the result is expressed in that space.

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

See Also