POV-Ray : Newsgroups : povray.general : Regular Polygons & Prisms : Re: Regular Polygons & Prisms Server Time
11 Aug 2024 07:13:47 EDT (-0400)
  Re: Regular Polygons & Prisms  
From: Andrea Ryan
Date: 9 Oct 1999 21:47:27
Message: <37FFEF26.9DC7DE39@global2000.net>
Thanks. I used your suggestions and they shaved some time off a render of a 1000
sided prism.
Brendan Ryan

Chris Colefax wrote:

> Remco de Korte <rem### [at] xs4allnl> wrote:.
> > I don't know exactly what caused your problem but the code above has some
> typos.
> >
> > Here is what I made of it:
> >
> > #declare sides=5;
> >
> > prism {
> >   linear_sweep
> >   linear_spline
> >   -0.5,
> >    0.5,
> >   sides+1,
> >
> > #local rotation_no = 0;
> > #while (rotation_no<sides)
> > #local angle_of_rotation = 360/sides;
> > // #local temp_vec=vrotate(<0,1,0>,<0,1,angle_of_rotation*rotation_no>);
> > #local temp_vec=vrotate(<0,1,0>,<0,0,angle_of_rotation*rotation_no>);
> > // #local vec=<temp_vec.y,temp_vec.z>;
> > #local vec=<temp_vec.x,temp_vec.y>;
> > #if (rotation_no=0)
> >   #declare vec0=vec;
> > #end
> > vec,
> > #local rotation_no = rotation_no+1;
> > #end
> > vec0
> > pigment{rgb 1}
> > rotate x*90
> > }
> >
> > When I tried this it worked fine.
>
> In the first line you've commented out above, the rotation of +y by 1 degree
> about the y axis actually has no effect (although your second version is
> more correct).  The real change is in the code in which you extract the 2D
> vector from the rotated 3D vector: in the commented-out line, the temp_vec.z
> component will always be 0 which obviously won't give the desired result!
>
> At any rate, as I posted in my other reply it is not necessary to convert
> the 3D to 2D vectors as you have done, as long as the vectors lie correctly
> in the X-Z plane.  Also, for better coding you should remove the calculation
> of the rotation angle outside the while loop; otherwise, you're simply
> recalculating the same value over and over again!  Finally, for the closing
> of the prism/polygon, all you really need is the unrotated radius vector at
> the beginning and end.  Using this you can avoid any rounding errors and
> unnecessary calculations, eg:
>
> #macro regular_prism (Sides, Height1, Height2)
>   #local RotAngle = 360/Sides;
>   prism {linear_sweep linear_spline
>     Height1, Height2, Sides+1, x,
>     #local Count = 1; #while (Count < Sides)
>       vrotate (x, y*RotAngle*Count),
>     #local Count = Count + 1; #end
>     x}
> #end
>
> From here you could adjust the basic code to create star-shaped prisms, or
> use curved splines to create petal shapes, etc.


Post a reply to this message

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