POV-Ray : Newsgroups : povray.advanced-users : Tranformation matrix to change coordinate spaces Server Time
6 May 2024 18:33:17 EDT (-0400)
  Tranformation matrix to change coordinate spaces (Message 11 to 14 of 14)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: John VanSickle
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 12 May 2001 07:41:28
Message: <3AFD226D.721FD4CB@erols.com>
Chris Huff wrote:
> 
> If you are using MegaPOV, it would be much easier to use:
> 
> transform {matrix <...> inverse}
> 
> This is even more useful, since you can specify any series of
> transforms, and use declared transforms...however, it can't be used to
> get the matrix, as your macro can be modified to do.
> 
> Or maybe it can...it should be possible by using vtransform() to
> "scan" a matrix, using x, y, and z to get the first 3 columns, and
> < 0, 0, 0> to get the fourth...right?

First you would use vtransform on <0,0,0> to get the translation
component (call it, say vL); then you use vtransform on x, y and
z, separately, and subtract vL from the results of each.

> > 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.
> 
> www.google.com is very helpful here...

Google is helpful no matter *what* you're looking for...

> For POV-specific pages, try the
> links page on povray.org, but the ones I've found don't explain
> inversion and stuff, just how to use the matrix transform.

True.

Regards,
John
-- 
ICQ: 46085459


Post a reply to this message

From: Peter Popov
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 12 May 2001 16:24:15
Message: <gd3rftk1taoovn2cbupeqc944f2hkg26pi@4ax.com>
I followed Rune's advice and was able to figure it out from there on
(after some transposing). I still don't understand John's inversion
macro. I know how to invert a matrix, but our Neo is doing some odd
stuff with the matrix there that I don't understand. Anyway, I will be
adding matrix multiplication and matrix transformations to the vector
class I am using, so I might as well use Rune's way.

Thanks for your help, guys!


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] vipbg
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 6 Aug 2001 14:19:33
Message: <3B6EE0A3.31C9731C@hotmail.com>
John VanSickle wrote:
>...
> 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
>...

Here's a shorter version of it:


#macro InvTransform(vX, vY, vZ, vL)

  #local Det = vdot(vX, vcross(vY, vZ));
  #if (Det = 0)
    #error "Macro InvTransform: Invalid matrix supplied.\n"
  #end // if
  #local vA = vcross(vY, vZ)/Det;
  #local vB = vcross(vZ, vX)/Det;
  #local vC = vcross(vX, vY)/Det;

  translate -vL
  matrix <
    vA.x, vB.x, vC.x,
    vA.y, vB.y, vC.y,
    vA.z, vB.z, vC.z,
    0,    0,    0
  >

#end // macro InvTransform


For those of you that want to see an 
example on how to use this macro;
see my example code below.


Best regards,

-- 
Tor Olav Kristensen
Email: tor### [at] hotmailcom
http://hjem.sol.no/t-o-k
http://www.crosswinds.net/~tok


// ===== 1 ======= 3 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
// By Tor Olav Kristensen

#version 3.1;

#include "colors.inc"

// ===== 1 ======= 3 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#macro Transform(vX, vY, vZ, vL)

  #local Det = vdot(vX, vcross(vY, vZ));
  #if (Det = 0)
    #error "Macro Transform: Invalid matrix supplied.\n"
  #end // if

  matrix <
    vX.x, vX.y, vX.z,
    vY.x, vY.y, vY.z,
    vZ.x, vZ.y, vZ.z,
    vL.x, vL.y, vL.z
  >

#end // macro Transform


#macro InvTransform(vX, vY, vZ, vL)

  #local Det = vdot(vX, vcross(vY, vZ));
  #if (Det = 0)
    #error "Macro InvTransform: Invalid matrix supplied.\n"
  #end // if
  #local vA = vcross(vY, vZ)/Det;
  #local vB = vcross(vZ, vX)/Det;
  #local vC = vcross(vX, vY)/Det;

  translate -vL
  matrix <
    vA.x, vB.x, vC.x,
    vA.y, vB.y, vC.y,
    vA.z, vB.z, vC.z,
    0,    0,    0
  >

#end // macro InvTransform

// ===== 1 ======= 3 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#declare vXX = <1, -0.3, 2>;
#declare vYY = <2, 1, 0>;
#declare vZZ = <0.3, 0, 1>;
#declare vLL = <0, -1.5, 0>;

#declare Box = box { -<1, 2, 3>, <1, 2, 3> }

object { Box pigment { color White } }

object {
  Box
  scale 1.00001 // scale 0.99999
  pigment { color Red }
  Transform(vXX, vYY, vZZ, vLL)
//  InvTransform(vXX, vYY, vZZ, vLL)
}
// Uncomment the InvTransform line above
// to see the Box transformed back.

// ===== 1 ======= 3 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

background { color Blue /2 } 

light_source { <2, 3, -1>*100 color White }

camera {
  location <1, 1, -2>*5
  look_at <0, 0, 0>
}

// ===== 1 ======= 3 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =


Post a reply to this message

From: John VanSickle
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 7 Aug 2001 14:14:54
Message: <3B7030D9.96271197@hotmail.com>
Tor Olav Kristensen wrote:
> 
> John VanSickle wrote:
> >...
> > 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.

<snip>

> Here's a shorter version of it:

Yup.  I had something like that lying around somewhere, but couldn't put
my mouse on the file, so I typed up what I did instead.

Regards,
John
-- 
ICQ: 46085459


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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