蒹葭_Keirll 发表于 2013-1-6 09:38:12

感谢高飞兄,坐标系一直是个很难懂的问题

tjuzkj 发表于 2013-1-6 09:47:19

一直没理解这个函数,现在总算明白些了

仲文玉 发表于 2013-1-6 09:53:43

又一个神贴

hao3ren 发表于 2013-1-6 10:25:28

顶礼膜拜中

zyhandw 发表于 2013-1-6 11:40:31

太强了,收藏下来看看!

pzweng 发表于 2013-1-6 15:19:24

这个我有时候需研究一下,用entmake与vla-add创建块,始终平行于wcs,我现在一直用command来建块,头疼的事情了

chpmould 发表于 2013-1-6 18:22:58

来的晚了点,先支持一个,很好的总结帖

highflybir 发表于 2013-1-7 09:20:54

本帖最后由 highflybir 于 2013-1-7 14:56 编辑

http://www.theswamp.org/index.php?topic=12887.msg157305#msg157305
的原帖发于此处:
Hi,

Quote

(setq ins1 (trans (cdr (assoc 10 (entget e1))) 0 1))      ;get insertion point


This will work only if UCS XY plane is parallel to WCS XY plane.
Insertion point coordinates of a block or text are defined in OCS (Object Coordinates System).

The following codes will work whatever the current UCS and the entity OCS :

Code:
(setq ins1 (trans (cdr (assoc 10 (entget e1))) e1 1))or
Code:
(setq ins1 (trans (cdr (assoc 10 (entget e1))) (cdr (assoc 210 (entget e1))) 1))
A 2D entiy's OCS is calculated by AutoCAD regarding its extrusion direction (210 DXF code or Normal property) using an "arbitrary axis algorithm" (see "Advanced DXF concepts" in the DXF section of the Developper's guide).
You can calculate an entity's OCS using this code :


;;; OCS Calculates the OCS of a 2D entity (text, block, circle, arc, lwpolyline, hatch ...)
;;; Argument : zdir, a single unit vector as returned by 210 DXF code
(defun sco (zdir / xdir)
(if (and (< (abs (car zdir)) 0.015625)
         (< (abs (cadr zdir)) 0.015625)
      )
    (setq xdir (vunit (v^v '(0 1 0) zdir)))
    (setq xdir (vunit (v^v '(0 0 1) zdir)))
)
(list xdir (vunit (v^v zdir xdir)) zdir)
)

;;; VUNIT Returns the vector's single unit vector
;;; Argument : v, a vector
(defun vunit (v / l)
(if (/= 0 (setq l (sqrt (apply '+ (mapcar '* v v)))))
    (mapcar '(lambda (x) (/ x l)) v)
)
)

;;; V^V Returns the cross product of two vecors
;;; (the normal vector of the plane defined by v1 v2)
;;; Argument : v1 v2, two non-colinear vectors
(defun v^v (v1 v2)
(if (inters '(0 0 0) v1 '(0 0 0) v2)
    (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
      (- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
      (- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
    )
    '(0.0 0.0 0.0)
)
)


自贡黄明儒 发表于 2013-1-7 12:22:40

一直没有搞清楚trans的原理,谢谢高飞兄!

weiqi 发表于 2013-1-7 21:13:33

还看不懂,支持下先。最近忙得要死,没时间学习LISP
页: 1 [2] 3 4 5 6 7
查看完整版本: 【越飞越高讲堂16】CAD 的坐标系统和trans函数的工作原理