POV-Ray : Newsgroups : povray.advanced-users : Tranformation matrix to change coordinate spaces Server Time
6 May 2024 11:30:54 EDT (-0400)
  Tranformation matrix to change coordinate spaces (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
From: Warp
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 11:08:12
Message: <3afc005c@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: First you need to calculate the inverse of 

  Also note that not all matrices can be inverted (it's an analog case to
real numbers, where 0 has no inverse).

  This is why a scale<1,0,0> is not allowed in povray (it would generate
a non-invertable matrix).

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Ron Parker
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 11:09:25
Message: <slrn9fo05b.m7q.ron.parker@fwi.com>
On 11 May 2001 11:08:12 -0400, Warp wrote:
>Ron Parker <ron### [at] povrayorg> wrote:
>: First you need to calculate the inverse of 
>
>  Also note that not all matrices can be inverted (it's an analog case to
>real numbers, where 0 has no inverse).

True, but if those really are basis vectors, the inverse should exist.

-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end 
Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}


Post a reply to this message

From: John VanSickle
Subject: Re: Tranformation matrix to change coordinate spaces
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

From: Warp
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 12:49:59
Message: <3afc1837@news.povray.org>
The Matrix Master has spoken. :)

  Nice stuff. It's good that at least someone knows about matrices because
it's one of the most unknown fields of math here (even I haven't studied
them enough to answer this kind of question).

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Chris Huff
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 16:51:40
Message: <3afc50db@news.povray.org>
John VanSickle <van### [at] erolscom> wrote:
> 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.

> 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.

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?


> 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...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.

This is a good POV-specific page: ;-)
http://enphilistor.users4.50megs.com/matrix.htm

Also:
http://davidf.faricy.net/povre.html
http://www.shipbrook.com/jeff/raytrace/matrix.html
http://www.cix.co.uk/~gbreed/matritut.htm


-- 
Christopher James Huff - chr### [at] maccom
Home Page: http://homepage.mac.com/chrishuff/
POV-Ray TAG e-mail: chr### [at] povrayorg
POV-Ray TAG web site: http://tag.povray.org/


Post a reply to this message

From: Francois Labreque
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 21:45:21
Message: <3AFC9483.2A370897@videotron.ca>
Warp wrote:
> 
>   The Matrix Master has spoken. :)
> 
>   Nice stuff. It's good that at least someone knows about matrices because
> it's one of the most unknown fields of math here (even I haven't studied
> them enough to answer this kind of question).

Watch it bud!  I studied matrices thoroughly in university - mechanical
engineering wiht a specialiation in finie elements analysis.

However, six years of work in a completely unrelated field - networking
- has made me forget most of it.

-- 
Francois Labreque | In the future, performance will be measured
    flabreque     | by the size of your pipe.
        @         |             - Dogbert, on networking
   videotron.ca   |


Post a reply to this message

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 4 Messages Goto Initial 10 Messages

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