POV-Ray : Newsgroups : povray.advanced-users : Tranformation matrix to change coordinate spaces Server Time
26 Apr 2024 07:55:41 EDT (-0400)
  Tranformation matrix to change coordinate spaces (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: Peter Popov
Subject: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 03:59:33
Message: <hb4nftstffp43ia7le4qpbvassaqhsi2gb@4ax.com>
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.

Thanks in advance.


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


Post a reply to this message

From: Rune
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 06:32:22
Message: <3afbbfb6@news.povray.org>
"Peter Popov" wrote:
> 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.

Do you need access the matrix itself or do you just need a transformation
that works?

If the latter, and if you use MegaPov, you can use:

transform {Coordinate_space1_matrix inverse}
transform {Coordinate_space2_matrix}

This is untested code, but I think it was something like that.

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated May 10)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Peter Popov
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 07:42:24
Message: <8sjnft4eusdddpsrgtb2css6jvhtmus9sl@4ax.com>
On Fri, 11 May 2001 10:53:09 +0200, "Rune"
<run### [at] mobilixnetdk> wrote:

>Do you need access the matrix itself or do you just need a transformation
>that works?

I need the matrix and how to find the coefficients, POV SDL if
possible. I will eventually code it in C++ but don't spoil the fun and
let me do that part myself :)

>If the latter, and if you use MegaPov, you can use:
>
>transform {Coordinate_space1_matrix inverse}
>transform {Coordinate_space2_matrix}
>
>This is untested code, but I think it was something like that.

OK, I'll test it (d/ling MP/Linux atm)


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


Post a reply to this message

From: Ron Parker
Subject: Re: Tranformation matrix to change coordinate spaces
Date: 11 May 2001 08:57:44
Message: <slrn9fnoed.m36.ron.parker@fwi.com>
On Fri, 11 May 2001 10:58:10 +0300, 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.

First you need to calculate the inverse of 

  Ax.x Ax.y Ax.z A0.x
  Ay.x Ay.y Ay.z A0.y
  Az.x Az.y Az.z A0.z
   0    0    0    1

and then multiply that by 

  Ax'.x Ax'.y Ax'.z A0'.x
  Ay'.x Ay'.y Ay'.z A0'.y
  Az'.x Az'.y Az'.z A0'.z
    0     0     0     1

(but I might have that transposed from what you expect, or I might have the 
A0s running along the wrong side of the matrix, so check it first.)

The first matrix (once inverted) should transform back into (0,x,y,z) space, 
and the second transforms to your second space.

-- 
#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: 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

Goto Latest 10 Messages Next 4 Messages >>>

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