Author Topic: Rotate an object at a point around a vector axis  (Read 6089 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Rotate an object at a point around a vector axis
« on: September 13, 2010, 04:34:34 PM »
Just in case anyone whats the code by itself.  I thought it might be useful to some other lispers one day, so that is why it is here only.  Hope my wording is correct, as far as what each item is, and how it is used.

Enjoy.

Code: [Select]
(defun RotateAtByVector ( obj pt vec ang / RotateAboutXAxis RotateAboutYAxis )
   
    ; obj = valid ' vla ' object
    ; pt = point in WCS, which will be used as base point of axis of rotation, along with ' vec ' as the vector
    ; vec = vector inwhich to rotate around
    ; ang = angle to rotate object, in radians
    ; Figured out how to rotate about an axis based on this site:
    ; http://local.wasp.uwa.edu.au/~pbourke/geometry/rotate/

    (defun RotateAboutXAxis ( obj vec firstMulti secondMulti / Dist )
       
        (if (not (equal (setq Dist (sqrt (+ (* (cadr vec) (cadr vec)) (* (caddr vec) (caddr vec))))) 0. 0.00000001))
            (vla-TransFormBy
                obj
                (vlax-tmatrix
                    (list
                        (list 1. 0. 0. 0.)
                        (list 0. (/ (caddr vec) Dist) (firstMulti (/ (cadr vec) Dist)) 0.)
                        (list 0. (secondMulti (/ (cadr vec) Dist)) (/ (caddr vec) Dist) 0.)
                        (list 0. 0. 0. 1.)
                    )
                )
            )
        )
    )
    ;---------------------------------------------------------------------------------------------
    (defun RotateAboutYAxis ( obj vec firstMulti secondMulti / Dist )
       
        (setq Dist (sqrt (+ (* (cadr vec) (cadr vec)) (* (caddr vec) (caddr vec)))))
        (vla-TransFormBy
            obj
            (vlax-tmatrix
                (list
                    (list Dist 0. (firstMulti (car vec)) 0.)
                    (list 0. 1. 0. 0.)
                    (list (secondMulti (car vec)) 0. Dist 0.)
                    (list 0. 0. 0. 1.)
                )
            )
        )
    )
    ;---------------------------------------------------------------------------------------------
    (vlax-invoke obj 'Move pt '(0. 0. 0.))
    (RotateAboutXAxis obj vec - +)
    (RotateAboutYAxis obj vec - +)
    (vla-TransformBy
        obj
        (vlax-tmatrix
            (list
                (list (cos ang) (- (sin ang)) 0. 0.)
                (list (sin ang) (cos ang) 0. 0.)
                (list 0. 0. 1. 0.)
                (list 0. 0. 0. 1.)
            )
        )
    )
    (RotateAboutYAxis obj vec + -)
    (RotateAboutXAxis obj vec + -)
    (vlax-invoke obj 'Move '(0. 0. 0.) pt)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Rotate an object at a point around a vector axis
« Reply #1 on: September 14, 2010, 03:12:55 AM »
it's something like vla-Rotate3D?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Rotate an object at a point around a vector axis
« Reply #2 on: September 14, 2010, 11:05:52 AM »
it's something like vla-Rotate3D?

Yea.  I tried that, but it didn't work for me.  Maybe I'll try it again.  If it works, then I'll really feel bad.   :lmao:

At least I learned somethings.

Edit:  That is why I didn't use it, you need to know a second point, where I only had one point and an axis to rotate around.  So I think my code is still useful.
« Last Edit: September 14, 2010, 11:21:11 AM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Rotate an object at a point around a vector axis
« Reply #3 on: September 14, 2010, 11:37:26 AM »

Edit:  That is why I didn't use it, you need to know a second point, where I only had one point and an axis to rotate around.  So I think my code is still useful.

how do you calculate the vector, then. i swear you need two points for that :)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Rotate an object at a point around a vector axis
« Reply #4 on: September 14, 2010, 11:45:16 AM »

Edit:  That is why I didn't use it, you need to know a second point, where I only had one point and an axis to rotate around.  So I think my code is still useful.

how do you calculate the vector, then. i swear you need two points for that :)

The vector is the normal of the plane the object is on in my case, so a second point was not known.  Plus if you want to rotate around an axis of the current ucs, then you can just get those system variables.

Maybe I could have gotten a second point, but my mind didn't work that way that day, so I went this route.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Rotate an object at a point around a vector axis
« Reply #5 on: October 01, 2010, 06:24:49 PM »
Just to finish this off, since I have a better understanding of Vectors and Points.  One could use ' Rotate3d ' like

(vlax-invoke i 'Rotate3d Pt (mapcar (function +) Pt Norm) Ang)

Where:
i = valid ActiveX object
Pt = point of rotation
Norm = vector you want to rotate around
Ang = Angle of rotation
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Rotate an object at a point around a vector axis
« Reply #6 on: July 30, 2011, 09:12:34 AM »
Recently, I've made this code (3d rotation at base point 0,0,0 along vector with desired angle), but when executed CAD applies transformation matrix for 3d rotation and prints its values on text screen... So, no need for IntelliCAD view of transformation via (entget (car (entsel))) - here it works with ordinary CAD and matrix is not inverse like in IntelliCAD, but that one that applies transformation to selected object... For simplicity reasons I didn't included base point, I just used for base 0,0,0 and angle of rotation is like in CAD (+)CCW (-)CW looking as Z axis in way from 0,0,0 to vector coordinates (I inverted vector coordinates in routine - this way this convention of positive angle functions as usual in CAD)... Hope this would be helpful, at least it is one 3d rotation matrix - honestly I don't know how can posted 5 different 3d rotation matrices be added to make single one... I used geomcal.arx to calculate 3d rotation of points that represent orts of main x,y,z axises and then turned that rotated vectors into orts so that their coordinates corresponds to values of 3d rotation matrix...

Code: [Select]
(defun c:tmat ( / obj o pt vect L x y z dx dy dz xx yy zz xxx yyy zzz xo yo zo xa ya za alfa osm)
(vl-load-com)
(setq osm (getvar 'osmode))
(setvar 'osmode 0)
(arxload "geomcal.arx")
(command "ucs" "w")
(setq o '(0.0 0.0 0.0))
(setq pt (getpoint o "\nSpecify end point of vector axis of 3d rotation : "))
(setq x (- (car pt)))
(setq y (- (cadr pt)))
(setq z (- (caddr pt)))
(setq L (sqrt (+ (expt x 2) (expt y 2) (expt z 2))))
(setq xo (/ x L))
(setq yo (/ y L))
(setq zo (/ z L))
(setq vect (list xo yo zo))
(setq alfa (getreal "\nInput angle of rotation in decimal degrees : "))
(setq za '(0.0 0.0 1.0))
(setq ya '(0.0 1.0 0.0))
(setq xa '(1.0 0.0 0.0))
(if (or (equal za vect 0.000001) (equal '(0.0 0.0 -1.0) vect 0.000001)) (setq zzz za) (setq zzz (cal "rot(za,o,vect,alfa)")))
(if (or (equal ya vect 0.000001) (equal '(0.0 -1.0 0.0) vect 0.000001)) (setq yyy ya) (setq yyy (cal "rot(ya,o,vect,alfa)")))
(if (or (equal xa vect 0.000001) (equal '(-1.0 0.0 0.0) vect 0.000001)) (setq xxx xa) (setq xxx (cal "rot(xa,o,vect,alfa)")))
(setq dz (distance o zzz))
(setq dy (distance o yyy))
(setq dx (distance o xxx))
(setq zz (mapcar '(lambda (x) (/ x dz)) zzz))
(setq yy (mapcar '(lambda (x) (/ x dy)) yyy))
(setq xx (mapcar '(lambda (x) (/ x dx)) xxx))
(setq obj (vlax-ename->vla-object (car (entsel "\nSelect object for 3d rotation"))))
(vla-transformby obj
(vlax-tmatrix (setq 3drmatrix
(list (list (car xx) (cadr xx) (caddr xx) 0.0)
      (list (car yy) (cadr yy) (caddr yy) 0.0)
      (list (car zz) (cadr zz) (caddr zz) 0.0)
      (list 0.0 0.0 0.0 1.0))
))
)
(prompt "\nTransformation matrix applied to selected object : ")(princ "\n")(princ 3drmatrix)
(setvar 'osmode osm)
(princ)
)

M.R. :-)
« Last Edit: August 01, 2011, 01:15:08 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Rotate an object at a point around a vector axis
« Reply #7 on: July 30, 2011, 10:26:29 AM »
You might be interested in this thread Marko  :-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Rotate an object at a point around a vector axis
« Reply #8 on: July 30, 2011, 01:00:27 PM »
Hi,

Another way combinating the 2d rotation matrix (about Zaxis) and the transformation matrix from a coordinate system to another one (uses the famous trp, mxv an mxm routines).

Code: [Select]
;; TRP
;; Transposes a matrix -Doug Wilson-
;;
;; Argument : a matrix

(defun trp (m) (apply 'mapcar (cons 'list m)))

;; MXV
;; Applies a transformation matrix to a vector -Vladimir Nesterovsky-
;;
;; Arguments : a matrix and a vector

(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)

;; MXM
;; Multiplies (combinates) two matrices -Vladimir Nesterovsky-
;;
;; Arguments : two matrices

(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

;; gc:TMatrixFromTo
;; Returns the 4x4 transformation matrix form a coordinate system
;; to another one.
;;
;; Arguments
;; from an to: the same arguments as for the trans function.

(defun gc:TMatrixFromTo (from to)
  (append
    (mapcar
      (function
(lambda (v o)
  (append (trans v from to T) (list o))
)
      )
      (list '(1. 0. 0.) '(0. 1. 0.) '(0. 0. 1.))
      (trans '(0. 0. 0.) to from)
    )
    (list '(0. 0. 0. 1.))
  )
)

;; gc:2dRotationMatrix
;; Returns the 4x4 transformation matrix for a rotation about the Z axis
;;
;; Arguments
;; base: the base point
;; ang: the angle in radians

(defun gc:2dRotationMatrix (base ang / mat)
  (append
    (mapcar
      (function
(lambda (v1 v2)
  (append v1 (list v2))
)
      )
      (setq mat (list (list (cos ang) (- (sin ang)) 0)
      (list (sin ang) (cos ang) 0)
      '(0. 0. 1.)
)
      )
      (mapcar '- base (mxv mat base))
    )
    (list '(0. 0. 0. 1.))
  )
)

;; gc:3dRotationMatrix
;; Returns the 3d rotation matrix
;;
;; Arguments
;; org: the rotation base point
;; axis: the rotation axis vector
;; ang: the angle rotation (radians)

(defun gc:3dRotationMatrix (org axis ang)
  (mxm
    (gc:TMatrixFromTo 0 axis)
    (mxm
      (gc:2dRotationMatrix (trans org 0 axis) ang)
      (gc:TMatrixFromTo axis 0)
    )
  )
)
« Last Edit: July 30, 2011, 01:17:47 PM by gile »
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Rotate an object at a point around a vector axis
« Reply #9 on: July 30, 2011, 07:56:09 PM »
Nice method Gile  :-)

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Rotate an object at a point around a vector axis
« Reply #10 on: July 31, 2011, 04:21:46 AM »
Here is my final variant with 3d vector defined by 2 points... Also, result is one 3drmatrix that is printed on text screen...

Code: [Select]
(defun c:tmat ( / obj o pt1 pt2 pt3 vect L x y z dx dy dz xx yy zz xxx yyy zzz xo yo zo xa ya za alfa osm)
(vl-load-com)
(setq osm (getvar 'osmode))
(setvar 'osmode 0)
(arxload "geomcal.arx")
(command "ucs" "w")
(setq o '(0.0 0.0 0.0))
(setq pt1 (getpoint "\nSpecify start point of vector axis of 3d rotation : "))
(setq pt2 (getpoint pt1 "\nSpecify end point of vector axis of 3d rotation : "))
(setq x (- (car pt1) (car pt2)))
(setq y (- (cadr pt1) (cadr pt2)))
(setq z (- (caddr pt1) (caddr pt2)))
(setq L (sqrt (+ (expt x 2) (expt y 2) (expt z 2))))
(setq xo (/ x L))
(setq yo (/ y L))
(setq zo (/ z L))
(setq vect (list xo yo zo))
(setq alfa (getreal "\nInput angle of rotation in decimal degrees : "))
(if (= (fix (* 100000000 (cal "dpl(o,pt1,pt2)"))) 0) (setq pt3 o) (setq pt3 (cal "rot(o,pt1,pt2,alfa)")))
(setq za '(0.0 0.0 1.0))
(setq ya '(0.0 1.0 0.0))
(setq xa '(1.0 0.0 0.0))
(if (or (equal za vect 0.000001) (equal '(0.0 0.0 -1.0) vect 0.000001)) (setq zzz za) (setq zzz (cal "rot(za,o,vect,alfa)")))
(if (or (equal ya vect 0.000001) (equal '(0.0 -1.0 0.0) vect 0.000001)) (setq yyy ya) (setq yyy (cal "rot(ya,o,vect,alfa)")))
(if (or (equal xa vect 0.000001) (equal '(-1.0 0.0 0.0) vect 0.000001)) (setq xxx xa) (setq xxx (cal "rot(xa,o,vect,alfa)")))
(setq dz (distance o zzz))
(setq dy (distance o yyy))
(setq dx (distance o xxx))
(setq zz (mapcar '(lambda (x) (/ x dz)) zzz))
(setq yy (mapcar '(lambda (x) (/ x dy)) yyy))
(setq xx (mapcar '(lambda (x) (/ x dx)) xxx))
(setq obj (vlax-ename->vla-object (car (entsel "\nSelect object for 3d rotation"))))
(vla-transformby obj
(vlax-tmatrix (setq 3drmatrix
(list (list (car xx) (cadr xx) (caddr xx) (car pt3))
      (list (car yy) (cadr yy) (caddr yy) (cadr pt3))
      (list (car zz) (cadr zz) (caddr zz) (caddr pt3))
      (list 0.0 0.0 0.0 1.0))
))
)
(prompt "\nTransformation matrix applied to selected object : ")(princ "\n")(princ 3drmatrix)
(setvar 'osmode osm)
(princ)
)

M.R. :-)
« Last Edit: August 01, 2011, 01:10:01 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Rotate an object at a point around a vector axis
« Reply #11 on: August 01, 2011, 08:39:55 AM »
Now not quite in topic of 3d rotation, I did one for 3d reflection - seeing Lee Mac thread... I am not sure how is this accurate, but on my comp it gives me satisfactory results...
Hope, it will help someone... Also result is 3drmatrix printed on text screen after execution...

Code: [Select]
(defun c:tmat-ref ( / obj o pt1 pt2 pt3 pt4 x2 y2 z2 L2 x2o y2o z2o vect2 x3 y3 z3 L3 x3o y3o z3o vect3 norm norx nory norz d4 xa ya za zzz dzz yyy dyy xxx dxx zz dz yy dy xx dx osm)
(vl-load-com)
(setq osm (getvar 'osmode))
(setvar 'osmode 0)
(arxload "geomcal.arx")
(command "ucs" "w")
(setq o '(0.0 0.0 0.0))
(setq pt1 (getpoint "\nSpecify first point of plane of 3d reflection : "))
(setq pt2 (getpoint pt1 "\nSpecify second point of plane of 3d reflection : "))
(setq pt3 (getpoint pt1 "\nSpecify third point of plane of 3d reflection : "))
(setq x2 (- (car pt1) (car pt2)))
(setq y2 (- (cadr pt1) (cadr pt2)))
(setq z2 (- (caddr pt1) (caddr pt2)))
(setq L2 (sqrt (+ (expt x2 2) (expt y2 2) (expt z2 2))))
(setq x2o (/ x2 L2))
(setq y2o (/ y2 L2))
(setq z2o (/ z2 L2))
(setq vect2 (list x2o y2o z2o))
(setq x3 (- (car pt1) (car pt3)))
(setq y3 (- (cadr pt1) (cadr pt3)))
(setq z3 (- (caddr pt1) (caddr pt3)))
(setq L3 (sqrt (+ (expt x3 2) (expt y3 2) (expt z3 2))))
(setq x3o (/ x3 L3))
(setq y3o (/ y3 L3))
(setq z3o (/ z3 L3))
(setq vect3 (list x3o y3o z3o))
(if (= (fix (* 100000000 (cal "dpp(o,pt1,pt2,pt3)"))) 0) (setq pt4 o) (progn (setq norm (cal "nor(pt1,pt2,pt3)")) (setq d4 (cal "dpp(o,pt1,pt2,pt3)")) (setq pt4 (cal "pld(o,norm,2*d4)")) ))
(if (not (equal (cal "dpp(o,pt1,pt2,pt3)") (cal "dpp(pt4,pt1,pt2,pt3)") 0.000001)) (progn (setq norm (cal "-nor(pt1,pt2,pt3)")) (setq d4 (cal "dpp(o,pt1,pt2,pt3)")) (setq pt4 (cal "pld(o,norm,2*d4)")) ))
(setq za '(0.0 0.0 1.0))
(setq ya '(0.0 1.0 0.0))
(setq xa '(1.0 0.0 0.0))
(if (and (equal (caddr pt1) (caddr pt2) 0.000001)(equal (caddr pt1) (caddr pt3) 0.000001)) (setq zzz '(0.0 0.0 -1.0)) (progn (setq norm (cal "nor(pt1,pt2,pt3)")) (setq dzz (cal "dpp(za,o,vect2,vect3)")) (setq norz (cal "za+norm")) (setq zzz (cal "pld(za,norz,2*dzz)")) ))
(if (and (equal (cadr pt1) (cadr pt2) 0.000001)(equal (cadr pt1) (cadr pt3) 0.000001)) (setq yyy '(0.0 -1.0 0.0)) (progn (setq norm (cal "nor(pt1,pt2,pt3)")) (setq dyy (cal "dpp(ya,o,vect2,vect3)")) (setq nory (cal "ya+norm")) (setq yyy (cal "pld(ya,nory,2*dyy)")) ))
(if (and (equal (car pt1) (car pt2) 0.000001)(equal (car pt1) (car pt3) 0.000001)) (setq xxx '(-1.0 0.0 0.0)) (progn (setq norm (cal "nor(pt1,pt2,pt3)")) (setq dxx (cal "dpp(xa,o,vect2,vect3)")) (setq norx (cal "xa+norm")) (setq xxx (cal "pld(xa,norx,2*dxx)")) ))
(setq dz (distance o zzz))
(setq dy (distance o yyy))
(setq dx (distance o xxx))
(setq zz (mapcar '(lambda (x) (/ x dz)) zzz))
(setq yy (mapcar '(lambda (x) (/ x dy)) yyy))
(setq xx (mapcar '(lambda (x) (/ x dx)) xxx))
(if (not (equal zz zzz 0.000001)) (progn (setq norm (cal "-nor(pt1,pt2,pt3)")) (setq dzz (cal "dpp(za,o,vect2,vect3)")) (setq norz (cal "za+norm")) (setq zz (cal "pld(za,norz,2*dzz)")) ))
(if (not (equal yy yyy 0.000001)) (progn (setq norm (cal "-nor(pt1,pt2,pt3)")) (setq dyy (cal "dpp(ya,o,vect2,vect3)")) (setq nory (cal "ya+norm")) (setq yy (cal "pld(ya,nory,2*dyy)")) ))
(if (not (equal xx xxx 0.000001)) (progn (setq norm (cal "-nor(pt1,pt2,pt3)")) (setq dxx (cal "dpp(xa,o,vect2,vect3)")) (setq norx (cal "xa+norm")) (setq xx (cal "pld(xa,norx,2*dxx)")) ))
(setq obj (vlax-ename->vla-object (car (entsel "\nSelect object for 3d rotation"))))
(vla-transformby obj
(vlax-tmatrix (setq 3drmatrix
(list (list (car xx) (cadr xx) (caddr xx) (car pt4))
      (list (car yy) (cadr yy) (caddr yy) (cadr pt4))
      (list (car zz) (cadr zz) (caddr zz) (caddr pt4))
      (list 0.0 0.0 0.0 1.0))
))
)
(prompt "\nTransformation matrix applied to selected object : ")(princ "\n")(princ 3drmatrix)
(setvar 'osmode osm)
(princ)
)

M.R. :-)
« Last Edit: August 02, 2011, 09:35:23 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Rotate an object at a point around a vector axis
« Reply #12 on: August 02, 2011, 09:39:43 AM »
All revisions finished... Checked for M.R. posts for 3drotation and 3dreflection...

ENJOY, Happy computing, M.R.

 8-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Rotate an object at a point around a vector axis
« Reply #13 on: August 16, 2011, 08:58:51 AM »
After studying what stated gile, I've managed to compose one 3dRotation matrix based of given 5... As gile mentioned, while operating mxm on matrices I used reverse order of those used when consequently applied transformby and successfully calculated one global 3dRotation matrix... So here is code :

Code: [Select]
;; TRP
;; Transposes a matrix -Doug Wilson-
;;
;; Argument : a matrix

(defun trp (m) (apply 'mapcar (cons 'list m)))

;; MXV
;; Applies a transformation matrix to a vector -Vladimir Nesterovsky-
;;
;; Arguments : a matrix and a vector

(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)

;; MXM
;; Multiplies (combinates) two matrices -Vladimir Nesterovsky-
;;
;; Arguments : two matrices

(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

(defun c:3DRotateAtByVector ( / pt1 pt2 obj org vec ang RotateAboutXAxis RotateAboutYAxis RotateAboutZAxis tmat )
   
    ; org = point in WCS, which will be used as base point of axis of rotation, along with ' vec ' as the vector
    ; vec = vector inwhich to rotate around
    ; ang = angle to rotate object, in radians

    ;---------------------------------------------------------------------------------------------
    (vl-load-com)
    (setq pt1 (getpoint "\nPick start point of vector : ")
          pt2 (getpoint "\nPick end point of vector : ")
          vec (mapcar '(lambda (x) (/ x (distance pt1 pt2))) (mapcar '- pt2 pt1))
          org (getpoint "\nPick origin point of 3dRotation : ")
          ang (* (/ PI 180) (getreal "\nInput angle of rotation in decimal degrees : "))
          obj (vlax-ename->vla-object (car (entsel "\nSelect object to apply 3dRotationMatrix")))
    )
    ;---------------------------------------------------------------------------------------------
    (defun RotateAboutXAxis ( vec firstMulti secondMulti / Dist )
        (if (not (equal (setq Dist (sqrt (+ (* (cadr vec) (cadr vec)) (* (caddr vec) (caddr vec))))) 0. 0.00000001))
                    (list
                        (list 1. 0. 0. 0.)
                        (list 0. (/ (caddr vec) Dist) (firstMulti (/ (cadr vec) Dist)) 0.)
                        (list 0. (secondMulti (/ (cadr vec) Dist)) (/ (caddr vec) Dist) 0.)
                        (list 0. 0. 0. 1.)
                     )
  )
      )
    ;---------------------------------------------------------------------------------------------
    (defun RotateAboutYAxis ( vec firstMulti secondMulti / Dist )
        (if (not (equal (setq Dist (sqrt (+ (* (cadr vec) (cadr vec)) (* (caddr vec) (caddr vec))))) 0. 0.00000001))
                (list
                    (list Dist 0. (firstMulti (car vec)) 0.)
                    (list 0. 1. 0. 0.)
                    (list (secondMulti (car vec)) 0. Dist 0.)
                    (list 0. 0. 0. 1.)
)
  )
      )
    ;---------------------------------------------------------------------------------------------
    (defun RotateAboutZAxis ( ang )
                (list
                    (list (cos ang) (- (sin ang)) 0. 0.)
                    (list (sin ang) (cos ang) 0. 0.)
                    (list 0. 0. 1. 0.)
                    (list 0. 0. 0. 1.)
                 )
    )
    ;---------------------------------------------------------------------------------------------
    (vlax-invoke obj 'Move org '(0. 0. 0.))
    (setq tmat
       (mxm
          (mxm
             (mxm
                (mxm (RotateAboutXAxis vec + -) (RotateAboutYAxis vec + -))
             (RotateAboutZAxis ang))
          (RotateAboutYAxis vec - +))
       (RotateAboutXAxis vec - +))
    )
    (vla-transformby obj (vlax-tmatrix tmat))
    (vlax-invoke obj 'Move '(0. 0. 0.) org)
    (princ "\n")
    (princ tmat)
(princ)
)
« Last Edit: August 16, 2011, 10:48:39 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube