明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1331|回复: 9

[已解答] 高手帮忙看一下这个程序的问题?

[复制链接]
发表于 2013-6-17 14:09:15 | 显示全部楼层 |阅读模式
用来画正弦函数图像的,运行总说参数错误
(defun c:inv(/ xmin xmax n dx x0 y0 x1 y1 )
  (setq xmin (getreal "\n 输入起始角:"))
  (setq xmax (getreal "\n 输入终止角:"))
  (setq dx (getreal "\n 输入角度增量:"))
  (setq n (fix(/(- xmax xmin)dx)))
  (setq dx (/ (- xmax xmin)n))
  (setq x0 xmin)
  (setq y0 (* sin x0))  
  (while (<= x0 xmax)
    (setq x1(+ x0 dx))
    (setq y1(* sin x1))
    (command "line"(list x0 y0)(list x1 y1)"")
    (setq x0 x1 x1 y1)
  )
)
发表于 2013-6-17 15:13:46 | 显示全部楼层
(setq y0 (* sin x0))   (setq y1(* sin x1))
==》
(setq y0 ( sin x0))   (setq y1( sin x1))
 楼主| 发表于 2013-6-17 16:04:48 | 显示全部楼层
Gu_xl 发表于 2013-6-17 15:13
(setq y0 (* sin x0))   (setq y1(* sin x1))
==》
(setq y0 ( sin x0))   (setq y1( sin x1))

改了,不过还是不行,没有图像啊?是不是程序不对?
发表于 2013-6-17 17:35:48 | 显示全部楼层
角度是用弧度的。 要转换成弧度。 还有就是你的角度是有问题的,万一起始角大于终止角,就可能成死循环了
(setq x0 x1 x1 y1)这个写错了。
发表于 2013-6-18 00:02:22 | 显示全部楼层
  1. (defun c:inv (/ xmin xmax n dx h x0 y0 x1 y1)
  2. (defun dtor (d) (/ (* d pi) 180))
  3. (setq xmin (getreal "\n 输入起始角:"))
  4. (setq xmax (getreal "\n 输入终止角:"))
  5. (setq dx (getreal "\n 输入角度增量:"))
  6. (setq h (getreal "\n输入幅值:"))
  7. (setq n (fix (/ (- xmax xmin) dx)))
  8. (setq dx (/ (- xmax xmin) n))
  9. (setq x0 xmin)
  10. (setq y0 (* (sin (dtor x0)) h))
  11. (command "_.PLINE" "non" (list x0 y0))
  12. (while (<= x0 xmax)
  13.   (setq x1 (+ x0 dx))
  14.   (setq y1 (* (sin (dtor x1)) h))
  15.   (command "non" (list x1 y1))
  16.   (setq x0 x1)
  17. )
  18. (command "")
  19. (princ)
  20. )
发表于 2013-6-18 08:34:08 | 显示全部楼层
路过学习学习。谢谢5楼楼主分享!

评分

参与人数 1明经币 +1 收起 理由
USER2128 + 1 谢谢鉴赏“整合多个GetXXX用户输入函数在一.

查看全部评分

 楼主| 发表于 2013-6-18 09:16:15 | 显示全部楼层
叮咚 发表于 2013-6-17 17:35
角度是用弧度的。 要转换成弧度。 还有就是你的角度是有问题的,万一起始角大于终止角,就可能成死循环了
...

谢谢,
 楼主| 发表于 2013-6-18 09:17:28 | 显示全部楼层
ZZXXQQ 发表于 2013-6-18 00:02

试了一下还是不行,和幅值有关系吗?
 楼主| 发表于 2013-6-18 09:52:12 | 显示全部楼层
谢谢楼上几位,可以运行了。
我的那种也可以,其实不用变换弧度的。你输的多少就默认成弧度了。比如6.28≈360度。
zzxxqq的也可以,他考虑了幅值的问题。
继续努力了。
发表于 2013-6-21 10:40:54 | 显示全部楼层
路过 学习 学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-29 03:16 , Processed in 0.218711 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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