more efficient way?

Discussion in 'AutoCAD' started by Devin, Aug 2, 2003.

  1. Devin

    Devin Guest

    is there a more efficient way to translate? I think this is the same method
    as Jon's but I needed to write it out to understand it. Anyway, I'm
    thinking a mapcar solution. Any ideas?

    (defun identity->matrix ( pt mat /
    px py pz #0 #1 #2
    #00 #01 #02 #03
    #10 #11 #12 #13
    #20 #21 #22 #23
    )
    (setq;extract pt
    px (car pt)
    py (cadr pt)
    pz (caddr pt)
    )
    (setq;extract matrix
    #0 (nth 0 mat) #1 (nth 1 mat) #2 (nth 2 mat)
    #00 (nth 0 #0) #01 (nth 1 #0) #02 (nth 2 #0) #03 (nth 3 #0)
    #10 (nth 0 #1) #11 (nth 1 #1) #12 (nth 2 #1) #13 (nth 3 #1)
    #20 (nth 0 #2) #21 (nth 1 #2) #22 (nth 2 #2) #23 (nth 3 #2)
    )
    (list;rotate/translate pt
    (+ (* px #00) (* py #01) (* pz #02) #03)
    (+ (* px #10) (* py #11) (* pz #12) #13)
    (+ (* px #20) (* py #21) (* pz #22) #23)
    )
    )

    (defun matrix->identity ( pt mat /
    px py pz #0 #1 #2
    #00 #01 #02 #03
    #10 #11 #12 #13
    #20 #21 #22 #23
    )
    (setq;extract pt
    px (car pt)
    py (cadr pt)
    pz (caddr pt)
    )
    (setq;extract matrix
    #0 (nth 0 mat) #1 (nth 1 mat) #2 (nth 2 mat)
    #00 (nth 0 #0) #01 (nth 1 #0) #02 (nth 2 #0) #03 (nth 3 #0)
    #10 (nth 0 #1) #11 (nth 1 #1) #12 (nth 2 #1) #13 (nth 3 #1)
    #20 (nth 0 #2) #21 (nth 1 #2) #22 (nth 2 #2) #23 (nth 3 #2)
    )
    (setq;translate pt
    px (- px #03)
    py (- px #13)
    pz (- px #23)
    )
    (list;rotate pt
    (+ (* px #00) (* py #10) (* pz #20))
    (+ (* px #01) (* py #11) (* pz #21))
    (+ (* px #02) (* py #12) (* pz #22))
    )
    )
     
    Devin, Aug 2, 2003
    #1
  2. Devin

    Devin Guest

    Oops, mistake in my code...
    should be...
     
    Devin, Aug 2, 2003
    #2
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.