POV-Ray : Newsgroups : povray.general : Transform help please : Re: Transform help please Server Time
4 Aug 2024 00:28:30 EDT (-0400)
  Re: Transform help please  
From: JC (Exether)
Date: 29 Aug 2003 03:01:36
Message: <3f4efa50@news.povray.org>
I'm not quite sure what you want to do, but I have a few remarks that 
could give you some hints:
- Are you sure the face's points are coplanar ? (I guess you are, but 
it's still worth asking)
- It is generaly better in POV scripts if you can use vectorial (cross 
products, projections, transforms.inc macros and stuff like that) 
formulaes instead of trigonometric, because it's clearer and it's not as 
error prone. Basically I don't what the Up vector should be, so it's 
difficult to point out a potential error.

Good luck, I know these kind of bugs are really annoying,

JC

Alf Peake wrote:
> /*
> 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

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