Knowing the center point coordinates, angle, half length, and half width of Retangle2, calculate the four vertex coordinates and the midpoint coordinates of the four line segments

Halcon can obtain the center point coordinates, angle, half-length, and half-width of Retangle2 through the minimum circumscribed rectangle operator. But there are no four vertex coordinates and four line segment midpoint coordinates. The following code is the method to obtain the coordinates of four vertices and the coordinates of the midpoint of four line segments.

gen_rectangle2 (Rectangle, 300, 200, 0.39, 100, 50)
CenterX:=200
CenterY:=300
JXPhi:=0.39
Len1:=100
Len2:=50

*矩形端点坐标变量,变中心坐标变量初始化
CornerX:=[]
CornerY:=[]
LineCenterY:=[]
LineCenterX:=[]
*临时变量初始化
RowT:=0
ColT:=0
*判断仿射矩形是否有效
if (Len1<=0 or Len2<=0)
return ( )
endif
*计算仿射矩形角度的正弦,余弦
tuple_cos(JXPhi,Cos)
tuple_sin(JXPhi,Sin)
*矩形第一个端点
ColT:=CenterX-Len1*Cos-Len2*Sin
RowT:=CenterY-(-Len1*Sin+Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
*矩形第二个端点
ColT:=CenterX+Len1*Cos-Len2*Sin
RowT:=CenterY-(Len1*Sin+Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
*矩形第三个端点
ColT:=CenterX+Len1*Cos+Len2*Sin
RowT:=CenterY-(Len1*Sin-Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
*矩形第四个端点
ColT:=CenterX-Len1*Cos+Len2*Sin
RowT:=CenterY-(-Len1*Sin-Len2*Cos)
CornerY:=[CornerY,RowT]
CornerX:=[CornerX,ColT]
dev_set_color ('white')
gen_cross_contour_xld (Cross, CornerY, CornerX, 10, 0.785398)

*矩形第一条边中心坐标
LineCenterY[0]:=(CornerY[0]+CornerY[1])*0.5
LineCenterX[0]:=(CornerX[0]+CornerX[1])*0.5
*矩形第二条边中心坐标
LineCenterY[1]:=(CornerY[1]+CornerY[2])*0.5
LineCenterX[1]:=(CornerX[1]+CornerX[2])*0.5
*矩形第三条边中心坐标
LineCenterY[2]:=(CornerY[3]+CornerY[2])*0.5
LineCenterX[2]:=(CornerX[3]+CornerX[2])*0.5
*矩形第四条边中心坐标
LineCenterY[3]:=(CornerY[3]+CornerY[0])*0.5
LineCenterX[3]:=(CornerX[3]+CornerX[0])*0.5
dev_set_color ('blue')
gen_cross_contour_xld (Cross1, LineCenterY, LineCenterX, 10, 0.785398)
return()

insert image description here

Supongo que te gusta

Origin blog.csdn.net/Douhaoyu/article/details/128557553
Recomendado
Clasificación