Press ESC to close

【Halcon 计算点到直线和点到直线延长线的距离】

Halcon 计算点到直线和点到直线延长线的距离

提示:Halcon计算点到直线的距离、(验证精度)点到直线延长线的距离

前言

实际项目进展过程中会应用到,计算直线与直线,点与直线距离计算,偶然发现,相同的计算条件,采取计算方式不同,得取的结果会存在偏差。以下仅供参考,讨论,具体哪种方式更加合理,有待讨论。

提示:以下是本篇文章正文内容,下面案例可供参考

一、点到直线的距离

计算点到直线的距离:140.828753

*获取窗口句柄

dev_get_window (WindowHandle)

dev_set_color ('yellow')

*绘制点

draw_point (WindowHandle, Row2, Column2)

gen_cross_contour_xld (Cross2, Row2, Column2, 6, 0.785398)

dev_set_color ('blue')

*绘制直线

draw_line (WindowHandle, Row11, Column11, Row21, Column21)

*Store input lines as regions.

gen_region_line (RegionLines, Row11, Column11, Row21, Column21)

* Calculate the center of gravity, length, and orientation of a line.

line_position (Row11, Column11, Row21, Column21, RowCenter, ColCenter, Length, Phi1)

*计算点和线之间的距离

distance_pl (Row2, Column2, Row11, Column11, Row21, Column21, Distance1)

disp_message (WindowHandle, Distance1, 'window', RowCenter, ColCenter, 'red', 'true')

stop ()

二、点到直线延长线的距离

计算点到直线延长线的距离:141.145246

*获取窗口句柄

dev_get_window (WindowHandle)

dev_set_color ('yellow')

*绘制点

draw_point (WindowHandle, Row2, Column2)

gen_cross_contour_xld (Cross2, Row2, Column2, 6, 0.785398)

dev_set_color ('blue')

*绘制直线

draw_line (WindowHandle, Row11, Column11, Row21, Column21)

*Store input lines as regions.

gen_region_line (RegionLines, Row11, Column11, Row21, Column21)

* Calculate the center of gravity, length, and orientation of a line.

line_position (Row11, Column11, Row21, Column21, RowCenter, ColCenter, Length, Phi1)

gen_contour_region_xld (RegionLines, LinesContours, 'border')

elliptic_axis_points_xld (LinesContours, Ra3, Rb3, Phi)

*获取直线中点

area_center_points_xld (LinesContours, LinesArea, LinesRowCenter, LinesColCenter)

***********************生成延长线*************************

*延长线长度

LineLength:=1000

*起点

NewRowStart := LinesRowCenter-cos(Phi+1.5708)*LineLength

NewColStart := LinesColCenter-sin(Phi+1.5708)*LineLength

*终点

NewRowEnd := LinesRowCenter-cos(Phi-1.5708)*LineLength

NewColEnd := LinesColCenter-sin(Phi-1.5708)*LineLength

gen_region_line (NewLine, NewRowStart, NewColStart, NewRowEnd, NewColEnd)

dev_display (NewLine)

distance_pl (Row2, Column2, NewRowStart, NewColStart, NewRowEnd, NewColEnd, Distance)

disp_message (WindowHandle, Distance, 'window', RowCenter, ColCenter, 'red', 'true')

stop ()

总结

提示:仅供参考

此测试,仅供验证测量方式的精度,如您有更合理的方式计算,还请提出更正建议。