
AUTO LISP小程序
请按照图片帮我改个程序我把三角形高求出来了可是绘出的图形总是有2个边符合输入值第三条边就是输入的b值总对不上(defunc:sbx(/p1p2p3abcphdang1)(...
请按照图片帮我改个程序 我把三角形高求出来了 可是绘出的图形总是有2个边符合输入值 第三条边就是 输入的b值总对不上
(defun c:sbx (/ p1 p2 p3 a b c p h d ang1 )
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setq p1 (getpoint "请输入基点:"))
(setq a (getdist "\n请输入a=:"))
(setq b (getdist "\n请输入b=:"))
(setq c (getdist "\n请输入c=:"))
(setq p (/ (+ a b c) 2))
(setq h (sqrt (/ (* (* 4 p) (- p a) (- p b) (- p c)) (* a a)))) 海伦定理
(setq d (sqrt (- (* c c) (* h h))))
(setq ang1 (atan h d))
(setq p3 (polar p1 (* ang1 (/ 180 pi )) c))
(setq p2 (polar p1 0 a))
(command "line" p1 p2 p3 "c")
(prin1)
)
不知道还要添加哪些东西 万分感谢! 展开
(defun c:sbx (/ p1 p2 p3 a b c p h d ang1 )
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setq p1 (getpoint "请输入基点:"))
(setq a (getdist "\n请输入a=:"))
(setq b (getdist "\n请输入b=:"))
(setq c (getdist "\n请输入c=:"))
(setq p (/ (+ a b c) 2))
(setq h (sqrt (/ (* (* 4 p) (- p a) (- p b) (- p c)) (* a a)))) 海伦定理
(setq d (sqrt (- (* c c) (* h h))))
(setq ang1 (atan h d))
(setq p3 (polar p1 (* ang1 (/ 180 pi )) c))
(setq p2 (polar p1 0 a))
(command "line" p1 p2 p3 "c")
(prin1)
)
不知道还要添加哪些东西 万分感谢! 展开
2个回答
展开全部
1.首先,同LZ说的,你OSMODE没弄成0,不过我觉得你出的错在于,你求的角度有问题,程序里你求的是角B,就是b对应着的角,而ATAN的范围是(-PI/2 PI/2),在没判别角的大小时,角B是有可能钝角的,所以就出错了,最好是把ABC按照大小排一下,按你程序里,把b弄成最小的角,就没问题了.
2.在程序前面加个判别能否形成三角形的语句,就是最小+次小>最大的那个.
3.程序末尾最好加个(PROMPT"")语句,标明怎么运行这个程序,不然加载了你这个程序不知道怎么打开.
刚才又看了下,发现你setq p3 (polar p1 (* ang1 (/ 180 pi )) c))这一句也有问题,ATAN返回的本来就是弧度值,而polar也是用弧度值的
祝LZ早日学成~ 附程序,还有缺陷,*ERROR*参数没设置,嫌麻烦
(defun c:sbx (/ p1 p2 p3 a b c p h d ang1)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setq p1 (getpoint "请输入基点:"))
(setq a (getdist "\n请输入a=:"))
(setq b (getdist "\n请输入b=:"))
(setq c (getdist "\n请输入c=:"))
(setq c1 (max a b c)
b1 (min a b c)
)
(foreach temp (list a b c)
(if (and (< temp c1) (> temp b1))
(setq a1 temp)
)
)
(if (< (+ a1 b1) c1)
(princ "出错,输入的三边不能组成三角形")
(progn
(setq p (/ (+ a b c) 2))
(setq h (sqrt (/ (* (* 4 p) (- p a) (- p b) (- p c)) (* a1 a1))))
(setq d (sqrt (- (* c1 c1) (* h h))))
(setq ang1 (atan h d))
(setq p3 (polar p1 ang1 c1))
(setq p2 (polar p1 0 a1))
(command "line" p1 p2 p3 "c")
)
)
(setvar "osmode" oldos)
(prin1)
)
(prompt"********************输入sbx以开始程序********************")
(princ)
2.在程序前面加个判别能否形成三角形的语句,就是最小+次小>最大的那个.
3.程序末尾最好加个(PROMPT"")语句,标明怎么运行这个程序,不然加载了你这个程序不知道怎么打开.
刚才又看了下,发现你setq p3 (polar p1 (* ang1 (/ 180 pi )) c))这一句也有问题,ATAN返回的本来就是弧度值,而polar也是用弧度值的
祝LZ早日学成~ 附程序,还有缺陷,*ERROR*参数没设置,嫌麻烦
(defun c:sbx (/ p1 p2 p3 a b c p h d ang1)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setq p1 (getpoint "请输入基点:"))
(setq a (getdist "\n请输入a=:"))
(setq b (getdist "\n请输入b=:"))
(setq c (getdist "\n请输入c=:"))
(setq c1 (max a b c)
b1 (min a b c)
)
(foreach temp (list a b c)
(if (and (< temp c1) (> temp b1))
(setq a1 temp)
)
)
(if (< (+ a1 b1) c1)
(princ "出错,输入的三边不能组成三角形")
(progn
(setq p (/ (+ a b c) 2))
(setq h (sqrt (/ (* (* 4 p) (- p a) (- p b) (- p c)) (* a1 a1))))
(setq d (sqrt (- (* c1 c1) (* h h))))
(setq ang1 (atan h d))
(setq p3 (polar p1 ang1 c1))
(setq p2 (polar p1 0 a1))
(command "line" p1 p2 p3 "c")
)
)
(setvar "osmode" oldos)
(prin1)
)
(prompt"********************输入sbx以开始程序********************")
(princ)

2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询