jjfujj宝贝 发表于 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)
)
)

Gu_xl 发表于 2013-6-17 15:13:46

(setq y0 (* sin x0))   (setq y1(* sin x1))
==》
(setq y0 ( sin x0))   (setq y1( sin x1))

jjfujj宝贝 发表于 2013-6-17 16:04:48

Gu_xl 发表于 2013-6-17 15:13 static/image/common/back.gif
(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)这个写错了。

ZZXXQQ 发表于 2013-6-18 00:02:22

(defun c:inv (/ xmin xmax n dx h x0 y0 x1 y1)
(defun dtor (d) (/ (* d pi) 180))
(setq xmin (getreal "\n 输入起始角:"))
(setq xmax (getreal "\n 输入终止角:"))
(setq dx (getreal "\n 输入角度增量:"))
(setq h (getreal "\n输入幅值:"))
(setq n (fix (/ (- xmax xmin) dx)))
(setq dx (/ (- xmax xmin) n))
(setq x0 xmin)
(setq y0 (* (sin (dtor x0)) h))
(command "_.PLINE" "non" (list x0 y0))
(while (<= x0 xmax)
(setq x1 (+ x0 dx))
(setq y1 (* (sin (dtor x1)) h))
(command "non" (list x1 y1))
(setq x0 x1)
)
(command "")
(princ)
)

清风明月名字 发表于 2013-6-18 08:34:08

路过学习学习。谢谢5楼楼主分享!

jjfujj宝贝 发表于 2013-6-18 09:16:15

叮咚 发表于 2013-6-17 17:35 static/image/common/back.gif
角度是用弧度的。 要转换成弧度。 还有就是你的角度是有问题的,万一起始角大于终止角,就可能成死循环了
...

谢谢,

jjfujj宝贝 发表于 2013-6-18 09:17:28

ZZXXQQ 发表于 2013-6-18 00:02 static/image/common/back.gif


试了一下还是不行,和幅值有关系吗?

jjfujj宝贝 发表于 2013-6-18 09:52:12

谢谢楼上几位,可以运行了。
我的那种也可以,其实不用变换弧度的。你输的多少就默认成弧度了。比如6.28≈360度。
zzxxqq的也可以,他考虑了幅值的问题。
继续努力了。

风雨依然 发表于 2013-6-21 10:40:54

路过 学习 学习
页: [1]
查看完整版本: 高手帮忙看一下这个程序的问题?