Dim Pt1 As Variant
Dim Pt2 As Variant
Dim RectRotation As Double
Dim objPolyline As Object
Dim RectangPoint(0 To 11) As Double
' 获得第一点Pt1
Pt1 = ThisDrawing.Utility.GetPoint(, "指定起始点")
' 获得第二点Pt2
Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "指定结束点")
' 得到两点构成直线的的角度值
RectRotation = Atn((Pt2(1) - Pt1(1)) / (Pt2(0) - Pt1(0)))
' 根据Pt1、Pt2两点计算矩形各顶点坐标
RectangPoint(0) = Pt1(0) - RecHalfWidth * Sin(RectRotation)
RectangPoint(1) = Pt1(1) + RecHalfWidth * Cos(RectRotation)
RectangPoint(3) = Pt1(0) + RecHalfWidth * Sin(RectRotation)
RectangPoint(4) = Pt1(1) - RecHalfWidth * Cos(RectRotation)
RectangPoint(6) = Pt2(0) + RecHalfWidth * Sin(RectRotation)
RectangPoint(7) = Pt2(1) - RecHalfWidth * Cos(RectRotation)
RectangPoint(9) = Pt2(0) - RecHalfWidth * Sin(RectRotation)
RectangPoint(10) = Pt2(1) + RecHalfWidth * Cos(RectRotation)
Set objPolyline = ThisDrawing.ModelSpace.AddPolyline(RectangPoint)
objPolyline.Closed = True
Set DrawRectang = objPolyline
End Function
本帖最后由 crazylsp 于 2013-4-11 17:26 编辑
谢谢wlong的程序,不过画出是个旋转角度的不过这样也好,随机的美感,半宽其实不用设,可由pt1,pt2两个点计算出 http://bbs.mjtd.com/forum.php?mod=viewthread&tid=91464&highlight=%BB%AD%BE%D8%D0%CE
页:
[1]