Translation of object

Discussion in 'AutoCAD' started by BillZ, Jun 30, 2004.

  1. BillZ

    BillZ Guest

    R2005:

    I finally got to where I can rotate objects, using a matrix, around the x,y or z axis. is around 0,0, but that's okay for now.
    What I am having trouble understanding is the translation or the moving of the object, after the rotation.
    I've read some examples:

    Rotation Matrix: 45 degrees about point (5, 5, 0)

    0.707107 –0.707107 0.0 5.0

    0.707107 0.707107 0.0 –2.071068

    0.0 0.0 1.0 0.0

    0.0 0.0 0.0 1.0

    How does –2.071068 in row 2 constitue y5?
    It's says "about point (5, 5, 0)"

    I've been experimenting but have had no luck in getting the solution.

    TIA

    Bill
     
    BillZ, Jun 30, 2004
    #1
  2. BillZ

    MP Guest

    Bill,

    ;gathered from previous ng posts...

    ;;;As for the rotation about the origin, all matrix transformations are
    defined
    ;;;about the origin. You overcome that by first translating the desired
    ;;;basepoint to the coordinate system origin, perform the desired
    ;;;transformations, and then translating back to the basepoint.

    ;i.e.
    ;move object from basept to 0,0
    ;rotate around 0,0
    ;move object back from 0,0 to basept

    ;e.g.

    ;function names by Mark Propst
    ;function contents gleaned from many posts on this ng and hundreds of hours
    of head scratching and going..."huh?"
    ; many thanks to Jon Fleming, John Uhden, Vladimir Nesterovsky, Larry
    Leuallan, Doug Broad, et al for shedding some light in the murky waters of
    matrix manipulations
    ;I wish I actually understood any of this! :)


    ;rotate an object about a given base point by given angle around given axis
    ;usage: (rotObjBase vlaObj "X" 30 basept)
    ;example:
    (defun test()
    (setq vlaObj(vlax-ename->vla-object(car(entsel"\nPick something"))))
    (setq axis (Getstring"\nX Y or Z"))
    (setq ang (Getreal"\nEnter angle in degrees"))
    (setq basept(Getpoint"\nBase point"))
    (rotObjBase vlaObj axis ang basept)
    )

    (defun rotObjBase(inObj inaxis indeg inbase)
    (moveObj inobj (vectorize inbase))
    (rotObj inobj inaxis indeg)
    (moveObj inobj inbase)
    )

    (defun vectorize (pt)
    (mapcar '- pt))

    (defun moveobj(inObj invec)
    (vla-transformby
    inObj
    (vlax-tmatrix
    (makeMoveMtxList invec)
    )
    )
    )

    (defun rotObj(inObj inaxis indeg)
    (vla-transformby
    inObj
    (vlax-tmatrix
    (makeRotMtxlist inaxis indeg)
    )
    )
    )

    ;;;pass in degrees to this function to get a rotation matrix
    ;;;the function converts the degrees to radians internally
    ;;; making it simpler to call in programs where I probably know the
    ;;; degrees i want to rotate before i'd know the radians
    ;;; I could have done either way, pass in rads or degs, just decided to use
    degs
    ;;; some funcs return ang in rads though, so in future if usage ends up
    getting angs in rads
    ;;; then i can change this to accept rads instead of degs.

    (defun makeRotMtxlist(axis deg / rlist rad)
    ;(or dtr(load"UtilFuncs"))
    (setq rad(dtr deg)); i assume you have an equivalent function
    (cond
    ((= "X" (strcase axis))
    (setq rlist
    (list
    (list 1 0 0 0)
    (list 0 (cos rad)(-(sin rad)) 0)
    (list 0 (sin rad) (cos rad) 0)
    (list 0 0 0 1)
    )
    );setq
    );x
    ((= "Y" (strcase axis))
    (setq rlist
    (list
    (list (cos rad) 0 (sin rad) 0)
    (list 0 1 0 0)
    (list (-(sin rad)) 0 (cos rad) 0)
    (list 0 0 0 1)
    )
    );setq
    );y
    ((= "Z" (strcase axis))
    (setq rlist
    (list
    (list (cos rad) (- (sin rad)) 0.0 0.0)
    (list (sin rad) (cos rad) 0.0 0.0)
    (list 0.0 0.0 1.0 0.0)
    (list 0.0 0.0 0.0 1.0)
    )
    );setq
    );z
    (1
    (princ"\nInvalid axis input")
    )
    );cond
    rlist
    )

    (defun makeMoveMtxList(invec)
    (list
    (list 1.0 0.0 0.0 (car invec))
    (list 0.0 1.0 0.0 (cadr invec))
    (list 0.0 0.0 1.0 (caddr invec))
    (list 0.0 0.0 0.0 1.0)
    )
    )

    hth
    Mark

    x,y or z axis. is around 0,0, but that's okay for now.
    the object, after the rotation.
     
    MP, Jul 1, 2004
    #2
  3. BillZ

    BillZ Guest

    Thanks Mark,
    This is all great infomation and I'm sure it will help as I develop this program.
    It's not a project that has any fixed deadline.
    If I could come up with a new app, it would make our dept. look good though. :)

    I'll be working on this right along, so expect me back without warning.

    Bill
     
    BillZ, Jul 1, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.