三角函数在图形学里的应用(五) 把直线移动到指定点

(应用6)已经直线的起始端点与终止端点,把这条直线移动到指定的点


勇哥先放上halcon写的函数moveline的代码,它的作用是把一条线移动到指定的点。

resultLineStartPointRow := 0
resultLineStartPointCol := 0
resultLineEndPointRow := 0
resultLineEndPointCol := 0
projection_pl(pointRow, pointCol, lineStartPointRow, lineStartPointCol, lineEndPointRow, lineEndPointCol, RowProj, ColProj)
disp_circle(winhandle, RowProj, ColProj, 12)
distance_pp(RowProj, ColProj, lineStartPointRow, lineStartPointCol, DistanceA)
distance_pp(RowProj, ColProj, lineEndPointRow, lineEndPointCol, DistanceB)
angle_lx(RowProj, ColProj, lineStartPointRow, lineStartPointCol, Angle)
disp_line(winhandle, RowProj, ColProj, lineStartPointRow, lineStartPointCol)
disp_line(winhandle, RowProj, ColProj, lineEndPointRow, lineEndPointCol)
disp_line(winhandle,RowProj, ColProj,pointRow, pointCol)
tuple_deg(Angle, Deg)
if(0<=Deg and Deg<=90)
    row1:=DistanceA*sin(Angle)
    col1:=DistanceA*cos(Angle)
    resultLineStartPointRow:=pointRow-row1
    resultLineStartPointCol:=pointCol+col1
elseif(Deg>90 and Deg<=180)
    row1:=DistanceA*sin(3.1415926-Angle)
    col1:=DistanceA*cos(3.1415926-Angle)
    resultLineStartPointRow:=pointRow-row1
    resultLineStartPointCol:=pointCol-col1
elseif(Deg<0 and Deg>=-90)
    row1:=DistanceA*sin(Angle)
    col1:=DistanceA*cos(Angle)
    resultLineStartPointRow:=pointRow+row1
    resultLineStartPointCol:=pointCol+col1
elseif(Deg<-90 and Deg>=-180)
    row1:=DistanceA*sin(3.1415926+Angle)
    col1:=DistanceA*cos(3.1415926+Angle)
    resultLineStartPointRow:=pointRow+row1
    resultLineStartPointCol:=pointCol-col1
endif
disp_circle(winhandle, resultLineStartPointRow, resultLineStartPointCol, 12)

angle_lx(RowProj, ColProj, lineEndPointRow, lineEndPointCol, Angle)
tuple_deg(Angle, Deg)
if(0<=Deg and Deg<=90)
    row1:=DistanceB*sin(Angle)
    col1:=DistanceB*cos(Angle)
    resultLineEndPointRow:=pointRow-row1
    resultLineEndPointCol:=pointCol+col1
elseif(Deg>90 and Deg<=180)
    row1:=DistanceB*sin(3.1415926-Angle)
    col1:=DistanceB*cos(3.1415926-Angle)
    resultLineEndPointRow:=pointRow-row1
    resultLineEndPointCol:=pointCol-col1
elseif(Deg<0 and Deg>=-90)
    tuple_abs(Angle, Abs)
    row1:=DistanceB*sin(Abs)
    col1:=DistanceB*cos(Abs)
    resultLineEndPointRow:=pointRow+row1
    resultLineEndPointCol:=pointCol+col1
elseif(Deg<-90 and Deg>=-180)
    row1:=DistanceB*sin(3.1415926+Angle)
    col1:=DistanceB*cos(3.1415926+Angle)
    resultLineEndPointRow:=pointRow+row1
    resultLineEndPointCol:=pointCol-col1
endif
disp_circle(winhandle, resultLineEndPointRow, resultLineEndPointCol, 12)


return ()


调用示例:

 moveline(4782,2240,outValue[0], outValue[1], outValue[2], outValue[3],WindowHandle,row1,col1,row2,col2)

其中参数WindowHandle只是用于测试时在屏幕上画线用的调试用。正式版本请去掉它。

4782,2240  是要线要移动到的点的坐标

outValue[0], outValue[1], outValue[2], outValue[3] 是线条的起始点、结束点的行列坐标。

row1,col1,row2,col2 是移动后线条的起始点、结束点的行列坐标。


结果如下图所示:

原来的线条已经移动到指定的点。

image.png



相同作用的C#代码参见勇哥的贴子《已知直线的起始端点与终止端点,移动到指定点的位置(C#代码演示)



--------------------- 

作者:hackpig
来源:
www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!




本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864