明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: jxphklibin

【求助】如何:获得图块的矩阵

  [复制链接]
发表于 2009-2-22 12:50:00 | 显示全部楼层
本帖最后由 作者 于 2009-2-22 12:56:10 编辑

  1. ;; TransNested (gile)
  2. ;; Translates a point coordinates from WCS or UCS to RCS -coordinates system of a
  3. ;; reference (xref or block) whatever its nested level-
  4. ;;
  5. ;; Arguments
  6. ;; pt : the point to translate
  7. ;; rlst : the parents entities list from the deepest nested to the one inserted in
  8. ;;        current space -same as (last (nentsel)) or (last (nentselp))
  9. ;; from to : as with trans function: 0 for WCS, 1 for current UCS, 2 for RCS
  10. (defun TransNested (pt rlst from to)
  11.   (and (= 1 from) (setq pt (trans pt 1 0)))
  12.   (and (= 2 to) (setq rlst (reverse rlst)))
  13.   (and (or (= 2 from) (= 2 to))
  14.        (while rlst
  15. (setq geom (if    (= 2 to)
  16.       (RevRefGeom (car rlst))
  17.       (RefGeom (car rlst))
  18.     )
  19.        rlst (cdr rlst)
  20.        pt   (mapcar '+ (mxv (car geom) pt) (cadr geom))
  21. )
  22.        )
  23.   )
  24.   (if (= 1 to)
  25.     (trans pt 0 1)
  26.     pt
  27.   )
  28. )
  29. ;; RefGeom (gile)
  30. ;; Returns a list which first item is a 3x3 transformation matrix (rotation,
  31. ;; scales, normal) and second item the object insertion point in its parent
  32. ;; (xref, bloc or space)
  33. ;;
  34. ;; Argument : an ename
  35. (defun RefGeom (ename / elst ang norm mat)
  36.   (setq    elst (entget ename)
  37. ang  (cdr (assoc 50 elst))
  38. norm (cdr (assoc 210 elst))
  39.   )
  40.   (list
  41.     (setq mat
  42.    (mxm
  43.      (mapcar (function (lambda (v) (trans v 0 norm T)))
  44.      '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
  45.      )
  46.      (mxm
  47.        (list (list (cos ang) (- (sin ang)) 0.0)
  48.      (list (sin ang) (cos ang) 0.0)
  49.      '(0.0 0.0 1.0)
  50.        )
  51.        (list (list (cdr (assoc 41 elst)) 0.0 0.0)
  52.      (list 0.0 (cdr (assoc 42 elst)) 0.0)
  53.      (list 0.0 0.0 (cdr (assoc 43 elst)))
  54.        )
  55.      )
  56.    )
  57.     )
  58.     (trans
  59.       (mapcar
  60. '-
  61. (cdr (assoc 10 elst))
  62. (mxv mat
  63.      (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 elst)))))
  64. )
  65.       )
  66.       norm
  67.       0
  68.     )
  69.   )
  70. )
  71. ;; RevRefGeom (gile)
  72. ;; RefGeom inverse function
  73. (defun RevRefGeom (ename / entData ang norm mat)
  74.   (setq    entData    (entget ename)
  75. ang    (- (cdr (assoc 50 entData)))
  76. norm    (cdr (assoc 210 entData))
  77.   )
  78.   (list
  79.     (setq mat
  80.    (mxm
  81.      (list (list (/ 1 (cdr (assoc 41 entData))) 0.0 0.0)
  82.    (list 0.0 (/ 1 (cdr (assoc 42 entData))) 0.0)
  83.    (list 0.0 0.0 (/ 1 (cdr (assoc 43 entData))))
  84.      )
  85.      (mxm
  86.        (list (list (cos ang) (- (sin ang)) 0.0)
  87.      (list (sin ang) (cos ang) 0.0)
  88.      '(0.0 0.0 1.0)
  89.        )
  90.        (mapcar (function (lambda (v) (trans v norm 0 T)))
  91.        '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
  92.        )
  93.      )
  94.    )
  95.     )
  96.     (mapcar '-
  97.     (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 entData)))))
  98.     (mxv mat (trans (cdr (assoc 10 entData)) norm 0))
  99.     )
  100.   )
  101. )
  102. ;;; VXV Returns the dot product of 2 vectors
  103. (defun vxv (v1 v2)
  104.   (apply '+ (mapcar '* v1 v2))
  105. )
  106. ;; TRP Transpose a matrix -Doug Wilson-
  107. (defun trp (m)
  108.   (apply 'mapcar (cons 'list m))
  109. )
  110. ;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
  111. (defun mxv (m v)
  112.   (mapcar '(lambda (r) (vxv r v)) m)
  113. )
  114. ;; MXM Multiply two matrices -Vladimir Nesterovsky-
  115. (defun mxm (m q)
  116.   (mapcar '(lambda (r) (mxv (trp q) r)) m)
  117. )
这个是gile的。贴此共享。
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-2-24 23:18 , Processed in 0.158525 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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