(defun c:text1() (setq J1 (getpoint "\n请输入三角形左下角点:")) (setq A (getreal "\n请输入三角形底边长:")) (setq B (getreal "\n请输入三角形左邻边长:")) (setq C (getreal "\n请输入三角形右邻边长:")) (setq S (/(+(+ A B)C)2)) (setq AREA (sqrt((*(*(* S (- S A))(- S B )(- S C)))))) (setq H (/(* 2 AREA)A)) (setq D (sqrt (-(* C C)(* H H)))) (setq Ang1 (atan(/ H D))) (setq Ang1 (* Ang1 (/ 180 pi))) (setq J2 (polar J1 0 A)) (setq J3 (polar J1 Ang1 C)) (command "pline" J1 J2 J3 "c") (prin1) )
根据你的已知条件应该是求不出三角形的,不过按你的程序意思倒是可以了,这个样子就很简单了,你为什么会做的那么复杂?数学不够扎实啊...
三角形的三边是有限制的,你最好在程序里做个判断:
(defun c:text1( / J1 A B C cosA sinA <A) (setq J1 (getpoint "\n请输入三角形左下角点:")) (setq A (getreal "\n请输入三角形底边长:")) (setq B (getreal "\n请输入三角形左邻边长:")) (setq C (getreal "\n请输入三角形右邻边长:")) (setq cosA (/ (- (+ (expt A 2) (expt B 2)) (expt C 2)) (* 2 A B))) (if (= cosA 0) (setq <A (/ pi 2)) (progn (setq sinA (sqrt (- 1 (expt cosA 2)))) (setq <A (atan (/ sinA cosA))) ) ) (command "_.pline" J1 (polar J1 0 A) (polar J1 <A B) "cl") (princ) )
小妹谢谢哥哥的指教.你批评得对.呵呵.我在晓东cad上也问了这个问题.
有几位朋友得指教也很好.我真是学到很多东西.
;;;;;;;;;;
(defun c:text1 () (setq J1 (getpoint "\n请输入三角形左下角点:") A (getdist J1 "\n请输入三角形底边长:") B (getdist J1 "\n请输入三角形左邻边长:") J2 (polar J1 0 A) C (getdist J2 "\n请输入三角形右邻边长:") S (/ (+ A B C) 2) AREA (sqrt (* S (- S A) (- S B) (- S C))) H (/ (* 2 AREA) A) D (sqrt (- (* B B) (* H H))) Ang1 (atan (/ H D)) J3 (polar J1 Ang1 B) ) (command "pline" J1 J2 J3 "c") (princ) )
;;;;;;;;;;
(defun c:text1 () (if (and (setq J1 (getpoint "\n请输入三角形左下角点:")) (setq A (getdist j1 "\n请输入三角形底边长:")) (setq J2 (polar j1 0.0 A)) (setq B (getdist j1 "\n请输入三角形左邻边长:")) (setq C (getdist j2 "\n请输入三角形右邻边长:")) (setq S (/ (+ A B C) 2.0)) (> s a) (> s b) (> s c) ) (progn (setq J3x (* B (/ (- (+ (* B B) (* A A)) (* C C)) (* 2.0 A B)))) (setq J3y (sqrt (- (* B B) (* j3x j3x)))) (setq j3 (list (+ (car j1) j3x) (+ (cadr j1) j3y))) (command "pline" J1 J2 J3 "c") ) (princ "\n数据有误,程序退出!") ) (princ) )