Hi,
A 4x4 transformation matrix countains :
- the 3x3 upper left matrix (rotations and scalings)
- the 4th column but last item is the translation vector (displacement of origin)
- the 4th row, always 0.0 0.0 0.0 1.0 is to make the matrix square
Example: applying your matrix to a line which start point is (20.0 20.0 0.0) and end point is (80.0 50.0 0.0) in WCS coordinates.
The new coordinates of the rotated line are : (5.0 26.2132 0.0) (26.2132 89.8528 0.0).
Now, if you create a new UCS moving the origin to (5.0 -2.071068 0.0) and rotating 45° on Z axis, the coordinates of the line in this UCS are (20.0 20.0 0.0) and (80.0 50.0 0.0).
When using matrices with AutoLISP, I'd rather first deal with separated rotation (sclaing) 3x3 matrices and translation vectors, and then build the 4x4 matrix (if needed).
To calculate the translation vector about a rotation matrix (for example) and a rotation base point, You can apply the 3x3 matrix to the vector from origin (0,0,0) to the base point.
Example to construct your 4x4 matrix:
;; Build the 3x3 rotation matrix
(setq 3x3Matrix (list (list (cos ang) (- (sin ang)) 0.0)
(list (sin ang) (cos ang) 0.0)
'(0.0 0.0 1.0)
)
)
;; Calculate the translation vector
(setq translation (mapcar '- BasePoint (mxv 3x3Matrix BasePoint)))
;; Build the 4x4 matrix
(setq 4x4Matrix (append
(mapcar '(lambda (v x) (append v (list x)))
3x3Matrix
translation
)
(list '(0.0 0.0 0.0 1.0))
)
)
The upper example uses the mxv function wich is, IMO, one of the three most usefull routines to play with matrices:
;; TRP Transpose a matrix -Doug Wilson-
(defun trp (m)
(apply 'mapcar (cons 'list m))
)
;; MXV Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v)
(mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m)
)
;; MXM Multiply two matrices -Vladimir Nesterovsky-
(defun mxm (m q)
(mapcar '(lambda (r) (mxv (trp q) r)) m)
)