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