POV-Ray : Newsgroups : povray.advanced-users : Deriving a matrix from a transform : Deriving a matrix from a transform Server Time
28 Jul 2024 14:31:08 EDT (-0400)
  Deriving a matrix from a transform  
From: David Wallace
Date: 30 Mar 2005 00:20:39
Message: <424a3727$1@news.povray.org>
If I have a complex transform like:

<code>
#macro ReorientCenter(Point1,Axis1,Point2,Axis2)
   #local vX1=vnormalize(Axis1);
   #local vX2=vnormalize(Axis2);
   #local vY=vnormalize(vcross(vX1,vX2));
   #local vZ1=vnormalize(vcross(vX1,vY));
   #local vZ2=vnormalize(vcross(vX2,vY));
   translate -Point1
   matrix < vX1.x, vY.x,vZ1.x, vX1.y,vY.y,vZ1.y, vX1.z,vY.z, vZ1.z, 0,0,0 >
   matrix < vX2.x,vX2.y,vX2.z,  vY.x,vY.y, vY.z, vZ2.x,vZ2.y,vZ2.z, 0,0,0 >
   translate Point2
#end
</code>

How would I retrieve the resulting matrix so that I could use it in a file like 
this:

#write (lFile, "object { Lamb matrix <",mxx, mxy, mxz, myx, myy, myz, mzx, mzy, 
mzz, mtx, mty ,mtz,"> }\n")

My guess would be this:

<code>
#macro vtransform(vec, trans)
    #local fn = function { transform { trans } }
    #local result = (fn(vec.x, vec.y, vec.z));
    result
#end

#macro Trans_Matrix(trn)
   #declare _mtx = array[12]
   #local _rt = vtransform(<0,0,0>,trn);
   #set _mtx[9] = _rt.x;
   #set _mtx[10] = _rt.y;
   #set _mtx[11] = _rt.z;
   #local _xt = vtransform(x,trn)-_rt;
   #set _mtx[0] = _xt.x;
   #set _mtx[1] = _xt.y;
   #set _mtx[2] = _xt.z;
   #local _yt = vtransform(y,trn)-_rt;
   #set _mtx[3] = _yt.x;
   #set _mtx[4] = _yt.y;
   #set _mtx[5] = _yt.z;
   #local _zt = vtransform(z,trn)-_rt;
   #set _mtx[6] = _zt.x;
   #set _mtx[7] = _zt.y;
   #set _mtx[8] = _zt.z;
#end

#declare trnLamb = transform { ReorientCenter(org, ori, trg, pnt) }
Trans_Matrix(trnLamb)
#write (lFile, "object { Lamb matrix <")
#local i = 0;
#while (i<12)
   #write (lFile, _mtx[i])
   #set i = i + 1;
#end
#write (lFile, "> }\n")
</code>

Does anyone have an easier solution?

--------------
David Wallace
TenArbor Consulting
"Just In Time Cash"
www.tenarbor.com
1-866-572-CASH


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.