Calculate the shortest distance between line and point

Overview

This example calculates the shortest distance between line and point, and displays the value in Text Window.

Specification of this example


Behavior
Get the approximate line and reference position from [Scan Edge Position] unit.
And calculate shortest distance between line and point, and display it in Text Window.

Screenshot


How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
refFile

2.Right-click and hold on the zip file, and drop it on working window of FJ system. The images and scene data in zip file are loaded on the program automatically.

3.Re-measure the image. Then System automatically calculates the shortest distance of approximate line and reference position which and display in Text Window.

How to implement

Scene data
Unit No.
Processing Item
0.
Camera Image Input
1.
Scan Edge Position
2.
Macro
The Macro Program below segment is to be set in '2.Macro'.
Macro Program
*MEASUREPROC
    MYUNIT& = UnitNo

    SX# = UnitData(MYUNIT& - 1,"SX")                                 '(1)
    SY# = UnitData(MYUNIT& - 1,"SY")
    A# = UnitData(MYUNIT& - 1,"A")
    B# = UnitData(MYUNIT& - 1,"B")
    C# = UnitData(MYUNIT& - 1,"C")

    LEN# = Abs( A# * SX# + B# * SY# + C#) / Sqr(A# * A# + B# * B#)   '(2)
Return

*MEASUREDISPT
    DrawText "Shortest Distance = " + Str$(LEN#), 1, 1               '(3)
Return

The macro program is in refthis link.
Explanation
(1)Get measurement results of previous unit via external reference data.
(2)Calculate the shortest distance of a point and a line.
(3)Display the shortest distance in Text Window.