POV-Ray : Newsgroups : povray.general : Regular Polygons & Prisms Server Time
11 Aug 2024 05:15:22 EDT (-0400)
  Regular Polygons & Prisms (Message 17 to 26 of 26)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 23:04:31
Message: <37FD5E50.1D2D4C61@global2000.net>
Finally! The finial comma vanished! I just declared comma_no before most of the other
stuff
and moved the line that subtracted one form comma_no to the outside of a #if
statement. I
think that the later is what fixed it.
Brendan Ryan          Thank you Remco! :-)

Remco de Korte wrote:

> Andrea Ryan wrote:
> >
> > Now, the macro is nearly perfect. It can create whole prism statements but the
part that
> > omits the comma after the last vector doesn't work. Here's the code:  (which is
inside a
> > while loop)
> > Brendan Ryan
> >
> > #write (data, "","\n")
> > #write (data, "",vec,"")
> > #ifndef (comma_no)
> > #local comma_no = sides;
> > #end
> > #if (comma_no>0)
> > #write (data, "",",")
> > #else
> > #local comma_no = comma_no-1
> > #end
> >
>
> I'm not sure how the rest looks but this seems a bit complicated.
>
> How about this:
>
> #write (data,"",vec,"")
> #if (counter<sides)
>   #write (data, "",",")
> #end
>
> or something in that fashion.
>
> Another solution, which also relates to your problem with closing the prism
> could be:
> #while (counter<sides)
>   // create a new vec for this value
>   #write (data,"",vec,"")
>   #write (data, "",",")
> #end
> #declare vec=first_vec;
> #write (data,"",vec,"")
>
> I hope this makes sense.
> Don't look too much at the write-stuff, I just copied it from your example.
>
> Good luck again :)
>
> Remco


Post a reply to this message

From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 23:11:46
Message: <37FD6004.A3A5944A@global2000.net>
I posted a image of a septagon prism in povray.binaries.images.

Andrea Ryan wrote:

> Finally! The finial comma vanished! I just declared comma_no before most of the
other stuff
> and moved the line that subtracted one form comma_no to the outside of a #if
statement. I
> think that the later is what fixed it.
> Brendan Ryan          Thank you Remco! :-)
>
> Remco de Korte wrote:
>
> > Andrea Ryan wrote:
> > >
> > > Now, the macro is nearly perfect. It can create whole prism statements but the
part that
> > > omits the comma after the last vector doesn't work. Here's the code:  (which is
inside a
> > > while loop)
> > > Brendan Ryan
> > >
> > > #write (data, "","\n")
> > > #write (data, "",vec,"")
> > > #ifndef (comma_no)
> > > #local comma_no = sides;
> > > #end
> > > #if (comma_no>0)
> > > #write (data, "",",")
> > > #else
> > > #local comma_no = comma_no-1
> > > #end
> > >
> >
> > I'm not sure how the rest looks but this seems a bit complicated.
> >
> > How about this:
> >
> > #write (data,"",vec,"")
> > #if (counter<sides)
> >   #write (data, "",",")
> > #end
> >
> > or something in that fashion.
> >
> > Another solution, which also relates to your problem with closing the prism
> > could be:
> > #while (counter<sides)
> >   // create a new vec for this value
> >   #write (data,"",vec,"")
> >   #write (data, "",",")
> > #end
> > #declare vec=first_vec;
> > #write (data,"",vec,"")
> >
> > I hope this makes sense.
> > Don't look too much at the write-stuff, I just copied it from your example.
> >
> > Good luck again :)
> >
> > Remco


Post a reply to this message

From: Nieminen Juha
Subject: Re: Regular Polygons & Prisms
Date: 8 Oct 1999 04:33:36
Message: <37fdac60@news.povray.org>
Andrea Ryan <ary### [at] global2000net> wrote:
: #if (-0.000000000000000244921<=vec.u<=0.000000000000000244921)

  This comparison doesn't work as expected. It will be true when the value
of 'vec.u' is less than the first value.

  Why?
  Let's take a simpler example:

#if(-0.5 <= var <= 0.5)
  #debug "Hello\n"
#end

  This will print "Hello" only when 'var' is less than '-0.5'.
  What happens?
  First povray will evaluate the first operator, ie. "-0.5 <= var". If
'var' is greater or equal to -0.5, it will return true, which is the same
as 1, else false, which is the same as 0.
  Let's suppose that 'var' has the value 0. The comparison "-0.5 <= 0" will
return true, ie 1. Now povray will make the comparison "1 <= 0.5" which
returns false. The string is not printed.
  Let's suppose that 'var' has the value -1. The comparison "-0.5 <= -1" will
return false, ie 0. The comparison "0 <= 0.5" will return true. The string
is printed.

  Thus, the string will be printed only when the value of 'var' is less
than -0.5.

  The correct way to do the comparison is:

#if(-0.5 <= var & var <= 0.5)

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 8 Oct 1999 15:58:53
Message: <37FE4C07.9CBC088@global2000.net>
It uses a #switch with #range now.
Brendan Ryan

Nieminen Juha wrote:

> Andrea Ryan <ary### [at] global2000net> wrote:
> : #if (-0.000000000000000244921<=vec.u<=0.000000000000000244921)
>
>   This comparison doesn't work as expected. It will be true when the value
> of 'vec.u' is less than the first value.
>
>   Why?
>   Let's take a simpler example:
>
> #if(-0.5 <= var <= 0.5)
>   #debug "Hello\n"
> #end
>
>   This will print "Hello" only when 'var' is less than '-0.5'.
>   What happens?
>   First povray will evaluate the first operator, ie. "-0.5 <= var". If
> 'var' is greater or equal to -0.5, it will return true, which is the same
> as 1, else false, which is the same as 0.
>   Let's suppose that 'var' has the value 0. The comparison "-0.5 <= 0" will
> return true, ie 1. Now povray will make the comparison "1 <= 0.5" which
> returns false. The string is not printed.
>   Let's suppose that 'var' has the value -1. The comparison "-0.5 <= -1" will
> return false, ie 0. The comparison "0 <= 0.5" will return true. The string
> is printed.
>
>   Thus, the string will be printed only when the value of 'var' is less
> than -0.5.
>
>   The correct way to do the comparison is:
>
> #if(-0.5 <= var & var <= 0.5)
>
> --
> main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
> ):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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.