作者sjgau (sjgau)
看板Fortran
标题Re: [心得] 让fortran 叫 AutoCAD 自动画图的方法
时间Tue Sep 9 12:11:35 2008
指令: area
指定第一个角点或 [物件(O)/加(A)/减(S)]: o
选取物件:
面积 = 1.984885,周长 = 6.619935
以上,是 AutoLISP 程式 叫AutoCAD 自动画出
sin() curve 後,叫 AutoCAD 计算曲线下面的面积
所得到的答案,可以作为 下面 check 之用。
AutoLISP 程式列表如下:
; file: plot-sin.lsp
; plot y= sin(x), from x1 to x2, step dx
; dx= (x2 - x1)/no
; no= ???
(setq x1 (getreal "\n x1=? (ex. 0.1) ")
x2 (getreal "\n x2=? (ex. 3.0) ")
no (getint "\n no=? (ex. 16) "))
; for x= x1 to x2 step dx
(setq dx (/ (- x2 x1) no)
x2 (+ x2 (/ dx 10.0)))
(setq x x1)
(command "spline")
(while (<= x x2)
(setq y (sin x))
(command (list x y))
(setq x (+ x dx))
); end while()
(command "" "" "")
(command "zoom" "e")
(princ)
; end of file
※ 引述《sjgau (sjgau)》之铭言:
: 先定义问题 和 过程 以及中间点的 检查方法
: plot y= sin(x), from x1 to x2, step dx
: dx= (x2 - x1)/no
: 限定 x1 < x2,
: x1, x2 >= 0, 而且 <= pi
: pi= 4.0*atan(1.0)
: no >= 10, 而且 <= 100
: 产生 (x, y) 的数据资料 放入 阵列之内
: 使用 辛普森积分 得到曲线下的面积
: 应该 大於 0, 小於 2.0, --> A1
: 将来 叫AutoCAD 自动画图以後
: 会得到面积 --> A2
: 两者应该一致
: OK, 请大家 拭目以待
: 有兴趣的 帮忙推一下
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.231.148.190