|
|
/*
Please help an old man whose brain is off-line ;-)
Wanted: a prism from 5 points on a plane.
Why doesn't this always work?
TIA
Alf
*/
camera{ location <-1, 2,-4> look_at <0,0,0> }
light_source{ <-100,100,-100> 1 }
#declare OK = 1; // 0/1 = Not OK/OK.
#if (OK = 1)
#declare P1 = < 1.170639, 1.170639, 1.170639>;
#declare P2 = < 1.894104, 0.000000, 0.723495>;
#declare P3 = < 1.894104, 0.000000,-0.723495>;
#declare P4 = < 1.170639, 1.170639,-1.170639>;
#declare P5 = < 0.723495, 1.894104, 0.000000>;
#else
#declare P1 = <-1.170639, 1.170639, 1.170639>;
#declare P2 = <-1.894104, 0.000000, 0.723495>;
#declare P3 = <-1.170639,-1.170639, 1.170639>;
#declare P4 = < 0.000000,-0.723495, 1.894104>;
#declare P5 = < 0.000000, 0.723495, 1.894104>;
#end
#declare Avg = (P1+P2+P3+P4+P5)/5; // Face center
#declare FaceN = vcross(P1-P2, P1-P3); // Face normal
// I think the error is here?
#declare Up = <-degrees( atan2( FaceN.z, FaceN.y) ),
0,
degrees( asin( FaceN.x/vlength(FaceN) ) )>;
union{ // Show original points.
sphere{ P1, 0.1 }
sphere{ P2, 0.1 }
sphere{ P3, 0.1 }
sphere{ P4, 0.1 }
sphere{ P5, 0.1 }
pigment{ rgb <1,0,1> }
}
// Rotate 5 points to be above and parallel to y-plane.
#declare Pa = vrotate(P1, Up);
#declare Pb = vrotate(P2, Up);
#declare Pc = vrotate(P3, Up);
#declare Pd = vrotate(P4, Up);
#declare Pe = vrotate(P5, Up);
// Show points on y-plane.
union{
sphere{ <Pa.x, 0, Pa.z>, 0.1 }
sphere{ <Pb.x, 0, Pb.z>, 0.1 }
sphere{ <Pc.x, 0, Pc.z>, 0.1 }
sphere{ <Pd.x, 0, Pd.z>, 0.1 }
sphere{ <Pe.x, 0, Pe.z>, 0.1 }
pigment{ rgb <0,1,1> }
}
// Now transform a prism to match original points.
prism{ -0.05, 0.05, 5+1,
<Pa.x, Pa.z>,
<Pb.x, Pb.z>,
<Pc.x, Pc.z>,
<Pd.x, Pd.z>,
<Pe.x, Pe.z>,
<Pa.x, Pa.z>
pigment{ rgb <1,1,0> }
translate y*vlength(Avg) // y*(distance from <0,0,0>)
rotate -Up
}
Post a reply to this message
|
|