明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 685|回复: 1

随机生成不规则多边形

[复制链接]
发表于 2017-12-7 10:22:41 | 显示全部楼层 |阅读模式
Sub polygon()
Dim myselect(1 To 20) As AcadEntity '定义选择集数组
Dim num As Integer
Dim pnt As Variant
Dim lpnt As Variant
num = 10 '正多边形边数
Dim fpnt(0 To 2) As Double '起点坐标
Dim leng As Double
Dim i As Long
For i = 1 To 20 '循环20次
fpnt(0) = 100 * Rnd: fpnt(1) = 100 * Rnd: fpnt(2) = 0 '起点随机坐标
leng = 10 * 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

上面是随机画正多边形的源码,先请教一下怎么修改,才能画出不规则多边形?在线等~~~~~
 楼主| 发表于 2017-12-7 12:50:47 | 显示全部楼层
只要能画出不规则多边形就可以了,比如周长是100cm,边数任意,求编写思路~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 07:18 , Processed in 0.160919 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表