Help with matrix transformation...

Devin

Usenet Archive
Joined
Sep 27, 2001
Messages
342
Reaction score
0
Hi there,

I'm trying to adjust Jon's routines to accept a transformation matrix as returned by getUCSMatrix but I think I've swapped something in the wrong way.

Thanks for any help,

Devin

;;; The "3DTransformBA" function is the inverse of
;;; this function.

;;; Arguments:
;;; XA = a list of three reals defining a unit vector ;;; pointing along the X axis of the "A" coordinate ;;; system, expressed in the "B" coordinate system ;;; YA = a list of three reals defining a unit vector ;;; pointing along the Y axis of the "A" coordinate ;;; system, expressed in the "B" coordinate system ;;; ZA = a list of three reals defining a unit vector ;;; pointing along the Z axis of the "A" coordinate ;;; system, expressed in the "B" coordinate system ;;; OA = A list of three reals defining a vector from ;;; the origin of the "B" coordinate system to the ;;; origin of the "A" coordinate system, expressed ;;; in the "B" coordinate system ;;; SA = A list of three reals defining the scale factors; ;;; "B" X axis units per "A" X axis unit, "B" Y axis ;;; units per "A" Y axis unit, and "B" Z axis units ;;; per "A" Z axis unit ;;; P1 = A list of three reals defining a point in the ;;; "A" coordinate system

;;; Return value: a list of three reals defining the same ;;; point as P1, but expressed in the "B" coordinate system

(defun 3DTransformAB ( p1 matrix / a )
;; Scale the input point to "B" system units
(setq
xa (car matrix)
ya (cadr matrix)
za (caddr matrix)
oa (list (last xa) (last ya) (last za))
sa (cadddr matrix)
xa (list (car xa) (cadr xa) (caddr xa))
ya (list (car ya) (cadr ya) (caddr ya))
za (list (car za) (cadr za) (caddr za))
sa (list (car sa) (cadr sa) (caddr sa))
sa (mapcar '(lambda (a) (if (zerop a) 1.0)) sa)
P1 (mapcar '* P1 SA)
)
;; Translate and set up the return value
(mapcar '+
OA
;; The following does the rotation transformation
(list (+ (* (car XA) (car P1))
(* (car YA) (cadr P1))
(* (car ZA) (caddr P1))
) ;_ end +
(+ (* (cadr XA) (car P1))
(* (cadr YA) (cadr P1))
(* (cadr ZA) (caddr P1))
) ;_ end +
(+ (* (caddr XA) (car P1))
(* (caddr YA) (cadr P1))
(* (caddr ZA) (caddr P1))
) ;_ end +
) ;_ end list
) ;_ end mapcar
) ;_ end defun

;;; Function to carry out an arbitrary 3D coordinate
;;; transformation from a "B" coordinate system
;;; to an "A" coordinate system. Works between any two ;;; Cartesian coordinates of the same handedness, and ;;; may work between Cartesian coordinate systems of ;;; different handedness (with appropriate negative ;;; values in the "SA" argument).

;;; The "3DTransformAB" function is the inverse of
;;; this function.

;;; Arguments:
;;; XA = a list of three reals defining a unit vector ;;; pointing along the X axis of the "A" coordinate ;;; system, expressed in the "B" coordinate system ;;; YA = a list of three reals defining a unit vector ;;; pointing along the Y axis of the "A" coordinate ;;; system, expressed in the "B" coordinate system ;;; ZA = a list of three reals defining a unit vector ;;; pointing along the Z axis of the "A" coordinate ;;; system, expressed in the "B" coordinate system ;;; OA = A list of three reals defining a vector from ;;; the origin of the "B" coordinate system to the ;;; origin of the "A" coordinate system, expressed ;;; in the "B" coordinate system ;;; SA = A list of three reals defining the scale factors; ;;; "B" X axis units per "A" X axis unit, "B" Y axis ;;; units per "A" Y axis unit, and "B" Z axis units ;;; per "A" Z axis unit ;;; P1 = A list of three reals defining a point in the ;;; "B" coordinate system

;;; Return value: a list of three reals defining the same ;;; point as P1, but expressed in the "A" coordinate system

(defun 3DTransformBA ( p1 matrix /)
;; Translate
(setq
xa (car matrix)
ya (cadr matrix)
za (caddr matrix)
oa (list (last xa) (last ya) (last za))
sa (cadddr matrix)
xa (list (car xa) (cadr xa) (caddr xa))
ya (list (car ya) (cadr ya) (caddr ya))
za (list (car za) (cadr za) (caddr za))
sa (list (car sa) (cadr sa) (caddr sa))
sa (mapcar '(lambda (a) (if (zerop a) 1.0)) sa)
P1 (mapcar '- P1 OA)
)
;; Scale and set up the return value
(mapcar '/
;; The following does the rotation
(list (+ (* (car XA) (car P1))
(* (cadr XA) (cadr P1))
(* (caddr XA) (caddr P1))
) ;_ end +
(+ (* (car YA) (car P1))
(* (cadr YA) (cadr P1))
(* (caddr YA) (caddr P1))
) ;_ end +
(+ (* (car ZA) (car P1))
(* (cadr ZA) (cadr P1))
(* (caddr ZA) (caddr P1))
) ;_ end +
) ;_ end list
SA
) ;_ end mapcar
) ;_ end defun
 
I guess Jon's formula is a vector transformation matrix solution and perhaps I need a rotational transformation matrix solution. I think that's the case cause I think AutoCAD's matrices are returned as a rotational transformation matrix.

Anybody know for sure?

Devin
 
Devin,

Take another look at the functions I posted in your other thread on the same topic. I suspect you are barking up the wrong tree, while you have an easy solution in-hand.

I may be wrong about this. I believe Jon's functions are designed to avoid using a transformation matrix as returned by nentsel or nentselp. Jon?

Joe Burke
 
As you can see, it is a rotation/translation matrix:

Command: ucs
Current ucs name: *WORLD*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World] <World>: 3p Specify new origin point <0,0,0>: 2,3,0 Specify point on positive portion of X-axis <3.0000,3.0000,0.0000>: 3,4,0 Specify point on positive-Y portion of the UCS XY plane <1.2929,3.7071,0.0000>: 2,4,0
Command: ucs
Current ucs name: *NO NAME*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World] <World>: s Enter name to save current UCS or [?]: Test
Command:

(defun C:Test
(vl-Load-Com)
(vlax-SafeArray->List
(vlax-Variant-Value
(vla-GetUCSMatrix
(vla-Item (vla-Get-UserCoordinateSystems
(vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
"Test")))))

_$ (c:Test)
((0.707107 -0.707107 0.0 2.0) (0.707107 0.707107 0.0 3.0) (0.0 0.0 1.0 0.0)
(0.0 0.0 0.0 1.0))

--
R. Robert Bell, MCSE
www.AcadX.com

| I guess Jon's formula is a vector transformation matrix solution and perhaps | I need a rotational transformation matrix solution. I think that's the case | cause I think AutoCAD's matrices are returned as a rotational transformation | matrix. | | Anybody know for sure? | | Devin | | | > Hi there, | > | > I'm trying to adjust Jon's routines to accept a transformation matrix as | > returned by getUCSMatrix but I think I've swapped something in the wrong | > way. | > | > Thanks for any help, | > | > Devin | > | > ;;; The "3DTransformBA" function is the inverse of | > ;;; this function. | > | > ;;; Arguments:
| > ;;; XA = a list of three reals defining a unit vector | > ;;; pointing along the X axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; YA = a list of three reals defining a unit vector | > ;;; pointing along the Y axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; ZA = a list of three reals defining a unit vector | > ;;; pointing along the Z axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; OA = A list of three reals defining a vector from | > ;;; the origin of the "B" coordinate system to the | > ;;; origin of the "A" coordinate system, expressed | > ;;; in the "B" coordinate system | > ;;; SA = A list of three reals defining the scale factors; | > ;;; "B" X axis units per "A" X axis unit, "B" Y axis | > ;;; units per "A" Y axis unit, and "B" Z axis units | > ;;; per "A" Z axis unit | > ;;; P1 = A list of three reals defining a point in the | > ;;; "A" coordinate system | > | > ;;; Return value: a list of three reals defining the same | > ;;; point as P1, but expressed in the "B" coordinate system | > | > (defun 3DTransformAB ( p1 matrix / a ) | > ;; Scale the input point to "B" system units | > (setq | > xa (car matrix) | > ya (cadr matrix) | > za (caddr matrix) | > oa (list (last xa) (last ya) (last za)) | > sa (cadddr matrix) | > xa (list (car xa) (cadr xa) (caddr xa)) | > ya (list (car ya) (cadr ya) (caddr ya)) | > za (list (car za) (cadr za) (caddr za)) | > sa (list (car sa) (cadr sa) (caddr sa)) | > sa (mapcar '(lambda (a) (if (zerop a) 1.0)) sa) | > P1 (mapcar '* P1 SA) | > ) | > ;; Translate and set up the return value | > (mapcar '+ | > OA | > ;; The following does the rotation transformation | > (list (+ (* (car XA) (car P1)) | > (* (car YA) (cadr P1)) | > (* (car ZA) (caddr P1)) | > ) ;_ end + | > (+ (* (cadr XA) (car P1)) | > (* (cadr YA) (cadr P1)) | > (* (cadr ZA) (caddr P1)) | > ) ;_ end + | > (+ (* (caddr XA) (car P1)) | > (* (caddr YA) (cadr P1)) | > (* (caddr ZA) (caddr P1)) | > ) ;_ end + | > ) ;_ end list | > ) ;_ end mapcar | > ) ;_ end defun | > | > ;;; Function to carry out an arbitrary 3D coordinate | > ;;; transformation from a "B" coordinate system | > ;;; to an "A" coordinate system. Works between any two | > ;;; Cartesian coordinates of the same handedness, and | > ;;; may work between Cartesian coordinate systems of | > ;;; different handedness (with appropriate negative | > ;;; values in the "SA" argument). | > | > ;;; The "3DTransformAB" function is the inverse of | > ;;; this function. | > | > ;;; Arguments:
| > ;;; XA = a list of three reals defining a unit vector | > ;;; pointing along the X axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; YA = a list of three reals defining a unit vector | > ;;; pointing along the Y axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; ZA = a list of three reals defining a unit vector | > ;;; pointing along the Z axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; OA = A list of three reals defining a vector from | > ;;; the origin of the "B" coordinate system to the | > ;;; origin of the "A" coordinate system, expressed | > ;;; in the "B" coordinate system | > ;;; SA = A list of three reals defining the scale factors; | > ;;; "B" X axis units per "A" X axis unit, "B" Y axis | > ;;; units per "A" Y axis unit, and "B" Z axis units | > ;;; per "A" Z axis unit | > ;;; P1 = A list of three reals defining a point in the | > ;;; "B" coordinate system | > | > ;;; Return value: a list of three reals defining the same | > ;;; point as P1, but expressed in the "A" coordinate system | > | > (defun 3DTransformBA ( p1 matrix /) | > ;; Translate | > (setq | > xa (car matrix) | > ya (cadr matrix) | > za (caddr matrix) | > oa (list (last xa) (last ya) (last za)) | > sa (cadddr matrix) | > xa (list (car xa) (cadr xa) (caddr xa)) | > ya (list (car ya) (cadr ya) (caddr ya)) | > za (list (car za) (cadr za) (caddr za)) | > sa (list (car sa) (cadr sa) (caddr sa)) | > sa (mapcar '(lambda (a) (if (zerop a) 1.0)) sa) | > P1 (mapcar '- P1 OA) | > ) | > ;; Scale and set up the return value | > (mapcar '/ | > ;; The following does the rotation | > (list (+ (* (car XA) (car P1)) | > (* (cadr XA) (cadr P1)) | > (* (caddr XA) (caddr P1)) | > ) ;_ end + | > (+ (* (car YA) (car P1)) | > (* (cadr YA) (cadr P1)) | > (* (caddr YA) (caddr P1)) | > ) ;_ end + | > (+ (* (car ZA) (car P1)) | > (* (cadr ZA) (cadr P1)) | > (* (caddr ZA) (caddr P1)) | > ) ;_ end + | > ) ;_ end list | > SA | > ) ;_ end mapcar | > ) ;_ end defun | > | > | |
 
Hi Robert,

I've been studying transformation matrices and understand them now. I know what you mean. It rotates and translates from the same 3x4 matrix. Don't know what the last 1x4 row is for though. I read somewhere where it involves perspective.

I've developed some routines for dealing with these matrices and want to incorperate them into my routines for effeciency at run time. I'm currently doing a ucs switch instead of a matrix transform and I do about 50 of them each time I select an item from a list. Takes a while for the program to run.

Thanks,

Devin

R. Robert Bell said:
As you can see, it is a rotation/translation matrix:

Command: ucs
Current ucs name: *WORLD*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World] <World>: 3p Specify new origin point <0,0,0>: 2,3,0 Specify point on positive portion of X-axis <3.0000,3.0000,0.0000>: 3,4,0 Specify point on positive-Y portion of the UCS XY plane <1.2929,3.7071,0.0000>: 2,4,0
Command: ucs
Current ucs name: *NO NAME*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World] <World>: s Enter name to save current UCS or [?]: Test
Command:

(defun C:Test
(vl-Load-Com)
(vlax-SafeArray->List
(vlax-Variant-Value
(vla-GetUCSMatrix
(vla-Item (vla-Get-UserCoordinateSystems
(vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
"Test")))))

_$ (c:Test)
((0.707107 -0.707107 0.0 2.0) (0.707107 0.707107 0.0 3.0) (0.0 0.0 1.0 0.0)
(0.0 0.0 0.0 1.0))

--
R. Robert Bell, MCSE
www.AcadX.com

| I guess Jon's formula is a vector transformation matrix solution and perhaps | I need a rotational transformation matrix solution. I think that's the case | cause I think AutoCAD's matrices are returned as a rotational transformation | matrix. | | Anybody know for sure? | | Devin | | | > Hi there, | > | > I'm trying to adjust Jon's routines to accept a transformation matrix as | > returned by getUCSMatrix but I think I've swapped something in the wrong | > way. | > | > Thanks for any help, | > | > Devin | > | > ;;; The "3DTransformBA" function is the inverse of | > ;;; this function. | > | > ;;; Arguments:
| > ;;; XA = a list of three reals defining a unit vector | > ;;; pointing along the X axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; YA = a list of three reals defining a unit vector | > ;;; pointing along the Y axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; ZA = a list of three reals defining a unit vector | > ;;; pointing along the Z axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; OA = A list of three reals defining a vector from | > ;;; the origin of the "B" coordinate system to the | > ;;; origin of the "A" coordinate system, expressed | > ;;; in the "B" coordinate system | > ;;; SA = A list of three reals defining the scale factors; | > ;;; "B" X axis units per "A" X axis unit, "B" Y axis | > ;;; units per "A" Y axis unit, and "B" Z axis units | > ;;; per "A" Z axis unit | > ;;; P1 = A list of three reals defining a point in the | > ;;; "A" coordinate system | > | > ;;; Return value: a list of three reals defining the same | > ;;; point as P1, but expressed in the "B" coordinate system | > | > (defun 3DTransformAB ( p1 matrix / a ) | > ;; Scale the input point to "B" system units | > (setq | > xa (car matrix) | > ya (cadr matrix) | > za (caddr matrix) | > oa (list (last xa) (last ya) (last za)) | > sa (cadddr matrix) | > xa (list (car xa) (cadr xa) (caddr xa)) | > ya (list (car ya) (cadr ya) (caddr ya)) | > za (list (car za) (cadr za) (caddr za)) | > sa (list (car sa) (cadr sa) (caddr sa)) | > sa (mapcar '(lambda (a) (if (zerop a) 1.0)) sa) | > P1 (mapcar '* P1 SA) | > ) | > ;; Translate and set up the return value | > (mapcar '+ | > OA | > ;; The following does the rotation transformation | > (list (+ (* (car XA) (car P1)) | > (* (car YA) (cadr P1)) | > (* (car ZA) (caddr P1)) | > ) ;_ end + | > (+ (* (cadr XA) (car P1)) | > (* (cadr YA) (cadr P1)) | > (* (cadr ZA) (caddr P1)) | > ) ;_ end + | > (+ (* (caddr XA) (car P1)) | > (* (caddr YA) (cadr P1)) | > (* (caddr ZA) (caddr P1)) | > ) ;_ end + | > ) ;_ end list | > ) ;_ end mapcar | > ) ;_ end defun | > | > ;;; Function to carry out an arbitrary 3D coordinate | > ;;; transformation from a "B" coordinate system | > ;;; to an "A" coordinate system. Works between any two | > ;;; Cartesian coordinates of the same handedness, and | > ;;; may work between Cartesian coordinate systems of | > ;;; different handedness (with appropriate negative | > ;;; values in the "SA" argument). | > | > ;;; The "3DTransformAB" function is the inverse of | > ;;; this function. | > | > ;;; Arguments:
| > ;;; XA = a list of three reals defining a unit vector | > ;;; pointing along the X axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; YA = a list of three reals defining a unit vector | > ;;; pointing along the Y axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; ZA = a list of three reals defining a unit vector | > ;;; pointing along the Z axis of the "A" coordinate | > ;;; system, expressed in the "B" coordinate system | > ;;; OA = A list of three reals defining a vector from | > ;;; the origin of the "B" coordinate system to the | > ;;; origin of the "A" coordinate system, expressed | > ;;; in the "B" coordinate system | > ;;; SA = A list of three reals defining the scale factors; | > ;;; "B" X axis units per "A" X axis unit, "B" Y axis | > ;;; units per "A" Y axis unit, and "B" Z axis units | > ;;; per "A" Z axis unit | > ;;; P1 = A list of three reals defining a point in the | > ;;; "B" coordinate system | > | > ;;; Return value: a list of three reals defining the same | > ;;; point as P1, but expressed in the "A" coordinate system | > | > (defun 3DTransformBA ( p1 matrix /) | > ;; Translate | > (setq | > xa (car matrix) | > ya (cadr matrix) | > za (caddr matrix) | > oa (list (last xa) (last ya) (last za)) | > sa (cadddr matrix) | > xa (list (car xa) (cadr xa) (caddr xa)) | > ya (list (car ya) (cadr ya) (caddr ya)) | > za (list (car za) (cadr za) (caddr za)) | > sa (list (car sa) (cadr sa) (caddr sa)) | > sa (mapcar '(lambda (a) (if (zerop a) 1.0)) sa) | > P1 (mapcar '- P1 OA) | > ) | > ;; Scale and set up the return value | > (mapcar '/ | > ;; The following does the rotation | > (list (+ (* (car XA) (car P1)) | > (* (cadr XA) (cadr P1)) | > (* (caddr XA) (caddr P1)) | > ) ;_ end + | > (+ (* (car YA) (car P1)) | > (* (cadr YA) (cadr P1)) | > (* (caddr YA) (caddr P1)) | > ) ;_ end + | > (+ (* (car ZA) (car P1)) | > (* (cadr ZA) (cadr P1)) | > (* (caddr ZA) (caddr P1)) | > ) ;_ end + | > ) ;_ end list | > SA | > ) ;_ end mapcar | > ) ;_ end defun | > | > | |
 

Latest threads

Back
Top