Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rotate a list of points?

7 REPLIES 7
Reply
Message 1 of 8
mdhutchinson
517 Views, 7 Replies

Rotate a list of points?

okay... one of the hardest concepts (at least for me) to understand is transformation matrices... I will admit...

Can't someone help me? ... how can I run a list of points through a function and have them come out rotated by a given angle?
7 REPLIES 7
Message 2 of 8
BillZ
in reply to: mdhutchinson

Hi hutch,

I went through the whole gambit of matrixes a while back.

Seems to me one of the hurdles that threw me off was the fact that on all the math forums, matrices were written out in columns and in the Autolisp help, they were written in rows, or maybe it was vice versa... but you get the idea.

Pisano, Domenico Maria, had helped someone here (I believe Devin) with a routine called "axial_rotate" which I ended up using in some of my programs.

Jon Fleming has also posted some great utilities for 3d rotation of points. "3dxform.lsp" was a good one. And he has more at his site.

Vladimir Nesterovsky, is another that comes to mind as one who has posted many formulas here to do the math.
http://discussion.autodesk.com/thread.jspa?messageID=1107642

Here: is some further explainations:

http://www.gamedev.net/reference/articles/article695.asp
http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm
http://gpwiki.org/index.php/3D:Matrix_Math

HTH

Bill Message was edited by: BillZ
Message 3 of 8
mdhutchinson
in reply to: mdhutchinson

this remains more than I can wrap my head around... until I can get more deeply into it the following will work... thanks to one of the engineers just down the hall..
Call this simply like this... (rotate ang pntlist) \
this seems to work... I just have to plug it into my application now.

(defun rotate (ang pntlist / x y)
(setq ang (DtoR ang))
(mapcar '(lambda (x)
(setq y (cadr x)
x (car x)
)
(list (+ (* x (cos ang)) (* y (sin ang)))
(- (* y (cos ang)) (* x (sin ang)))
))
pntlist
)
)
(defun DtoR (numberOfDegrees)
(* pi (/ numberOfDegrees 180.0)))
Message 4 of 8
mdhutchinson
in reply to: mdhutchinson

sorry for the stray character '\'
Message 5 of 8
tom_brabant
in reply to: mdhutchinson

Here are some fragments that might help; pasted them in from a previous project.
(mapcar '(lambda (p)(rotxy theta p)) yourpointlist)
;.................................................
(defun c:t ()
(setq
p (4d (getpoint "\nPick point to transform: "))
np (3d (rotxz (dtr -45.0) p))
)
(command "point" np)
)
;.....................................................
(defun dotprod (x y)(apply '+ (mapcar '* x y)))
(defun matvec4 (M v)
(mapcar '(lambda (u)(dotprod u v)) M)
)
(defun 4d (v);headed for homogenous rep [tacking a 1 on]
(reverse (cons 1 (reverse v)))
)
(defun 3d (v);return R4 point to R3
(mapcar '/ (list (car v)(cadr v)(caddr v))
(list (cadddr v)(cadddr v)(cadddr v))
)
)
;.....................................................
(defun rotxy (th p);rotation of p by theta around '(0 0 0) in xy-plane
(matvec4
(list ;row1
(list (cos th) (- (sin th)) 0 0 )
(list (sin th) (cos th) 0 0 )
(list 0 0 1 0 )
(list 0 0 0 1 )
)
p
)
)
(defun rotxz (th p);rotation of p by theta around '(0 0 0) in xz-plane
(matvec4
(list ;row1
(list (cos th) 0 (- (sin th)) 0 )
(list 0 1 0 0 )
(list (sin th) 0 (cos th) 0 )
(list 0 0 0 1 )
)
p
)
)
(defun rotyz (th p)());left as an exercise
Message 6 of 8
tom_brabant
in reply to: mdhutchinson

Pardon, there's a comment in there that contains the word "homogenous". It should be "homogeneous" (one resource: http://bishopw.loni.ucla.edu/AIR5/homogenous.html). I've got more code, and more info on this if would help.
Message 7 of 8
BillZ
in reply to: mdhutchinson

"homogenous" is what your brain feels like after figuring this out. :^)


Here's one that I devised.

Usage: (setq RotMtx (RotMat 0.0 pi 0.0)) ;get rotation matrix.
(setq p1 (cdr (assoc 10 nen)) ;get point to rotate.
p1 (trans p1 0 2)
p1 (mxv RotMtx p1)
p1 (vl-remove (last p1) p1) ;new point.
)

[code]
;;8/26/05 Revised to columns
;;Usage - Input x,y,z rotation angles, creates rotation matrix.
;;
;;angx, angy, angz are angle around each, x = pitch, axis = y = roll, z = yaw.
;;

(defun RotMat (angx angy angz / Rot_Matrix)

(setq Rot_Matrix (list

(list (+ (* (cos angz)(cos angy))(* (sin angz)(sin angx)(sin angy)))
(* (sin angz)(cos angx))
(+ (* (sin angz)(sin angx)(cos angy))(* (cos angz)(- (sin angy))))
0.0)

(list (+ (* (- (sin angz))(cos angy))(* (cos angz)(sin angx)(sin angy)))
(* (cos angz)(cos angx))
(+ (* (cos angz)(sin angx)(cos angy))(* (sin angz)(sin angy)))
0.0)

(list (* (cos angx)(sin angy))
(- (sin angx))
(* (cos angx)(cos angy))
0.0)

(list 0.0 0.0 0.0 1.0)) ;perspective row.
) ;end setq
Rot_Matrix
)[/code]

Seems to work for my app. so that's when my research ended.

;----------------------------------------------;
;Vladimir Nesterovsky - Matrix function
(defun mxv (m v) ;NewP = Matrix * Point
(mapcar '(lambda (row) (dotprod row v)) m)
)
;---;
;Vladimir Nesterovsky - Matrix function
(defun dotprod (u v)
(apply '+ (mapcar '* u v))
)
;---------------------------------------------;


Bill Message was edited by: BillZ
Message 8 of 8
BillZ
in reply to: mdhutchinson

Oh, Hutch, another thing that I realized about rotation matrixes.
Seemed like the results rotated the point based on the 0,0,0 coordiante. So you had to take that into consideration.
And yeah, there were rounding errors that made for accumalitive differences in results. In other words, on a large list of points, you could be off an inch or two by the end.
I found this out on a mesh unfold program.

Bill

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost