POV-Ray : Newsgroups : povray.advanced-users : Matrix question Server Time
11 Oct 2026 14:38:56 EDT (-0400)
  Matrix question (Message 1 to 24 of 24)  
From: Rune
Subject: Matrix question
Date: 21 Dec 2000 16:25:08
Message: <3a427534@news.povray.org>
I have a matrix A. Then I transform it by the matrix B. The result is Matrix
C. Given A and C, how do I find B ?

Instead of matrixes the input and output should be sets of 4 vectors each.

I imagine a macro like this:

FindMatrix (Ax,Ay,Az,Ap,Cx,Cy,Cz,Cp)

It would #declare the vectors Bx, By, Bz and Bp

Thanks in advance!

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 December 17)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Francois Labreque
Subject: Re: Matrix question
Date: 21 Dec 2000 18:08:41
Message: <3A428CA3.D5E323E7@videotron.ca>
Rune wrote:
> 
> I have a matrix A. Then I transform it by the matrix B. The result is Matrix
> C. Given A and C, how do I find B ?

[A][B] = [C]

Premultiply both sides by the inverse of [A]

[A-1][A][B] = [A-1][C]

a matrix times its inverse is the indentity matrix, hence

[1][B] = [A-1][C]

any matrix times the identity matrix is the matrix itself, hence

[B] = [A-1][C]

Q.E.D.

However, this only works for square matrices (if my math isn't too
rusty).

> 
> Instead of matrixes the input and output should be sets of 4 vectors each.
> 
> I imagine a macro like this:
> 
> FindMatrix (Ax,Ay,Az,Ap,Cx,Cy,Cz,Cp)
> 
> It would #declare the vectors Bx, By, Bz and Bp

The macro coding is left to the student as an exercice. :)

-- 
Francois Labreque | Rimmer: "Let's go to red alert!"
    flabreque     | Kryten: "Are you sure, Sir?  You realize it
        @         |          actually means changing the bulb!"
   videotron.ca


Post a reply to this message

From: Rune
Subject: Re: Matrix question
Date: 21 Dec 2000 18:55:37
Message: <3a429879@news.povray.org>
"Francois Labreque" wrote:
> [A][B] = [C]
>
> Premultiply both sides by the inverse of [A]

You've lost me. Too tricky for me.

> However, this only works for square matrices (if my math
> isn't too rusty).

AFAIK the matrixes in POV-Ray are square. the last column is always 0,0,0,1

> The macro coding is left to the student as an exercice. :)

But that's the tricky part! ...too!

I only know how to use matrixes in POV-Ray.
I don't have any general matrix knowledge at all. :(

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 December 17)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Wlodzimierz ABX Skiba
Subject: Re: Matrix question
Date: 22 Dec 2000 04:30:27
Message: <3a431f33@news.povray.org>
Rune wrote in message <3a429879@news.povray.org>...
> I only know how to use matrixes in POV-Ray.
> I don't have any general matrix knowledge at all. :(


http://forum.swarthmore.edu/library/topics/matrices/

good luck :-)

ABX


Post a reply to this message

From: Warp
Subject: Re: Matrix question
Date: 22 Dec 2000 04:50:45
Message: <3a4323f5@news.povray.org>
Rune <run### [at] inamecom> wrote:
:> Premultiply both sides by the inverse of [A]

: You've lost me. Too tricky for me.

  Just calculate the inverse matrix of A and then multiply A*C (matrix
multiplication, not item-by-item multiplication) and you'll get B.

  Calculating the inverse of a matrix is not a simple operation, though.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Matrix question
Date: 22 Dec 2000 08:39:55
Message: <slrn946mdd.4h2.ron.parker@fwi.com>
On 22 Dec 2000 04:50:45 -0500, Warp wrote:
>Rune <run### [at] inamecom> wrote:
>:> Premultiply both sides by the inverse of [A]
>
>: You've lost me. Too tricky for me.
>
>  Just calculate the inverse matrix of A and then multiply A*C (matrix
>multiplication, not item-by-item multiplication) and you'll get B.
>
>  Calculating the inverse of a matrix is not a simple operation, though.

I think there's a can't-miss formula for the inverse of a 3x3 matrix, but
I don't remember it off the top of my head.  And of course it doesn't work
for noninvertable matrices.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Warp
Subject: Re: Matrix question
Date: 22 Dec 2000 08:48:55
Message: <3a435bc7@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: I think there's a can't-miss formula for the inverse of a 3x3 matrix, but
: I don't remember it off the top of my head.

  But I think that povray matrices are 4x4 (and I think the original poster
was talking about povray matrices if I'm not mistaken).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Matrix question
Date: 22 Dec 2000 09:56:58
Message: <slrn946qts.4ig.ron.parker@fwi.com>
On 22 Dec 2000 08:48:55 -0500, Warp wrote:
>Ron Parker <ron### [at] povrayorg> wrote:
>: I think there's a can't-miss formula for the inverse of a 3x3 matrix, but
>: I don't remember it off the top of my head.
>
>  But I think that povray matrices are 4x4 (and I think the original poster
>was talking about povray matrices if I'm not mistaken).

They're not really.  The fourth column is just a convenient way of specifying
the translate component.  You could easily take that out, invert, and put 
it back.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Josh English
Subject: Re: Matrix question
Date: 22 Dec 2000 11:29:57
Message: <3A4381AC.4EADC643@spiritone.com>
Rune wrote
I have a matrix A. Then I transform it by the matrix B. The result is Matrix

> C. Given A and C, how do I find B ?
>
> Instead of matrixes the input and output should be sets of 4 vectors each.
>
> I imagine a macro like this:
>
> FindMatrix (Ax,Ay,Az,Ap,Cx,Cy,Cz,Cp)
>
> It would #declare the vectors Bx, By, Bz and Bp

Tricky question.... well, not tricky, but complicated.
You can find B as the product of A^-1*C, so finding that inverse is tricky.

For a square matrix A, the inverse of A is 1/det(A)*adj(A), or in English, the
Adjoint of A divided by the determinant. (The determinant is a scalar value that
we can find from A).

So, A =
a b c 0
d e f  0
g h i 0
j k l 1.

(I know, a fixed width font would be good for that.)
To find the determinant of A, we can use a shortcut and use the fourth column,
so we only need to find the determinant of the 3 by 3 matrix a...i:
det(A) = a(ei - fh) - b(di - fg) + c(dh - eg)  and you better make sure that
this doesn't equal 0, if it does you can't find an inverse.

To find the adjoint we find the cofactors of A which is defined by
(-1)^(i+j)det(Mij)  Here i and j refer to the row and column of the matric
element (just to clarify a muddy situation)
Mij is the Minor of Aij, which means we remove row i and column j and we have a
smaller square matrix (3 by 3 in this scenario)
So to find the Minor of a in our original matrix, we are left with the 3 by 3
matrix
e f 0
h i 0
k l 1
and since we need the determinant of this three by three matrix, we take
advantage of the last column, and det(M11) = ei - fh. I hope you understand,
because I leave you to figure out the rest of the Minors, and remember that you
still have to mulitply the determinant of the Minor by (-1)^(i + j), basically,
this forms a checkerboard pattern of negatives, so the the determinant of the
Minor calculated for element a  is normal, the determinant for the Minor
calculated for values b,d,f,h,j, and l are multiplied by -1, and you will still
have minors down the fourth column.
Once you have 16 cofactors, divide each one by the determinate we calculated in
the beginning, and you should have your inverse matrix. If you want to check,
multiply A by its inverse and see if you get the identity matrix, which is a
matrix of 0's except the diagonal from top left to bottom right should be 1's.

This is probably more glib than it needs to be, so I won't be offended by
questions.

--
Josh English -- Lexiphanic Lethomaniac
eng### [at] spiritonecom
The POV-Ray Cyclopedia http://www.spiritone.com/~english/cyclopedia/


Post a reply to this message

From: Josh English
Subject: Re: Matrix question
Date: 22 Dec 2000 14:45:04
Message: <3A43AF3F.7B72DA6C@spiritone.com>
Silly me, I already solved the problem of how to find the inverse of a matrix to
deal with a collision model for POV-Ray wth the help of a friend:

Here is the relevant code:
// The POV_Ray representation of the matrix that we need to find the inverse of.
#declare bX = <1,-0.05,0>;
#declare bY = <-0.5,0.5,0>;
#declare bZ = <0,0,1>;
#declare bC = <0,0,0>;

// THe 16 statements to fill out the 16 elements of the inverse
// // New system devised by David Jones
#declare dp = bX.x*bY.z - bX.z*bY.x;
#declare dq = bX.z*bY.y - bX.y*bY.z;
#declare dr = bX.x*bY.y - bX.y*bY.x;
#declare dt = bX.y*bZ.x - bZ.y*bX.x;

#declare dy = bZ.x*dq - bZ.y*dp + bZ.z*dr;
#declare dx = bC.x*dq - bC.y*dp + bC.z*dr;

#declare c11 = (bY.y * bZ.z - bY.z * bZ.y)/dy;
#declare c12 = (bX.z * bZ.y - bX.y * bZ.z)/dy;
#declare c13 = (bX.y * bY.z - bX.z * bY.y)/dy;
#declare c14 = 0;

#declare c21 = (bY.z * bZ.x - bY.x * bZ.z)/dy;
#declare c22 = (bX.x * bZ.z - bX.z * bZ.x)/dy;
#declare c23 = (bX.z * bY.x - bX.x * bY.z)/dy;
#declare c24 =0;

#declare c31 = (bY.x * bZ.y - bY.y * bZ.x)/dy;
#declare c32 = (bX.y * bZ.x - bZ.y * bX.x)/dy;
#declare c33 = (bX.x * bY.y - bX.y * bY.x)/dy;
#declare c34 = 0;

#declare c41 = -1*(bC.x * c11 + bC.y * c21 + bC.z * c31);
#declare c42 = -1*(bC.x * c12 + bC.y * c22 + bC.z * c23);
#declare c43 = -1*(bC.x * c13 + bC.y * c23 + bC.z * c33);
#declare c44 = 1;

This seemed to work after all of my tests, and it was a lot faster

Josh


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Matrix question
Date: 22 Dec 2000 16:41:15
Message: <3A43C7B4.31BF7900@online.no>
Rune wrote:
> 
> "Francois Labreque" wrote:
> > [A][B] = [C]
> >
> > Premultiply both sides by the inverse of [A]
> 
> You've lost me. Too tricky for me.

Hello Rune

Back in March i made some POV-macros 
that do matrix calculations on 3x3
matrices stored in POV-arrays.

If you have a look at these two posts:

news://news.povray.org/38CCE1C6.4947A712%40hotmail.com
news://news.povray.org/38CEBC39.582A511F%40online.no

(My thread "Different error messages for same POV-file")

then maybe you are able to see how to find 
the inverse of a matrix with POV-script.
(Look at the Minv macro.)

I think that I also have some newer code 
that does the same (and maybe more) if 
you are interested.


Best regards,

Tor Olav
-- 
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: Rune
Subject: Re: Matrix question
Date: 22 Dec 2000 17:55:42
Message: <3a43dbee@news.povray.org>
"Josh English" wrote:
> Silly me, I already solved the problem of how to find the inverse
> of a matrix to deal with a collision model for POV-Ray wth the
> help of a friend

Thank you very much!

To be honest I don't understand any of it, but it seems to work very well.

To really understand it I'd have to learn about matrixes all from the
beginning. I haven't learned about it in school, and I've not been able to
find a place on the net that describes it thoroughly enough.

But it works anyway... :)

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 December 17)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Rune
Subject: Re: Matrix question
Date: 22 Dec 2000 17:55:44
Message: <3a43dbf0@news.povray.org>
"Warp" wrote:
>   Just calculate the inverse matrix of A and then multiply A*C
> (matrix multiplication, not item-by-item multiplication) and
> you'll get B.

Thanks for your help.

If I've understood it correctly, to multiply matrixes in POV-Ray I can
simply apply both matrixes to the object (first A, then C), right?

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 December 17)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Rune
Subject: Re: Matrix question
Date: 22 Dec 2000 17:55:45
Message: <3a43dbf1@news.povray.org>
"Francois Labreque" wrote:
> [A][B] = [C]
>
> [B] = [A-1][C]

Thanks for your help.

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 December 17)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Chris Huff
Subject: Re: Matrix question
Date: 22 Dec 2000 19:05:40
Message: <chrishuff-C060DC.19065122122000@news.povray.org>
In article <3a43dbf0@news.povray.org>, "Rune" <run### [at] inamecom> 
wrote:

> If I've understood it correctly, to multiply matrixes in POV-Ray I can
> simply apply both matrixes to the object (first A, then C), right?

Depends on what you want to do...matrices are multiplied together to 
concatenate the transforms, but you won't be able to retrieve the 
matrix. And if you really only want to manipulate objects or vectors, 
and don't care about the matrices themselves, MegaPOV allows you to 
transform vectors and use inverse transformations without needing any 
macros.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Rune
Subject: Re: Matrix question
Date: 23 Dec 2000 10:31:12
Message: <3a44c540@news.povray.org>
"Chris Huff" wrote:
> "Rune" wrote:
>
> > If I've understood it correctly, to multiply matrixes in
> > POV-Ray I can simply apply both matrixes to the object
> > (first A, then C), right?
>
> Depends on what you want to do...matrices are multiplied
> together to concatenate the transforms, but you won't be
> able to retrieve the matrix.

I haven't figured it all out yet, but I *think* I won't need the matrix
itself.

> And if you really only want to manipulate objects or
> vectors, and don't care about the matrices themselves,
> MegaPOV allows you to transform vectors and use inverse
> transformations without needing any macros.

Uh, clever!

Erm, hehe, I guess that means I don't need the inverse matrix macro after
all...

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 December 17)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Warp
Subject: Re: Matrix question
Date: 24 Dec 2000 12:17:09
Message: <3a462f94@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: They're not really.  The fourth column is just a convenient way of specifying
: the translate component.  You could easily take that out, invert, and put 
: it back.

  But aren't the rays also translated with the inverse translation of the
object? Isn't the whole 4x4 matrix inverted?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Matrix question
Date: 24 Dec 2000 12:56:40
Message: <slrn94ce3t.5q0.ron.parker@fwi.com>
On 24 Dec 2000 12:17:09 -0500, Warp wrote:
>Ron Parker <ron### [at] povrayorg> wrote:
>: They're not really.  The fourth column is just a convenient way of specifying
>: the translate component.  You could easily take that out, invert, and put 
>: it back.
>
>  But aren't the rays also translated with the inverse translation of the
>object? Isn't the whole 4x4 matrix inverted?

Yes, but it's easiest to invert the 3x3 matrix and then tack on the inverse
translation than to try to invert the whole thing.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Warp
Subject: Re: Matrix question
Date: 24 Dec 2000 13:22:46
Message: <3a463ef5@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
: Yes, but it's easiest to invert the 3x3 matrix and then tack on the inverse
: translation than to try to invert the whole thing.

  But would inverting the whole 4x4 matrix work as well?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Matrix question
Date: 24 Dec 2000 19:38:37
Message: <slrn94d5ks.60e.ron.parker@fwi.com>
On 24 Dec 2000 13:22:46 -0500, Warp wrote:
>Ron Parker <ron### [at] povrayorg> wrote:
>: Yes, but it's easiest to invert the 3x3 matrix and then tack on the inverse
>: translation than to try to invert the whole thing.
>
>  But would inverting the whole 4x4 matrix work as well?

Of course.  

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Warp
Subject: Re: Matrix question
Date: 25 Dec 2000 11:11:23
Message: <3a4771ab@news.povray.org>
Ron Parker <ron### [at] povrayorg> wrote:
:>  But would inverting the whole 4x4 matrix work as well?

: Of course.  

  It may be crystal-clear to you, but it isn't to me.

  The decision to put the translation as the fourth column of the matrix
can sound quite arbitrary ("Hey, we need some place to put the translation
along with the other transformations. Where should we put it? Perhaps the
most handy way is just to expand the transformation matrix to 4x4 and put
the translation in the extra places").

  However, if the inversion of this matrix works as expected (that is, the
translation is also inverted as it should), then putting the translation
where it is now has a strong mathematical basis. Which is good, of course :)

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Ron Parker
Subject: Re: Matrix question
Date: 25 Dec 2000 11:49:19
Message: <slrn94euki.6kk.ron.parker@fwi.com>
On 25 Dec 2000 11:11:23 -0500, Warp wrote:
>  However, if the inversion of this matrix works as expected (that is, the
>translation is also inverted as it should), then putting the translation
>where it is now has a strong mathematical basis. Which is good, of course :)

It does.  Essentially, as long as you put a '1' in the last row of the 4-d
vector, the translation gets added in to the transformation as you'd expect
it to.  The last row should always be 0,0,0,1.  Any other sort of 4-d matrix
doesn't have the same effect.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Ben Birdsey
Subject: Re: Matrix question
Date: 31 Dec 2000 15:26:36
Message: <3A4F971F.8C76F672@mail.com>
Here's a slightly different method which might be a little faster,
since it uses intrinsically defined functions and pre-calculates more of
the values.

Taking my cue from Rune, define

/////////////////////////////////

#declare bX = <1,-0.05,0>;
#declare bY = <-0.5,0.5,0>;
#declare bZ = <0,0,1>;
#declare bC = <0,0,0>;

// The 16 statements to fill out the 16 elements of the inverse
// New system devised by Ben Birdsey (12/31/00)

#declare xp  = vcross(bY,bZ);
#declare yp  = vcross(bZ,bX);
#declare zp  = vcross(bX,bY);
#declare det = vdot(bX,xp);

#declare c11 = xp.x / det;
#declare c12 = yp.x / det;
#declare c13 = zp.x / det;
#declare c14 = 0;

#declare c21 = xp.y / det;
#declare c22 = yp.y / det;
#declare c23 = zp.y / det;
#declare c24 = 0;

#declare c31 = xp.z / det;
#declare c32 = yp.z / det;
#declare c33 = zp.z / det;
#declare c34 = 0;

#declare c41 = -vdot(xp,bC)/det;
#declare c42 = -vdot(yp,bC)/det;
#declare c43 = -vdot(zp,bC)/det;
#declare c44 = 1;

/////////////////////////////////

I checked the math on Mathematica, so it *should* be right.

You could look at this as some kind of matrix transform and lit it go
there, but maybe we can get some more understanding.

1) The new vectors xp,yp, and zp are the closest thing that the original
transformation could give you for an ordinary coordinate system.  (
because <1,0,0> is equal to vcross(<0,1,0>,<0,0,1>) ...)

2) det, which equals vdot(bX,vcross(bY,bZ)) is equal to the volume
inside the box with corners at 0, bX, bY, bZ, bX+bY, bX+bZ, bY+bZ and
bX+bY+bZ

3) the expressions for the c4x are similar to the amount of bC along
xp,yp,and zp

I hope this helps.

Ben
<><


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Matrix question
Date: 2 Jan 2001 21:13:30
Message: <3A528A9A.5EF512B@online.no>
Ben Birdsey wrote:
> 
>         Here's a slightly different method which might be a little faster,
> since it uses intrinsically defined functions and pre-calculates more of
> the values.
> 
> Taking my cue from Rune, define
> 
> /////////////////////////////////
> 
> #declare bX = <1,-0.05,0>;
> #declare bY = <-0.5,0.5,0>;
> #declare bZ = <0,0,1>;
> #declare bC = <0,0,0>;
> 
> // The 16 statements to fill out the 16 elements of the inverse
> // New system devised by Ben Birdsey (12/31/00)
> 
> #declare xp  = vcross(bY,bZ);
> #declare yp  = vcross(bZ,bX);
> #declare zp  = vcross(bX,bY);
> #declare det = vdot(bX,xp);
> 
> #declare c11 = xp.x / det;
> #declare c12 = yp.x / det;
> #declare c13 = zp.x / det;
> #declare c14 = 0;
> 
> #declare c21 = xp.y / det;
> #declare c22 = yp.y / det;
> #declare c23 = zp.y / det;
> #declare c24 = 0;
> 
> #declare c31 = xp.z / det;
> #declare c32 = yp.z / det;
> #declare c33 = zp.z / det;
> #declare c34 = 0;
> 
> #declare c41 = -vdot(xp,bC)/det;
> #declare c42 = -vdot(yp,bC)/det;
> #declare c43 = -vdot(zp,bC)/det;
> #declare c44 = 1;

I haven't checked or tried your code, so I don't know if 
it does what it's supposed to do.


But if you are going for optimizations, then I THINK that 
doing it this way this will increase the parsing speed:

#declare bX = < 1.00, -0.05,  0.00>;
#declare bY = <-0.50,  0.50,  0.00>;
#declare bZ = < 0.00,  0.00,  1.00>;
#declare bC = < 0.00,  0.00,  0.00>;

#declare det = vdot(bX, vcross(bY, bZ));
#declare xp  = vcross(bY, bZ)/det;
#declare yp  = vcross(bZ, bX)/det;
#declare zp  = vcross(bX, bY)/det;

#declare c11 = xp.x;
#declare c12 = yp.x;
#declare c13 = zp.x;
#declare c14 = 0;

#declare c21 = xp.y;
#declare c22 = yp.y;
#declare c23 = zp.y;
#declare c24 = 0;

#declare c31 = xp.z;
#declare c32 = yp.z;
#declare c33 = zp.z;
#declare c34 = 0;

#declare c41 = -vdot(xp, bC);
#declare c42 = -vdot(yp, bC);
#declare c43 = -vdot(zp, bC);
#declare c44 = 1;


(Note that I haven't checked my modifications either.)


Regards,

Tor Olav
-- 
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

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