本帖最后由 highflybird 于 2022-9-23 19:16 编辑
这个是lisp求解示例代码:
这个解是精确解,不是迭代法。
- (defun c:test (/ A B C D H HP L M N P0 P1 P2 P3 P4 P5 P6 P7 S W X Y)
- (initget 9)
- (setq W (getdist "\n宽:"))
- (initget 9)
- (setq H (getdist "\n高:"))
- (initget 9)
- (setq L (getdist "\n边:"))
- (setq m (/ W L))
- (setq n (/ H L))
- (setq A (* -4 n))
- (setq B (+ (* n n) (* m m) -4))
- (setq C (+ n n))
- (setq D (- 1 (* m m)))
- (setq S nil)
- (foreach n (Math:quartic_Equation 4 A B C D)
- (setq x (car n))
- (setq y (cadr n))
- (if (and (equal y 0 1e-6) (> x 0))
- (setq s (cons (* x L) s))
- )
- )
- (princ "\n解是:")
- (princ s)
- (initget 9)
- (setq HP (* 0.5 pi))
- (setq p0 (getpoint "\n插入点:"))
- (setq p1 (polar p0 pi W))
- (setq p2 (polar p0 HP H))
- (setq p3 (polar p2 pi W))
- (Ent:Make_LWPoly (list p0 p1 p3 p2) T)
- (foreach x S
- (setq y (sqrt (- (* L L) (* x x))))
- (setq p4 (polar p0 HP x))
- (setq p5 (polar p0 pi y))
- (setq p6 (polar p3 HP (- x)))
- (setq p7 (polar p3 0 y))
- (Ent:Make_LWPoly (list p4 p5 p6 p7) T)
- )
- (princ)
- )
- (defun Ent:Make_LWPoly (pts closed /)
- (entmakeX
- (vl-list*
- '(0 . "LWPOLYLINE")
- '(100 . "AcDbEntity")
- '(100 . "AcDbPolyline")
- (cons 90 (length pts)) ;顶点个数
- (cons 70 (if closed 1 0)) ;闭合的
- (mapcar (function (lambda (x) (cons 10 x))) pts) ;多段线顶点
- )
- )
- )
|