|
|
Nieminen Mika wrote:
>
> Peter Popov <pet### [at] usanet> wrote:
> : Can anyone tell me the matrix to transform a given triangle into
> : another given triangle? I need this for some UV mapping stuff in POV
> : (not UVPOV :) ). TIA.
>
> If http://users.erols.com/vansickl/matrix.htm doesn't help, you
> could ask the author of that page himself. I'm sure he knows the
> answer.
"Look! It's a vector!"
"It's a tensor!"
"No! It's MATRIX MAN!
The exact formula isn't on the page, because I hadn't gotten around to
figuring it out. After reading your message I sat down and wrote a
macro that will transform a triangle from one place to another. I've
tested the code and it seems to work.
To use it, you define a triangle at a given set of points, and use the
macro to move it:
triangle { A,B,C
texture { MyTexture }
TransformTriangle(A,B,C,D,E,F)
}
If you want to declare the triangle at its final destination, and
only transform the texture, this will work as well:
triangle { D,E,F
texture { MyTexture
TransformTriangle(A,B,C,D,E,F)
}
}
If you have a triangle somewhere in space and you want to slap
an image_map onto it, so that one corner of the image map is in each of
the corners of the triangle, this might be what you want:
triangle { A,B,C
texture {
pigment { image_map { gif "mygif.gif" }
TransformTriangle(0,x,y,A,B,C)
}
}
}
Here's the macro code. Put it into your favorite macro file:
// START OF MACRO CODE
// this macro creates the matrix that will transform triangle
// (A,B,C) into triangle (D,E,F). Basically it's a matrix inversion,
// followed by the application of another matrix.
#macro TransformTriangle(pA,pB,pC,pD,pE,pF)
#local vXa=(pB-(pA));
#local vYa=(pC-(pA));
#local vZa=vcross(vXa,vYa);
// #local vLa=pA;
#local vXb=(pE-(pD));
#local vYb=(pF-(pD));
#local vZb=vcross(vXb,vYb);
#local sDET=vdot(vZa,vcross(vXa,vYa));
// these next three lines calculate the values for the inverted
// matrix:
#local vCX=vcross(vYa,vZa)/sDET;
#local vCY=vcross(vZa,vXa)/sDET;
#local vCZ=vcross(vXa,vYa)/sDET;
// these two steps take the triangle at (A,B,C) and move it to
// (<0,0,0>,x,y)
translate -(pA)
matrix < vCX.x,vCY.x,vCZ.x,
vCX.y,vCY.y,vCZ.y,
vCX.z,vCY.z,vCZ.z,
0, 0, 0 >
// this matrix takes the triangle at (<0,0,0>,x,y) and moves it
// to (D,E,F)
matrix < vXb.x,vXb.y,vXb.z,
vYb.x,vYb.y,vYb.z,
vZb.x,vZb.y,vZb.z,
pD.x, pD.y, pD.z >
#end
// END OF MACRO CODE
I think it's time to update the Throughly Useful Macros file...
Hope this helps,
John
Post a reply to this message
|
|