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'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