POV-Ray : Newsgroups : povray.advanced-users : Describing a perfect circle with a spline. Server Time
5 Jul 2024 16:30:49 EDT (-0400)
  Describing a perfect circle with a spline. (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: gregjohn
Subject: Describing a perfect circle with a spline.
Date: 24 Sep 2007 14:00:00
Message: <web.46f7fa0313a1f79e40d56c170@news.povray.org>
For any number of points n, (n>3 if that makes it any easier), what is the
simplest spline that defines a circle (value of spline at 0= start of
circle, 1= back to same point).

I have this fear that what I think may be a simple solution would instead be
a rounded square for n=4.


Post a reply to this message

From: andrel
Subject: Re: Describing a perfect circle with a spline.
Date: 24 Sep 2007 17:20:20
Message: <46F82B31.10308@hotmail.com>
gregjohn wrote:
> For any number of points n, (n>3 if that makes it any easier), what is the
> simplest spline that defines a circle (value of spline at 0= start of
> circle, 1= back to same point).
> 
> I have this fear that what I think may be a simple solution would instead be
> a rounded square for n=4.
> 
> 

The simple answer is that you can not make a perfect circle with 
splines, because sin() and cos() have an infinite Taylor expansion.

The more elaborate answer is that you can get a reasonable approximation 
with 4 cubic splines. With more splines the approximation can be even 
better. With two it is not even close.
You want to know how to define it in one spline, that I don't know. ;)
The 'problem' with standard splines is that not all points are treated 
the same. Often the first and last point are on the spline whereas the 
others are control points, indicating where 'approximately' you want the 
spline to go. I wouldn't be surprised if there is a set of base 
functions that are totally symmetrical and can be used for circular 
splines, but POV does not support them (AFAIK).
If this question is beyond POV, I might look into the literature for you 
and/or try to find a reasonable solution by minimizing some distance 
function, but I would advise you to build a circle with a set of simple 
splines (or use a very low cylinder).


Post a reply to this message

From: Charles C
Subject: Re: Describing a perfect circle with a spline.
Date: 24 Sep 2007 19:50:00
Message: <web.46f84c02bd0f5648c667cf480@news.povray.org>
andrel <a_l### [at] hotmailcom> wrote:
> gregjohn wrote:
> > For any number of points n, (n>3 if that makes it any easier), what is the
> > simplest spline that defines a circle (value of spline at 0= start of
> > circle, 1= back to same point).
> >
> > I have this fear that what I think may be a simple solution would instead be
> > a rounded square for n=4.
> >
> >
>
> The simple answer is that you can not make a perfect circle with
> splines, because sin() and cos() have an infinite Taylor expansion.
>
> The more elaborate answer is that you can get a reasonable approximation
> with 4 cubic splines. With more splines the approximation can be even
> better. With two it is not even close.
> You want to know how to define it in one spline, that I don't know. ;)
> The 'problem' with standard splines is that not all points are treated
> the same. Often the first and last point are on the spline whereas the
> others are control points, indicating where 'approximately' you want the
> spline to go. I wouldn't be surprised if there is a set of base
> functions that are totally symmetrical and can be used for circular
> splines, but POV does not support them (AFAIK).
> If this question is beyond POV, I might look into the literature for you
> and/or try to find a reasonable solution by minimizing some distance
> function, but I would advise you to build a circle with a set of simple
> splines (or use a very low cylinder).


For any number of points? Does that mean you know how many sample points
will be taken?  Also what do you mean by 'simple?'  If you create a control
point for each and every expected sample point, then shouldn't it be as
'perfect' as can be?  I'd just create a while loop going (either directly
or in effect) from -1/n to n + (1/n) along with your
Scale*sin(Position*2*pi) and Scale*cos(Position*2*pi) functions to create a
cubic_spline.

Charles


Post a reply to this message

From: Tim Attwood
Subject: Re: Describing a perfect circle with a spline.
Date: 25 Sep 2007 04:29:54
Message: <46f8c702$1@news.povray.org>
> For any number of points n, (n>3 if that makes it any easier), what is the
> simplest spline that defines a circle (value of spline at 0= start of
> circle, 1= back to same point).
>
> I have this fear that what I think may be a simple solution would instead 
> be
> a rounded square for n=4.

About n=11, or 45 degrees apart, remember you need one before
and one after as control points usually.  You can set a macro up that
will evaluate a circle though, it's one line of code.

Demo scene....

#version 3.6;
global_settings {assumed_gamma 1.0} default{finish{ambient 1}}
camera {location  <0,0,-4>
   direction 1.5*z
   right     x*image_width/image_height
   look_at   <0,0,0>}
#declare rad = 1.25;
#declare circleS = spline {
   natural_spline
   -0.125,vrotate(<0,rad,0>,<0,0,-45>)
    0.0,  vrotate(<0,rad,0>,<0,0,  0>)
    0.125,vrotate(<0,rad,0>,<0,0, 45>)
    0.25, vrotate(<0,rad,0>,<0,0, 90>)
    0.375,vrotate(<0,rad,0>,<0,0,135>)
    0.5,  vrotate(<0,rad,0>,<0,0,180>)
    0.625,vrotate(<0,rad,0>,<0,0,225>)
    0.75, vrotate(<0,rad,0>,<0,0,270>)
    0.875,vrotate(<0,rad,0>,<0,0,315>)
    1.0,  vrotate(<0,rad,0>,<0,0,  0>)
    1.125,vrotate(<0,rad,0>,<0,0, 45>)
};
#macro circleM(a) vrotate(<0,rad,0>,<0,0,360*a>) #end
#local c = 0;
#while (c<=1)
   sphere {circleS(c),0.02 pigment{rgb <1,0,0>}translate<0,0,-0.03>}
   sphere {circleM(c),0.04 pigment{rgb <0,1,0>}}
   #local c=c+0.01;
#end
cylinder {<0,0,0>,<0,0,0.1>,rad pigment{rgb <0,0,1>}}


Post a reply to this message

From: Alain
Subject: Re: Describing a perfect circle with a spline.
Date: 25 Sep 2007 10:26:08
Message: <46f91a80@news.povray.org>
gregjohn nous apporta ses lumieres en ce 2007/09/24 13:55:
> For any number of points n, (n>3 if that makes it any easier), what is the
> simplest spline that defines a circle (value of spline at 0= start of
> circle, 1= back to same point).
> 
> I have this fear that what I think may be a simple solution would instead be
> a rounded square for n=4.
> 
> 
What do you want to do exactly, and how is it suposed to look?

If it's suposed to look as a dougnut, then you should use a torus: MUCH simpler.
torus{Major_Radius, Minor_Radius rotate Your_Rotation translate Your_Translation}

If it's suposed to like a thick disk, then you could go with a cylinder.
cylinder{Top_Face, Bottom_Face, Radius}

If it suposed to look like a disc, there is the disc primitive.
disc{Center, Normal, Radius [,Hole_Radius]}

If you want a thick disk with rounded edges, you can use an union of a cylinder 
and a torus.
union{cylinder{Top, Bottom, Radius}torus{Major_Radius, Minor_Radius}rotate 
Some_Rotation translate Some_Translation}

cylinder and disc can be deffined at any arbitrary location.
torus are initialy centered at the origin, on the x-z plane around the y axis.

All of those will give you a perfectly circular shape and can be scaled if needed.

-- 
Alain
-------------------------------------------------
For here we are not afraid to follow truth wherever it may lead.
Thomas Jefferson


Post a reply to this message

From: gregjohn
Subject: Re: Describing a perfect circle with a spline.
Date: 25 Sep 2007 13:05:01
Message: <web.46f93e99bd0f564840d56c170@news.povray.org>
Alain <ele### [at] netscapenet> wrote:
>
> What do you want to do exactly, and how is it supposed to look?
>

I wanted a spline My_Spline where My_Spline(n) spits out 3D points on a
circle for any n, if 0<n<1, and with any predefined
Number_of_Entries_in_Spline.

I knew a way to code this which seemed a PITA, and I feared it were neither
necessary nor sufficient.  The advice I got above seems to confirm that it
is necessary and sufficient.

thanks all.


Post a reply to this message

From: andrel
Subject: Re: Describing a perfect circle with a spline.
Date: 25 Sep 2007 16:06:30
Message: <46F96B46.8000401@hotmail.com>
Charles C wrote:
> andrel <a_l### [at] hotmailcom> wrote:
>> gregjohn wrote:
>>> For any number of points n, (n>3 if that makes it any easier), what is the
>>> simplest spline that defines a circle (value of spline at 0= start of
>>> circle, 1= back to same point).
>>>
>>> I have this fear that what I think may be a simple solution would instead be
>>> a rounded square for n=4.
>>>
>>>
>> The simple answer is that you can not make a perfect circle with
>> splines, because sin() and cos() have an infinite Taylor expansion.
>>
>> The more elaborate answer is that you can get a reasonable approximation
>> with 4 cubic splines. With more splines the approximation can be even
>> better. With two it is not even close.
>> You want to know how to define it in one spline, that I don't know. ;)
>> The 'problem' with standard splines is that not all points are treated
>> the same. Often the first and last point are on the spline whereas the
>> others are control points, indicating where 'approximately' you want the
>> spline to go. I wouldn't be surprised if there is a set of base
>> functions that are totally symmetrical and can be used for circular
>> splines, but POV does not support them (AFAIK).
>> If this question is beyond POV, I might look into the literature for you
>> and/or try to find a reasonable solution by minimizing some distance
>> function, but I would advise you to build a circle with a set of simple
>> splines (or use a very low cylinder).
> 
> 
> For any number of points? Does that mean you know how many sample points
> will be taken?  Also what do you mean by 'simple?' 
I guess that this remark is aimed at my first statement that it is 
essentially not possible. To (hopefully) clarify a bit more: splines are 
polynomials and sin() and cos() require a polynomial with infinite 
length to describe. So you can approximate a circle but never get is 
*exactly* right. That does not mean that for all practical purposes your 
solution below might give a sufficient approximation. You may even tweak 
the Scale a bit, because now all points on the curve are inside the 
circle. Increasing it a bit so that some of the curve is inside and 
another part is outside decreases the error even more.
> If you create a control
> point for each and every expected sample point, then shouldn't it be as
> 'perfect' as can be?  I'd just create a while loop going (either directly
> or in effect) from -1/n to n + (1/n) along with your
> Scale*sin(Position*2*pi) and Scale*cos(Position*2*pi) functions to create a
> cubic_spline.


Post a reply to this message

From: Charles C
Subject: Re: Describing a perfect circle with a spline.
Date: 25 Sep 2007 19:10:00
Message: <web.46f994f2bd0f5648c667cf480@news.povray.org>
andrel <a_l### [at] hotmailcom> wrote:
> I guess that this remark is aimed at my first statement that it is
> essentially not possible. To (hopefully) clarify a bit more: splines are
> polynomials and sin() and cos() require a polynomial with infinite
> length to describe. So you can approximate a circle but never get is
> *exactly* right. That does not mean that for all practical purposes your
> solution below might give a sufficient approximation. You may even tweak
> the Scale a bit, because now all points on the curve are inside the
> circle. Increasing it a bit so that some of the curve is inside and
> another part is outside decreases the error even more.

True. There's always the fact that we're using floats with a finite number
of bits.  I figure <2*pi*cos(Value),2*pi*sin(Value),0> is probably as close
to definition as we can express.  My thinking was just that maybe he could
elminate the added aproximation that comes with using a spline by
retrieving points from the spline that happen to be the very same points
that defined the spline.
Charles


Post a reply to this message

From: Slime
Subject: Re: Describing a perfect circle with a spline.
Date: 26 Sep 2007 00:54:12
Message: <46f9e5f4$1@news.povray.org>
> The simple answer is that you can not make a perfect circle with
> splines, because sin() and cos() have an infinite Taylor expansion.

I was under the impression that you could make a perfect circle with
rational b-splines (
http://www.cl.cam.ac.uk/teaching/2000/AGraphHCI/SMEG/node5.html ). These
work around the problem in some way because they're not just a simple
polynomial. POV-Ray doesn't support these so it's not useful here.

My question would be, why bother making a spline in the shape of a circle,
when you already know the <cos(theta),sin(theta),0> method? You can just use
that in place of your spline.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: gregjohn
Subject: Re: Describing a perfect circle with a spline.
Date: 26 Sep 2007 08:05:00
Message: <web.46fa4ab6bd0f564834d207310@news.povray.org>
"Slime" <fak### [at] emailaddress> wrote:
>
> My question would be, why bother making a spline in the shape of a circle,
> when you already know the <cos(theta),sin(theta),0> method? You can just use
> that in place of your spline.
>

http://news.povray.org/povray.binaries.animations/thread/%3C46f9ba61%40news.povray.org%3E/

Because then I can make a skinnable mesh2 macro where I can change from
cross-section to cross-section between circles and square-shaped contours.


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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