POV-Ray : Newsgroups : povray.general : Regular Polygons & Prisms Server Time
11 Aug 2024 07:08:32 EDT (-0400)
  Regular Polygons & Prisms (Message 21 to 26 of 26)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 8 Oct 1999 19:00:27
Message: <37FE7698.EA91502D@global2000.net>
After a little testing, I found that the macro worked fine for prisms with
a odd number of sides, but it doesn't work prisms that have an even number
of sides.
I think the problem is in this code:

#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 vec=<temp_vec.y,temp_vec.z>;
#local rotation_no = rotation_no+1;
//the stuff that writes to the data file
#end

When a prism with a even number of sides is created, one of the points has
a coordinate with an incorrect sign. Thanks for your help.
Brendan Ryan

Andrea Ryan wrote:

> I am trying to create a macro for making regular polygons and prisms. I
> can't get one point to rotate to the vertexes.
> Brendan Ryan


Post a reply to this message

From: Remco de Korte
Subject: Re: Regular Polygons & Prisms
Date: 8 Oct 1999 20:23:18
Message: <37FE8B28.8415B51B@xs4all.nl>
Andrea Ryan wrote:
> 
> After a little testing, I found that the macro worked fine for prisms with
> a odd number of sides, but it doesn't work prisms that have an even number
> of sides.
> I think the problem is in this code:
> 
> #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 vec=<temp_vec.y,temp_vec.z>;
> #local rotation_no = rotation_no+1;
> //the stuff that writes to the data file
> #end
> 
> When a prism with a even number of sides is created, one of the points has
> a coordinate with an incorrect sign. Thanks for your help.
> Brendan Ryan
> 
> Andrea Ryan 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.

Remco


Post a reply to this message

From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 8 Oct 1999 22:21:43
Message: <37FEA5C0.9A6CDFB7@global2000.net>
Thanks! It works for any prisms. I rendered a 1000-gon in 2 minutes and 22 seconds.
It looked like a cylinder. :-)
Brendan Ryan

Remco de Korte wrote:

> Andrea Ryan wrote:
> >
> > After a little testing, I found that the macro worked fine for prisms with
> > a odd number of sides, but it doesn't work prisms that have an even number
> > of sides.
> > I think the problem is in this code:
> >
> > #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 vec=<temp_vec.y,temp_vec.z>;
> > #local rotation_no = rotation_no+1;
> > //the stuff that writes to the data file
> > #end
> >
> > When a prism with a even number of sides is created, one of the points has
> > a coordinate with an incorrect sign. Thanks for your help.
> > Brendan Ryan
> >
> > Andrea Ryan 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.
>
> Remco


Post a reply to this message

From: Remco de Korte
Subject: Re: Regular Polygons & Prisms
Date: 9 Oct 1999 12:05:22
Message: <37FF67F3.84418C5C@xs4all.nl>
Andrea Ryan wrote:
> 
> Thanks! It works for any prisms. I rendered a 1000-gon in 2 minutes and 22 seconds.
> It looked like a cylinder. :-)
> Brendan Ryan
> 

Next step: take a polygon with a an even number of sides and scale each odd (or
even) side up or down. I.e. translate the point towards the center or further
away from it.
What happens?
You can do similar things with other regular (or irregular) repeating
transformations.

Ciao!

Remco


Post a reply to this message

From: Chris Colefax
Subject: Re: Regular Polygons & Prisms
Date: 9 Oct 1999 21:03:39
Message: <37ffe5eb@news.povray.org>
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

From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
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

<<< Previous 10 Messages Goto Initial 10 Messages

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