本帖最后由 尘缘一生 于 2024-12-19 18:34 编辑
闲来无事,看到本坛的说,COMMAND MOVE ROTATE
过往啊,我也尝试,探讨许多次,
总觉得,还是COMMAND的快,并不慢,到底怎么快,拿不准主意
鉴于矩阵的话,比较晦涩难懂,弄一段时间,放弃了,
所以啊,高飞大师这种数学好的,是基础科学,好比华为任正非讲的:“俄罗斯科学家那个故事....”
闲也无聊呢,弄几个函数,测试还是不快呢!
难道移动,旋转最快的方式我们找不到吗?特别是和GRREAD整合做起来,频繁刷新时候,能不卡的。
非得C ARX VB去写吗? 可惜我早已忘记C++20几年了,拾不起来!
- ;实体,选择集,实体表->矩阵移动---(一级)---
- (defun sl:move (ss p1 p2)
- (sl:mov-ang ss p1 p2 nil)
- )
- ;选择集ss以基点p0 旋转ang(弧度)---(一级)-----
- ;(sl-rot (ssget) (getpoint) (* pi 0.25))
- (defun sl-ssrot (ss p0 ang / mat)
- (setq mat (mat:rotation (trans p0 1 0) ang))
- (sl:sstransformby mat ss)
- (sl-wzgz ss)
- (princ)
- )
- ;;实体,选择集,实体表->矩阵从p1到p2移动并旋转ang度-----(一级)------
- (defun sl:mov-ang (ss p1 p2 ang / mat)
- (if (setq mat (mat:translateby2pang p1 p2 ang))
- (cond
- ((= (type ss) 'ENAME) (vla-transformby (vlax-ename->vla-object ss) (vlax-tmatrix mat))) ;图元
- ((= (type ss) 'PICKSET) (sl:sstransformby mat ss)) ;集
- ((= (type ss) 'LIST) (sl:sstransformby mat (sl:pickset-fromlist ss))) ;实体表
- )
- )
- )
- ;平移+旋转变换矩阵---(一级)---
- ;p1 基点 p2 目标点 并旋转ang(nil 仅平移)度
- ;(mat:translateby2pang p1 p2 nil) 平移
- ;(mat:translateby2pang p1 p1 ang) 旋转
- ;(mat:translateby2pang p1 p2 ang) 平移+旋转
- (defun mat:translateby2pang (p1 p2 ang / q mat)
- (setq mat (mat:translateby2p p1 p2))
- (if ang
- (if mat
- (setq q (mat:rotation (trans p1 1 0) ang) mat (mat:mxm mat q)) ;转动矩阵;矩阵相乘:移动+转动
- (cond
- ((and p1 (is_pt p1))
- (setq mat (mat:rotation (trans p1 1 0) ang))
- )
- ((and p2 (is_pt p2))
- (setq mat (mat:rotation (trans p2 1 0) ang))
- )
- )
- )
- )
- mat
- )
- ;选择集矩阵变换---(一级)---
- (defun sl:sstransformby (mat ss / i e)
- (setq mat (vlax-tmatrix mat))
- (setq i -1)
- (while (setq e (ssname ss (setq i (1+ i))))
- (vla-transformby (vlax-ename->vla-object e) mat)
- )
- )
- ;平移变换矩阵---(一级)---
- ;p1基点 p2目标点
- (defun mat:translateby2p (p1 p2 / mat)
- (if (and p1 p2 (is_pt p1) (is_pt p2) (> (distance p1 p2) 0.01))
- (setq mat (mat:translation (mapcar '- p2 p1)))
- )
- mat
- )
- ;平移变换矩阵v 位移矢量---(一级)---
- (defun mat:translation (v)
- (list
- (list 1. 0. 0. (car v))
- (list 0. 1. 0. (cadr v))
- (list 0. 0. 1. (caddr v))
- (list 0. 0. 0. 1.)
- )
- )
这一切,只不过是想弄掉几个command代码罢了,举例三领函数之一;然而,效率不行,矩阵再高级,也绝不可入三领集成的。 以上函数,我还是采用了COMMAND多,总觉得,还有未知之路,还有永不止境的完善空间......
|