平移

  1. (defun c:MyMove(/ bf-mat-translation ent mat n p0 p1 ss)
  2. ;;;name:BF-Mat-Translation
  3. ;;;desc:根据矢量计算平移矩阵
  4. ;;;arg:v:平移矢量
  5. ;;;return:4X4的平移矩阵
  6. ;;;example:(BF-Mat-Translation '(1 0 0))
  7. (defun BF-Mat-Translation (v)
  8. (list
  9. (list 1. 0. 0. (float (car v)))
  10. (list 0. 1. 0. (float (cadr v)))
  11. (list 0. 0. 1. (float (caddr v)))
  12. (list 0. 0. 0. 1.)
  13. )
  14. )
  15. (if (and (setq ss (ssget)) (setq p0 (getpoint "\n请指定基点:")) (setq p1 (getpoint p0 "指定第二点的位移: ")))
  16. (progn
  17. (setq mat (vlax-make-safearray vlax-vbDouble '(0 . 3) '(0 . 3)) n -1)
  18. (vlax-safearray-fill mat (BF-Mat-Translation (mapcar '- p1 p0)))
  19. (while (setq ent (ssname ss (setq n (1+ n))))
  20. (vla-TransformBy (vlax-ename->vla-object ent) mat)
  21. )
  22. )
  23. )
  24. )

旋转

  1. (defun C:MyRotation(/ bf-mat-scaling ent mat n p0 ss)
  2. ;;;name:BF-Mat-Rotation
  3. ;;;desc:根据基点和旋转角度计算旋转矩阵
  4. ;;;arg:Cen:基点
  5. ;;;arg:ang:旋转角度(弧度值)
  6. ;;;return:4X4的旋转矩阵
  7. ;;;example:(BF-Mat-Rotation '(1 0 0) (/ pi 3))
  8. (defun BF-Mat-Rotation (Cen ang / c s x y)
  9. (setq c (cos ang) s (sin ang))
  10. (setq x (car Cen) y (cadr Cen))
  11. (list
  12. (list c (- s) 0. (- x (- (* c x) (* s y))))
  13. (list s c 0. (- y (+ (* s x) (* c y))))
  14. '(0. 0. 1. 0.)
  15. '(0. 0. 0. 1.)
  16. )
  17. )
  18. (if (and (setq ss (ssget)) (setq p0 (getpoint "\n请指定基点:") ang (getangle p0 "\n请指定旋转角度:")))
  19. (progn
  20. (setq mat (vlax-make-safearray vlax-vbDouble '(0 . 3) '(0 . 3)) n -1)
  21. (vlax-safearray-fill mat (BF-Mat-Rotation p0 ang))
  22. (while (setq ent (ssname ss (setq n (1+ n))))
  23. (vla-TransformBy (vlax-ename->vla-object ent) mat)
  24. )
  25. )
  26. )
  27. )

缩放

  1. (defun C:MyScaling(/ bf-mat-scaling ent mat n p0 ss)
  2. ;;;name:BF-Mat-Scaling
  3. ;;;desc:根据基点和缩放比例计算缩放矩阵
  4. ;;;arg:Cen:基点
  5. ;;;arg:scale:缩放比例
  6. ;;;return:4X4的缩放矩阵
  7. ;;;example:(BF-Mat-Scaling '(1 0 0) 2)
  8. (defun BF-Mat-Scaling (Cen scale / s)
  9. (setq s (- 1 (setq scale (float scale))))
  10. (list
  11. (list scale 0. 0. (* s (car Cen)))
  12. (list 0. scale 0. (* s (cadr Cen)))
  13. (list 0. 0. scale (* s (caddr Cen)))
  14. '(0. 0. 0. 1.)
  15. )
  16. )
  17. (if (and (setq ss (ssget)) (setq p0 (getpoint "\n请指定基点:")) sca (getdist "\n请指定缩放比例:"))
  18. (progn
  19. (setq mat (vlax-make-safearray vlax-vbDouble '(0 . 3) '(0 . 3)) n -1)
  20. (vlax-safearray-fill mat (BF-Mat-Scaling p0 sca))
  21. (while (setq ent (ssname ss (setq n (1+ n))))
  22. (vla-TransformBy (vlax-ename->vla-object ent) mat)
  23. )
  24. )
  25. )
  26. )