POV-Ray : Newsgroups : povray.advanced-users : Tranformation matrix to change coordinate spaces : Re: Tranformation matrix to change coordinate spaces Server Time
6 May 2024 19:10:22 EDT (-0400)
  Re: Tranformation matrix to change coordinate spaces  
From: John VanSickle
Date: 11 May 2001 12:40:05
Message: <3AFC16E8.E0BEBDF2@erols.com>
Peter Popov wrote:
> 
> This probably does not deserve being here but anyway...
> 
> Can anyone (John? Please :) ) show me how to find a matrix that
> changes from one coordinate space (A0, Ax, Ay, Az) to another (A0',
> Ax', Ay', Az')? I found some info on the Net but I have problems
> finding the signs of the angles involved and it will probably be
> slower than some things I recall seeing here.

The advice that the others give is sound.  You need to calculate
the inversion of the first matrix, and then multiply this inversion
by the second matrix.

This is, by the way, the manner in which the Reorient() macro works.

If you happen to have this matrix:

matrix < vecx.x vecx.y, vecx.z,
         vecy.x vecy.y, vecy.z,
         vecz.x vecz.y, vecz.z,
         vecl.x vecl.y, vecl.z >

The following macro will invert it.  It cheats a bit, BTW,
in that it undoes the translation component (the vecl part),
and then undoes the rotation, scaling, and shearing that
is done by vecz, vecy, vecz.

#macro Inverse(vecx,vecy,vecz,vecl)
  #local vx=(vecx);
  #local vy=(vecy);
  #local vz=(vecz);
  #local det=vdot(vx,vcross(vy,vz));
  #if (det=0)
    #fatal "Invalid matrix supplied to macro.\n"
  #end
  #local ca=vx.x;  #local cb=vx.y;  #local cc=vx.z;
  #local cd=vy.x;  #local ce=vy.y;  #local cf=vy.z;
  #local cg=vz.x;  #local ch=vz.y;  #local ci=vz.z;

  translate -(vecl)
  matrix <
  (ce*ci-cf*ch)/det,(cc*ch-cb*ci)/det,(cb*cf-cc*ce)/det,
  (cf*cg-cd*ci)/det,(ca*ci-cc*cg)/det,(cc*cd-ca*cf)/det,
  (cd*ch-cg*ce)/det,(cb*cg-ca*ch)/det,(ca*ce-cb*cd)/det, 0,0,0>
#end

If you want to understand this sort of thing better (useful
for things outside of POV-Ray, too!), go find "matrix inversion"
and "matrix multiplication" on the Web, and find a page that
makes sense to you.

Hope this helps,
John
-- 
ICQ: 46085459


Post a reply to this message

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