找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1885|回复: 0

[VBA函数]:原创:正弦曲线

[复制链接]
发表于 2003-6-15 21:15:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
这是我第一次在这发贴!
本论坛中有一用LISP画正弦曲线的贴子,我编了两个VBA小程序,各位PP。

  1. Sub sin1()
  2. '由正弦曲线的起点、终点、幅度、周波数来画正弦曲线
  3. Dim sinObj As AcadLWPolyline
  4. Dim points() As Double
  5. Dim a, n, k As Integer
  6. Dim H, L As Double
  7. Dim pa, pb As Variant
  8. PI = 3.1415926535

  9. pa = ThisDrawing.Utility.GetPoint(, "请输入正弦曲线起点:")
  10. pb = ThisDrawing.Utility.GetPoint(pa, "请输入正弦曲线终点:")
  11. H = ThisDrawing.Utility.GetDistance(pa, "请正弦曲线幅度:")
  12. n = ThisDrawing.Utility.GetReal("请输入正弦曲线周波数:")
  13. k = ThisDrawing.Utility.GetReal("请输入正弦曲线每周波线段数(建议不小于36):")

  14. ReDim points(0 To 2 * k * n + 1) As Double
  15. L = dis(pa, pb)
  16. b = ThisDrawing.Utility.AngleFromXAxis(pa, pb)

  17. For a = 0 To 2 * k * n Step 2
  18. points(a) = pa(0) + L * (a / 2) / (k * n)
  19. points(a + 1) = pa(1) + H * Sin(2 * PI * a / k / 2)
  20. Next

  21. Set sinObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
  22. sinObj.Rotate pa, b
  23. ZoomExtents
  24. End Sub

  25. Public Function dis(pa, pb As Variant) As Double
  26. dis = ((pa(0) - pb(0)) ^ 2 + (pa(1) - pb(1)) ^ 2 + (pa(2) - pb(2)) ^ 2) ^ 0.5
  27. End Function


  1. Sub sin2()
  2. '由正弦曲线的起点、幅度、周期、周波数、方向来画正弦曲线
  3. Dim sinObj As AcadLWPolyline
  4. Dim points() As Double
  5. Dim a, n, k As Integer
  6. Dim H, f As Double
  7. Dim pa, pb As Variant
  8. PI = 3.1415926535

  9. pa = ThisDrawing.Utility.GetPoint(, "请输入正弦曲线起点:")
  10. H = ThisDrawing.Utility.GetDistance(pa, "请正弦曲线幅度:")
  11. f = ThisDrawing.Utility.GetDistance(pa, "请正弦曲线周期:")
  12. n = ThisDrawing.Utility.GetReal("请输入正弦曲线周波数:")
  13. k = ThisDrawing.Utility.GetReal("请输入正弦曲线每周波线段数(建议不小于36):")
  14. pb = ThisDrawing.Utility.GetPoint(pa, "请输入点以确定正弦曲线的方向:")

  15. ReDim points(0 To 2 * k * n + 1) As Double
  16. b = ThisDrawing.Utility.AngleFromXAxis(pa, pb)

  17. For a = 0 To 2 * k * n Step 2
  18. points(a) = pa(0) + f * (a / 2) / k
  19. points(a + 1) = pa(1) + H * Sin(2 * PI * a / k / 2)
  20. Next

  21. Set sinObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
  22. sinObj.Rotate pa, b
  23. ZoomExtents
  24. End Sub
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-23 01:54 , Processed in 0.375443 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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