Author Topic: [AcGe(9)] AcGeMatrix3d - Matrix Operation (5)-Combined translation (ALIGN)  (Read 414 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 505
Regarding the basic concepts of AcGeMatrix3d and simple methods of implementing COPY and MOVE, see the post:
https://www.theswamp.org/index.php?topic=58880.msg617740#msg617740

ARX constructs the rotation transformation matrix through AcGeMatrix3d::setToScaling(..)

======================

Let’s enter the content of high-order points, matrix combination transformation, take the ALIGN command as an example,
As shown below, an ALIGN operation is a combination of translation, rotation, and scaling.
we want:
1. Translate first



2. Then rotate and align



3. Zoom and stretch



It requires three transformations,

result:


Code - Auto/Visual Lisp: [Select]
  1. (defun c:aln ()
  2.   (if
  3.     (and (setq ss (xdrx-ssget "\nSelect the object to be Aligned <exit>:"))
  4.          (setq src-p1 (getpoint "\nSource First Point<exit>:"))
  5.          (setq dest-p1 (getpoint "\nDest First Point<exit>:"))
  6.          (setq src-p2 (getpoint "\nSource Second Point<exit>:"))
  7.          (setq dest-p2 (getpoint "\nDest Second Point<exit>:"))
  8.     )
  9.      (progn
  10.        (xdrx-begin)
  11.        (setq mat-trans (xdrx-matrix-settranslation
  12.                          (mapcar '- dest-p1 src-p1)
  13.                        )
  14.              mat-rot   (xdrx-matrix-setrotation
  15.                          (angle dest-p1 dest-p2)
  16.                          '(0 0 1.0)
  17.                          dest-p1
  18.                        )
  19.              mat-scl   (xdrx-matrix-setscale
  20.                          (/ (distance dest-p1 dest-p2)
  21.                             (distance src-p1 src-p2)
  22.                          )
  23.                          dest-p1
  24.                        )
  25.        )
  26.        (setq ents (xdrx-ss->ents ss))
  27.        (xdrx-entity-transform ents mat-trans); first translation
  28.        (xdrx-entity-transform ents mat-rot); second rotation align
  29.        (xdrx-entity-transform ents mat-scl); third scale stretch
  30.        (xdrx-end)
  31.      )
  32.   )
  33.   (princ)
  34. )

If a complex transformation is carried out dozens of times, then it will be transformed to the final result one at a time. Isn't it very inefficient because AUTOCAD needs to refresh the object, display, etc. every time it transforms?
Is there any way to transform to the final result in one go?
have:
This is the artifact of mathematics, matrix combination transformation,
Use matrix left multiplication to obtain the final transformation matrix in one go.
The order of left multiplication is that the last transformation is at the front and the first matrix operation is at the end.
The ARX AcGeMatrix3d class provides AcGeMatrix3d::setToProduct(...)



==========

The following code uses a combination matrix to find the align transformation matrix. Only one transform operation is used to obtain the final transformation result.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:aln ()
  2.   (if
  3.     (and (setq ss (xdrx-ssget "\nSelect the object to be Aligned <exit>:"))
  4.          (setq src-p1 (getpoint "\nSource First Point<exit>:"))
  5.          (setq dest-p1 (getpoint "\nDest First Point<exit>:"))
  6.          (setq src-p2 (getpoint "\nSource Second Point<exit>:"))
  7.          (setq dest-p2 (getpoint "\nDest Second Point<exit>:"))
  8.     )
  9.      (progn
  10.        (xdrx-begin)
  11.        (setq mat-trans (xdrx-matrix-settranslation
  12.                          (mapcar '- dest-p1 src-p1)
  13.                        )
  14.              mat-rot   (xdrx-matrix-setrotation
  15.                          (angle dest-p1 dest-p2)
  16.                          '(0 0 1.0)
  17.                          dest-p1
  18.                        )
  19.              mat-scl   (xdrx-matrix-setscale
  20.                          (/ (distance dest-p1 dest-p2)
  21.                             (distance src-p1 src-p2)
  22.                          )
  23.                          dest-p1
  24.                        )
  25.              mat-align (xdrx-matrix-product mat-scl mat-rot mat-trans)
  26.        )
  27.        (setq ents (xdrx-ss->ents ss))
  28.        (xdrx-entity-transform ents mat-align)
  29.        (xdrx-end)
  30.      )
  31.   )
  32.   (princ)
  33. )
« Last Edit: December 12, 2023, 08:58:46 AM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net