POV-Ray : Newsgroups : povray.general : Regular Polygons & Prisms Server Time
11 Aug 2024 05:11:04 EDT (-0400)
  Regular Polygons & Prisms (Message 11 to 20 of 26)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>
From: Chris Colefax
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 10:50:05
Message: <37fcb31d@news.povray.org>
Brendan Ryan <ary### [at] global2000net> 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.
...
> I need 2d vectors for polygons but vrotate changes them into 3d vectors.

POV-Ray shouldn't have a problem with 3D vectors in the prism definition (or
lathes, or sor's), as long as they lie in the correct plane (ie. XZ for the
prism, XY for the other two).  Here's an answer I posted back in July '97
when this question was asked on comp.graphics.rendering.raytracing:

  #declare NumberofSides = 5;
  #declare BasePrism = prism {0, 1, NumberofSides + 1
    #declare Rot = 0; #while (Rot < 360)
      vrotate (x, z * Rot),
    #declare Rot = Rot + 360 / NumberofSides; #end
      x}

By changing the NumberofSides, you can create any sided figure,
automatically centred around the origin.  You can then use this object
to create other objects, eg:

  difference {
    object {BasePrism scale <2, 4, 2>}
    object {BasePrism scale <1.5, 2, 1.5> translate <0, 3, 0>}
    pigment {rgb 1}}

In the above example we have scaled the first prism by 2 in width, and
the second by 1.5; you can change the thickness of the sides by
adjusting the numbers, eg: 2 and 1.9 for thinner sides, 2 and 1.1 for
thicker sides.


Post a reply to this message

From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 16:18:29
Message: <37FCFF25.F69CC0B5@global2000.net>
Yay! It worked! I rendered a regular pentagon! But... there's still a little problem.
I used the following code:

#if (-0.000000000000000244921<=vec.u<=0.000000000000000244921)
#declare vec=<0,1>;
#end

and the first three vectors were <0,1> when there should be only one at the beginning.

The second and third vectors had negative numbers in them.


The last vector didn't match the first one. I want them to be alike so there would be
no warnings. I might use the quadratic and cubic splines after adding the control
points. If a prism using quadratic or cubic splines is not closed, POV-Ray will
generate a error message.

Brendan Ryan

Remco de Korte wrote:

> Andrea Ryan wrote:
> >
> > I used your code but it still made 3d vectors. The last point should be the same
> > as the first one. This is the code that creates the vectors.
> >
> > #fopen data "data.inc" append
> > #local rotation_no = 0;
> > #while (rotation_no<=sides)
> > #local angle_of_rotation = 360/sides;
> > #local temp_vec=vrtotate(<0,1,0>,<0,0,angle_of_rotation*rotation_no>);
> > #local vec=<temp_vec.x,temp_vec.y>;
> > #local rotation_no = rotation_no+1;
> > #write (data, "",vec,"")
> > #end
>
> I'm not sure I understand where it went wrong.
> The temp_vec is a 3D-vector from which you derive vec as a 2D-vector.
> I tried this and I got a file with 2D-vectors (after fixing a small typo).
> I agree the last point should be the same as the first and indeed in my file the
> first was: <0,1> while the last was <2.44921e-016,1>. I don't know if this
> really bothers you, but 2.44921e-016 is might close to 0. If you'd really like
> to avoid it you could put in something like:
> #if (vec.u<.0000001)
>   #declare vec=0;
> #end
> Not very elegant, but efficient enough. It won't really matter for the resulting
> scene.
>
> Bye,
>
> Remco


Post a reply to this message

From: Ken
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 16:36:58
Message: <37FD0458.128DFEF9@pacbell.net>
Andrea Ryan wrote:
> 
> Yay! It worked! I rendered a regular pentagon! But... there's still a little
problem.
> I used the following code:
> 
> #if (-0.000000000000000244921<=vec.u<=0.000000000000000244921)
> #declare vec=<0,1>;
> #end

You can't use numbers that long in pov. Drop about 10 zeros and it
should work ok.

-- 
Ken Tyler
1100+ Povray, Graphics, 3D Rendering, and Raytracing Links:
http://home.pacbell.net/tylereng/index.html


Post a reply to this message

From: Remco de Korte
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 18:23:50
Message: <37FD1DAB.E7F7CC86@xs4all.nl>
Andrea Ryan wrote:
> 
> Yay! It worked! I rendered a regular pentagon! But... there's still a little
problem.
> I used the following code:
> 
> #if (-0.000000000000000244921<=vec.u<=0.000000000000000244921)
> #declare vec=<0,1>;
> #end
> 
> and the first three vectors were <0,1> when there should be only one at the
beginning.
> 
> The second and third vectors had negative numbers in them.
> 
> The last vector didn't match the first one. I want them to be alike so there would
be
> no warnings. I might use the quadratic and cubic splines after adding the control
> points. If a prism using quadratic or cubic splines is not closed, POV-Ray will
> generate a error message.
> 
> Brendan Ryan
> 

Closing is easier if you just copy the first point to the last. There is no way
that can go wrong (the stuff in between however....)

Cheers!

Remco


Post a reply to this message

From: Andrea Ryan
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 20:35:28
Message: <37FD3B62.1178E21F@global2000.net>
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

Remco de Korte wrote:

> Andrea Ryan wrote:
> >
> > Yay! It worked! I rendered a regular pentagon! But... there's still a little
problem.
> > I used the following code:
> >
> > #if (-0.000000000000000244921<=vec.u<=0.000000000000000244921)
> > #declare vec=<0,1>;
> > #end
> >
> > and the first three vectors were <0,1> when there should be only one at the
beginning.
> >
> > The second and third vectors had negative numbers in them.
> >
> > The last vector didn't match the first one. I want them to be alike so there would
be
> > no warnings. I might use the quadratic and cubic splines after adding the control
> > points. If a prism using quadratic or cubic splines is not closed, POV-Ray will
> > generate a error message.
> >
> > Brendan Ryan
> >
>
> Closing is easier if you just copy the first point to the last. There is no way
> that can go wrong (the stuff in between however....)
>
> Cheers!
>
> Remco


Post a reply to this message

From: Remco de Korte
Subject: Re: Regular Polygons & Prisms
Date: 7 Oct 1999 22:08:10
Message: <37FD523E.F6734AD2@xs4all.nl>
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: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

<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>

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