|
![](/i/fill.gif) |
Michael Andrews <m.c### [at] reading ac uk> wrote in
news:3e54d2d5$1@news.povray.org:
...
>I surprised myself with how easy the
> orientation macro was to write:
>
> #macro Three_Point_Trans(T1a, T1b, T1c, T2a, T2b, T2c)
> transform {
> #local Y = vnormalize(T1b - T1a);
> #local X = vnormalize(T1c - T1a);
> #local Z = vnormalize(vcross(X, Y));
> #local X = vcross(Z, Y);
> #local T = Shear_Trans(X, Y, Z)
> translate -T1a
> transform { T inverse }
> #local Y = vnormalize(T2b - T2a);
> #local X = vnormalize(T2c - T2a);
> #local Z = vnormalize(vcross(X, Y));
> #local X = vcross(Z, Y);
> Shear_Trans(X, Y, Z)
> translate T2a
> }
> #end
>
> The three points a,b,c define a triangle; a is the origin, b-a is
> the primary orientation and abc gives a secondary orientation plane.
> The two orientation axes b-a and c-a do not have to be orthogonal,
> just independant so vcross(b-a,c-a) doesn't return a zero length
> vector.
>
> So Three_Point_Trans(0,y,x, P0,P1,P2) gives a transform from the
> origin to P0, aligns y with P1-P0 and puts the (x,y) plane in the
> plane of the (P0,P1,P2) triangle.
...
Here is a slightly modified version of that macro:
#macro ThreePoint_Trans(pA1, pB1, pC1, pA2, pB2, pC2)
#local vY1 = vnormalize(pB1 - pA1);
#local vZ1 = vnormalize(vcross(pC1 - pA1, vY1));
#local vX1 = vcross(vZ1, vY1);
#local T1 = transform { Matrix_Trans(vX1, vY1, vZ1, pA1) inverse }
#local vY2 = vnormalize(pB2 - pA2);
#local vZ2 = vnormalize(vcross(pC2 - pA2, vY2));
#local vX2 = vcross(vZ2, vY2);
#local T2 = transform { Matrix_Trans(vX2, vY2, vZ2, pA2) }
transform { T1 T2 }
#end // macro ThreePoint_Trans
Tor Olav
Post a reply to this message
|
![](/i/fill.gif) |