经过几天的搜索,发现了这个 http://bbs.mjtd.com/thread-99926-1-1.html
然后提取了满足问题的最少代码。
- ;;;-----------------------------------------------------------;;
- ;;; MAT:mxm Multiply two matrices -Vladimir Nesterovsky- ;;
- ;;;-----------------------------------------------------------;;
- (defun mat:mxm (m q)
- (mapcar (function (lambda (r) (mat:mxv (mat:trp q) r))) m)
- )
- ;;;-----------------------------------------------------------;;
- ;;; Matrix x Vector - Vladimir Nesterovsky ;;
- ;;; Args: m - nxn matrix, v - vector in R^n ;;
- ;;;-----------------------------------------------------------;;
- (defun mat:mxv (m v)
- (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
- )
- ;;; MAT:trp Transpose a matrix -Doug Wilson- ;;
- ;;;-----------------------------------------------------------;;
- (defun mat:trp (m)
- (apply 'mapcar (cons 'list m))
- )
- ;;;-----------------------------------------------------------;;
- ;;; MAT:RefGeom (gile) ;;
- ;;; Returns a list which first item is a 3x3 transformation ;;
- ;;; matrix(rotation,scales normal) and second item the object ;;
- ;;; insertion point in its parent(xref, bloc or space) ;;
- ;;; ;;
- ;;; Argument : an ename ;;
- ;;;-----------------------------------------------------------;;
- (defun mat:refgeom (ename / elst ang norm mat)
- (setq elst (entget ename)
- ang (cdr (assoc 50 elst))
- norm (cdr (assoc 210 elst))
- )
- (list
- (setq mat
- (mat:mxm
- (mapcar (function (lambda (v) (trans v 0 norm t)))
- '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
- )
- (mat:mxm
- (list (list (cos ang) (- (sin ang)) 0.0)
- (list (sin ang) (cos ang) 0.0)
- '(0.0 0.0 1.0)
- )
- (list (list (cdr (assoc 41 elst)) 0.0 0.0)
- (list 0.0 (cdr (assoc 42 elst)) 0.0)
- (list 0.0 0.0 (cdr (assoc 43 elst)))
- )
- )
- )
- )
- (mapcar
- '-
- (trans (cdr (assoc 10 elst)) norm 0)
- (mat:mxv mat
- (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 elst)))))
- )
- )
- )
- )
- ;;; pt 块定义内的点
- ;;; insert 块实例图元
- ;;; 返回 指定实例内的点的WCS坐标值
- (defun block->wcs (pt insert / geom)
- (setq geom (mat:refgeom insert))
- (mapcar '+ (mat:mxv (car geom) pt) (cadr geom))
- )
|