明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: highflybir

[【高飞鸟】] 【越飞越高讲堂16】CAD 的坐标系统和trans函数的工作原理

    [复制链接]
发表于 2013-1-6 09:38 | 显示全部楼层
感谢高飞兄,坐标系一直是个很难懂的问题
发表于 2013-1-6 09:47 | 显示全部楼层
一直没理解这个函数,现在总算明白些了
发表于 2013-1-6 09:53 | 显示全部楼层
又一个神贴
发表于 2013-1-6 10:25 | 显示全部楼层
顶礼膜拜中
发表于 2013-1-6 11:40 | 显示全部楼层
太强了,收藏下来看看!
发表于 2013-1-6 15:19 | 显示全部楼层
这个我有时候需研究一下,用entmake与vla-add创建块,始终平行于wcs,我现在一直用command来建块,头疼的事情了
发表于 2013-1-6 18:22 | 显示全部楼层
来的晚了点,先支持一个,很好的总结帖
 楼主| 发表于 2013-1-7 09:20 | 显示全部楼层
本帖最后由 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: [Select]
(setq ins1 (trans (cdr (assoc 10 (entget e1))) e1 1))or
Code: [Select]
(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 | 显示全部楼层
一直没有搞清楚trans的原理,谢谢高飞兄!
发表于 2013-1-7 21:13 | 显示全部楼层
还看不懂,支持下先。最近忙得要死,没时间学习LISP
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-21 13:34 , Processed in 0.461835 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表