判断随机生成的闭合多段线是否相交
Sub polygon()Dim myselect(1 To 90) As AcadEntity '定义选择集数组
Dim num As Integer
Dim pnt As Variant
Dim lpnt As Variant
num = 20 '正多边形边数
Dim fpnt(0 To 2) As Double '起点坐标
Dim leng As Double
Dim i As Long
For i = 1 To 90 '循环90次
fpnt(0) = 100 * Rnd: fpnt(1) = 100 * Rnd: fpnt(2) = 0 '起点随机坐标
leng = 3 * Rnd '边长随机长度
ReDim lpnt(0 To num * 2 - 1) As Double '下面是画正多边形
pnt = fpnt
lpnt(0) = pnt(0)
lpnt(1) = pnt(1)
Dim st As Integer
For st = 1 To num - 1
pnt = ThisDrawing.Utility.PolarPoint(pnt, (3.14159265 * 2 / num) * (st - 1), leng)
lpnt(st * 2) = pnt(0)
lpnt(st * 2 + 1) = pnt(1)
Next st
Dim pgon As AcadLWPolyline
Set pgon = ThisDrawing.ModelSpace.AddLightWeightPolyline(lpnt)
pgon.Closed = True
Next i
ThisDrawing.Regen (True)
End Sub
本人新手一枚,上面是随机生成多边形的源码,但是在生成过程中各多边形会发生相交,想请教一下怎么才能让每一个多边形与相邻的多边形都不发生相交,求指点。
页:
[1]