kapat 发表于 2022-7-5 23:59:58

uni中圆的象限

大家好。
我一直在努力跟上我能听懂的所有Lisp程序的情况,而且我在这方面做得越来越好。如此之多,我已经写了一些没有任何帮助!
 
但唉,我迟早会失败的。所以我爬回来了。
 
我写了这个小口吃。我确信有50种不同的版本,它是在这3个点的UCS内制作一个3点圆,而不需要手动更改UCS。
 
此处显示:
 


;        3 point circle maker!!!!
;        11/06/13
;        Patrick Mitchell
;        kapatrick@gmail.com
; picks 3 points, makes those their own UCS and makes a circle in 1 easy step!
;
;

(defun c:3PC (/ p1 p2 p3 wp1 wp2 wp3)
(while ;start while

(setq p1 (getpoint "point1"))
(setq p2 (getpoint "point2"))
(setq p3 (getpoint "point3"))

(setq wp1 (trans p1 1 0))
(setq wp2 (trans p2 1 0))
(setq wp3 (trans p3 1 0))

(command "_ucs" "3p" p1 p2 p3)

(command "CIRCLE" "3P" (trans wp1 0 1) (trans wp2 0 1) (trans wp3 0 1))
(command "._ucs" "_w")

(princ)
) ;end while
)


 
(旁注:我无法让“entmake”以这种方式工作。由于某种原因,我无法让DXF代码和“trans 0 1”工作。我通常喜欢使用entmake,这样我可以命名我的圆和线,并引用它们。)
 
现在,这里是它变得棘手的地方。因为我想“改进”它,但非常具体。
 
我想我需要的大部分代码都可以与“assoc”和“mapcar”一起使用。
 
我在寻找一种方法,当我创建这些圆时,我在寻找这些圆的象限,但在WCS中。据我猜测,这可能是不可能的。因为在WCS中,无法拾取在唯一UCS中生成的圆的象限。到目前为止,我不得不通过在它旁边创建一个圆来伪造它,并根据我的完美圆旋转一些象限线。
 
有什么想法吗?或者我希望有人告诉我这是不可能的,所以我不会在两周内追逐白日梦。
 
谢谢你的时间!

Lee Mac 发表于 2022-7-6 00:25:53

以下示例应在所有UCS和视图中正确执行:
 

(defun c:3pc ( / cn cr nv p1 p2 p3 rd )
   (if
       (and
         (setq p1 (getpoint "\n1st point: "))
         (setq p2 (getpoint "\n2nd point: " p1))
         (setq p3 (getpoint "\n3rd point: " p2))
       )
       (if (setq cr (LM:3PCircle p1 p2 p3))
         (progn
               (setq nv (trans '(0.0 0.0 1.0) 1 0 t)
                     cn (trans (car cr) 1 nv)
                     rd (cadr cr)
               )
               (entmake
                   (list
                      '(0 . "CIRCLE")
                     (cons 010 cn)
                     (cons 040 rd)
                     (cons 210 nv)
                   )
               )
               (foreach x
                   (list
                     (list rd 0.0 0.0)
                     (list 0.0 rd 0.0)
                     (list (- rd) 0.0 0.0)
                     (list 0.0 (- rd) 0.0)
                   )
                   (entmake
                     (list
                        '(0 . "POINT")
                           (cons 010 (trans (mapcar '+ cn x) nv 0))
                           (cons 210 nv)
                     )
                   )
               )
         )
         (princ "\nPoints are collinear.")
       )
   )
   (princ)
)

;; 3-Point Circle-Lee Mac
;; Returns the Center and Radius of the Circle defined by the supplied three points.

(defun LM:3PCircle ( p1 p2 p3 / a b c d )
   (setq p2 (mapcar '- p2 p1)
         p3 (mapcar '- p3 p1)
         a(* 2.0 (- (* (car p2) (cadr p3)) (* (cadr p2) (car p3))))
         b(distance '(0.0 0.0) p2)
         c(distance '(0.0 0.0) p3)
         b(* b b)
         c(* c c)
   )
   (if (not (equal 0.0 a 1e-)
       (list
         (setq d
               (mapcar '+ p1
                   (list
                     (/ (- (* (cadr p3) b) (* (cadr p2) c)) a)
                     (/ (- (* (carp2) c) (* (carp3) b)) a)
                     0.0
                   )
               )
         )
         (distance d p1)
       )
   )
)

kapat 发表于 2022-7-6 00:45:49

李,你再次令我惊叹。够近了!

Lee Mac 发表于 2022-7-6 01:03:59

不客气Patrick
页: [1]
查看完整版本: uni中圆的象限