- UID
- 25232
- 积分
- 2113
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-1-12
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这是我第一次在这发贴!
本论坛中有一用LISP画正弦曲线的贴子,我编了两个VBA小程序,各位PP。
- Sub sin1()
- '由正弦曲线的起点、终点、幅度、周波数来画正弦曲线
- Dim sinObj As AcadLWPolyline
- Dim points() As Double
- Dim a, n, k As Integer
- Dim H, L As Double
- Dim pa, pb As Variant
- PI = 3.1415926535
- pa = ThisDrawing.Utility.GetPoint(, "请输入正弦曲线起点:")
- pb = ThisDrawing.Utility.GetPoint(pa, "请输入正弦曲线终点:")
- H = ThisDrawing.Utility.GetDistance(pa, "请正弦曲线幅度:")
- n = ThisDrawing.Utility.GetReal("请输入正弦曲线周波数:")
- k = ThisDrawing.Utility.GetReal("请输入正弦曲线每周波线段数(建议不小于36):")
- ReDim points(0 To 2 * k * n + 1) As Double
- L = dis(pa, pb)
- b = ThisDrawing.Utility.AngleFromXAxis(pa, pb)
- For a = 0 To 2 * k * n Step 2
- points(a) = pa(0) + L * (a / 2) / (k * n)
- points(a + 1) = pa(1) + H * Sin(2 * PI * a / k / 2)
- Next
- Set sinObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
- sinObj.Rotate pa, b
- ZoomExtents
- End Sub
- Public Function dis(pa, pb As Variant) As Double
- dis = ((pa(0) - pb(0)) ^ 2 + (pa(1) - pb(1)) ^ 2 + (pa(2) - pb(2)) ^ 2) ^ 0.5
- End Function
- Sub sin2()
- '由正弦曲线的起点、幅度、周期、周波数、方向来画正弦曲线
- Dim sinObj As AcadLWPolyline
- Dim points() As Double
- Dim a, n, k As Integer
- Dim H, f As Double
- Dim pa, pb As Variant
- PI = 3.1415926535
- pa = ThisDrawing.Utility.GetPoint(, "请输入正弦曲线起点:")
- H = ThisDrawing.Utility.GetDistance(pa, "请正弦曲线幅度:")
- f = ThisDrawing.Utility.GetDistance(pa, "请正弦曲线周期:")
- n = ThisDrawing.Utility.GetReal("请输入正弦曲线周波数:")
- k = ThisDrawing.Utility.GetReal("请输入正弦曲线每周波线段数(建议不小于36):")
- pb = ThisDrawing.Utility.GetPoint(pa, "请输入点以确定正弦曲线的方向:")
- ReDim points(0 To 2 * k * n + 1) As Double
- b = ThisDrawing.Utility.AngleFromXAxis(pa, pb)
- For a = 0 To 2 * k * n Step 2
- points(a) = pa(0) + f * (a / 2) / k
- points(a + 1) = pa(1) + H * Sin(2 * PI * a / k / 2)
- Next
- Set sinObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
- sinObj.Rotate pa, b
- ZoomExtents
- End Sub
|
|