POV-Ray : Newsgroups : povray.general : Q: Sine Wave Server Time
4 Nov 2024 19:17:41 EST (-0500)
  Q: Sine Wave (Message 1 to 8 of 8)  
From: Ken
Subject: Q: Sine Wave
Date: 2 Feb 1999 02:28:45
Message: <36B6A90E.4FB9D6DF@pacbell.net>
Greetings !

Could someone please provide me an example of how to create
a sine wave using a while loop to translate/rotate(?) a sphere.

Example:

      --         --         --
    /    \     /    \     /    \
___/      \___/      \___/      \___



Appreciate any help and thanks !

-- 
Ken Tyler

tyl### [at] pacbellnet


Post a reply to this message

From: Marc Schimmler
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 02:43:54
Message: <36B6ACB0.1393FF2@ica.uni-stuttgart.de>
Ken wrote:
> 
> Greetings !
> 
> Could someone please provide me an example of how to create
> a sine wave using a while loop to translate/rotate(?) a sphere.
> 
> Example:
> 
>       --         --         --
>     /    \     /    \     /    \
> ___/      \___/      \___/      \___
> 
> Appreciate any help and thanks !
> 
> --
> Ken Tyler
> 
> tyl### [at] pacbellnet

I tried this one in v3.02

-------

camera {
 rotate <0,180,0>
 location <45,0,-40>
 look_at  <45,0,0>
 angle 60
}

#declare i=0;

#while (i<90)
 sphere {0,1 
         pigment {rgb <1,0,0>}
         finish {ambient 1.0}
		 translate <i,10*sin(i*pi/30),0>}
 #declare i = i + 1;
#end;

-----


Marc
-- 
Marc Schimmler


Post a reply to this message

From: Nieminen Mika
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 04:22:38
Message: <36b6c3de.0@news.povray.org>
Ken <tyl### [at] pacbellnet> wrote:
: Could someone please provide me an example of how to create
: a sine wave using a while loop to translate/rotate(?) a sphere.

  Since I'm a programmer and a perfectionist, I will give you a more
detailed answer than the one already given:

//-----------------------------------------------------------------------

// I'm not completely sure about the terms used here; correct as needed
#declare Amplitude=1;
#declare Cycles=3;
#declare StartAngle=pi*3/2;

#declare WaveStartX=-5;
#declare WaveWidth=10;

#declare ItemAmnt=100;
#declare Item=sphere { 0,.1 pigment { rgb <1,0,0> } finish { specular .5 } }

//---

#declare Index=0;
#while(Index<ItemAmnt)
  #declare Angle=StartAngle+2*pi*Cycles*Index/ItemAmnt;
  #declare PosX=WaveStartX+WaveWidth*Index/ItemAmnt;
  #declare PosY=Amplitude*sin(Angle);
  object { Item translate <PosX,PosY,0> }
  #declare Index=Index+1;
#end

//---

camera { location -z*20 look_at 0 angle 35 }
light_source { <100,150,-100> 1 }

//-----------------------------------------------------------------------

-- 
main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
*_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp. -*/


Post a reply to this message

From: Ken
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 05:44:13
Message: <36B6D6DE.6BB4D265@pacbell.net>
Nieminen Mika wrote:
> 
> Ken <tyl### [at] pacbellnet> wrote:
> : Could someone please provide me an example of how to create
> : a sine wave using a while loop to translate/rotate(?) a sphere.
> 
>   Since I'm a programmer and a perfectionist, I will give you a more
> detailed answer than the one already given:
> 
> //-----------------------------------------------------------------------
<snip> 

Thank you sir and thank you Mark as well for your example.

Next question -

Now that I have the shape established I would like to
rotate the face of the defining object to follow the
curve of the wave.

 Say I had a box(-1,1 scale<1,0.1,10>}

The flat face of the object is in the +y direction.
As it moves through the curve it needs to rotate
+/- 180*z to keep from having a stair stepped appearance.

Again any help would be appreciated.

-- 
Ken Tyler

tyl### [at] pacbellnet


Post a reply to this message

From: Marc Schimmler
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 06:16:50
Message: <36B6DEA1.D401CFEE@ica.uni-stuttgart.de>
Ken wrote:
> 
> Nieminen Mika wrote:
> >
> > Ken <tyl### [at] pacbellnet> wrote:
> > : Could someone please provide me an example of how to create
> > : a sine wave using a while loop to translate/rotate(?) a sphere.
> >
> >   Since I'm a programmer and a perfectionist, I will give you a more
> > detailed answer than the one already given:
> >
> > //-----------------------------------------------------------------------
> <snip>
> 
> Thank you sir and thank you Mark as well for your example.
> 
> Next question -
> 
> Now that I have the shape established I would like to
> rotate the face of the defining object to follow the
> curve of the wave.
> 
>  Say I had a box(-1,1 scale<1,0.1,10>}
> 
> The flat face of the object is in the +y direction.
> As it moves through the curve it needs to rotate
> +/- 180*z to keep from having a stair stepped appearance.
> 
> Again any help would be appreciated.
> 
> --
> Ken Tyler
> 
> tyl### [at] pacbellnet


Hi Ken!
-----
camera {
 rotate <0,180,0>
 location <45,0,-80>
 look_at  <45,0,0>
 angle 60
}

#declare i=0;

#while (i<90)
 #declare angle1 = i*pi/30;
 box {<-0.5,-0.5,-0.5>,<0.5,0.5,0.5> 
         pigment {rgb <1,0,0>}
         finish {ambient 1.0}
         rotate <0,0,45*sin(angle1)>
		 translate <i,10*sin(angle1+pi/2),0>}
 #declare i = i + 1;
#end;

----

The rotation follows the sine. I inserted a phase differenvce of pi/2 to
have the sine starting in a horizontal position.

I hope it helps!


Marc
-- 
Marc Schimmler


Post a reply to this message

From: Ken
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 06:23:45
Message: <36B6E022.87FF2023@pacbell.net>
Marc Schimmler wrote:
> 
> Ken wrote:
> >
> > Nieminen Mika wrote:
> > >
> > > Ken <tyl### [at] pacbellnet> wrote:
> > > : Could someone please provide me an example of how to create
> > > : a sine wave using a while loop to translate/rotate(?) a sphere.
> > >
> > >   Since I'm a programmer and a perfectionist, I will give you a more
> > > detailed answer than the one already given:
> > >
> > > //-----------------------------------------------------------------------
> > <snip>
> >
> > Thank you sir and thank you Mark as well for your example.
> >
> > Next question -
> >
> > Now that I have the shape established I would like to
> > rotate the face of the defining object to follow the
> > curve of the wave.
> >
> >  Say I had a box(-1,1 scale<1,0.1,10>}
> >
> > The flat face of the object is in the +y direction.
> > As it moves through the curve it needs to rotate
> > +/- 180*z to keep from having a stair stepped appearance.
> >
> > Again any help would be appreciated.
> >
> > --
> > Ken Tyler
> >
> > tyl### [at] pacbellnet
> 
> Hi Ken!
> -----
> camera {
>  rotate <0,180,0>
>  location <45,0,-80>
>  look_at  <45,0,0>
>  angle 60
> }
> 
> #declare i=0;
> 
> #while (i<90)
>  #declare angle1 = i*pi/30;
>  box {<-0.5,-0.5,-0.5>,<0.5,0.5,0.5>
>          pigment {rgb <1,0,0>}
>          finish {ambient 1.0}
>          rotate <0,0,45*sin(angle1)>
>                  translate <i,10*sin(angle1+pi/2),0>}
>  #declare i = i + 1;
> #end;
> 
> ----
> 
> The rotation follows the sine. I inserted a phase differenvce of pi/2 to
> have the sine starting in a horizontal position.
> 
> I hope it helps!
> 
> Marc
> --
> Marc Schimmler

Thank you very much. I will put it through it's paces
right now.

Now - how about a square wave ?
Just kidding :)

-- 
Ken Tyler

tyl### [at] pacbellnet


Post a reply to this message

From: Marc Schimmler
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 06:38:24
Message: <36B6E38E.45C57DC6@ica.uni-stuttgart.de>
Ken wrote:
> 
> Marc Schimmler wrote:
> >
> > Ken wrote:
> > >
> > > Nieminen Mika wrote:
> > > >
> > > > Ken <tyl### [at] pacbellnet> wrote:
> > > > : Could someone please provide me an example of how to create
> > > > : a sine wave using a while loop to translate/rotate(?) a sphere.
> > > >
> > > >   Since I'm a programmer and a perfectionist, I will give you a more
> > > > detailed answer than the one already given:
> > > >
> > > > //-----------------------------------------------------------------------
> > > <snip>
> > >
> > > Thank you sir and thank you Mark as well for your example.
> > >
> > > Next question -
> > >
> > > Now that I have the shape established I would like to
> > > rotate the face of the defining object to follow the
> > > curve of the wave.
> > >
> > >  Say I had a box(-1,1 scale<1,0.1,10>}
> > >
> > > The flat face of the object is in the +y direction.
> > > As it moves through the curve it needs to rotate
> > > +/- 180*z to keep from having a stair stepped appearance.
> > >
> > > Again any help would be appreciated.
> > >
> > > --
> > > Ken Tyler
> > >
> > > tyl### [at] pacbellnet
> >
> > Hi Ken!
> > -----
> > camera {
> >  rotate <0,180,0>
> >  location <45,0,-80>
> >  look_at  <45,0,0>
> >  angle 60
> > }
> >
> > #declare i=0;
> >
> > #while (i<90)
> >  #declare angle1 = i*pi/30;
> >  box {<-0.5,-0.5,-0.5>,<0.5,0.5,0.5>
> >          pigment {rgb <1,0,0>}
> >          finish {ambient 1.0}
> >          rotate <0,0,45*sin(angle1)>
> >                  translate <i,10*sin(angle1+pi/2),0>}
> >  #declare i = i + 1;
> > #end;
> >
> > ----
> >
> > The rotation follows the sine. I inserted a phase differenvce of pi/2 to
> > have the sine starting in a horizontal position.
> >
> > I hope it helps!
> >
> > Marc
> > --
> > Marc Schimmler
> 
> Thank you very much. I will put it through it's paces
> right now.
> 
> Now - how about a square wave ?
> Just kidding :)
> 
> --
> Ken Tyler
> 
> tyl### [at] pacbellnet

I had messed up a signum!

It should be 

         rotate <0,0,-45*sin(angle1)>

Sorry!



Marc
-- 
Marc Schimmler


Post a reply to this message

From: Nieminen Mika
Subject: Re: Q: Sine Wave
Date: 2 Feb 1999 07:11:30
Message: <36b6eb72.0@news.povray.org>
Ken <tyl### [at] pacbellnet> wrote:
: Now that I have the shape established I would like to
: rotate the face of the defining object to follow the
: curve of the wave.

:  Say I had a box(-1,1 scale<1,0.1,10>}

  The answer to this question is not as simple as Marc stated (at least
in the general case). Since I _am_ a perfectionist, I will give you the
complete mathematical answer:

  We calculate the x coordinate of the object with the formula:

PosX = WaveWidth*Index/ItemAmnt

  Now the y coordinate which we want is calculated this way:

Angle = StartAngle+2*pi*Cycles*PosX/WaveWidth
PosY = Amplitude*sin(Angle)

  What we now need to achieve what you want is the arcus tangent of the
slope at the current position in the sine function. For this we need to
calculate the derived function of the above. Above we have acutally this:

Amplitude*sin(StartAngle+2*pi*Cycles*PosX/WaveWidth)

  The derived function of this function is:

Amplitude*cos(StartAngle+2*pi*Cycles*PosX/WaveWidth)*2*pi*Cycles/WaveWidth

ie:

Amplitude*cos(Angle)*2*pi*Cycles/WaveWidth

  Now this is the slope (ie. the tangent) of the function at the current
point. To get the angle we need to calculate the arcus tangent of this. Ie:

RotAngle = atan(Amplitude*cos(Angle)*2*pi*Cycles/WaveWidth)

  So we can now rewrite the code to achieve what you want:

//-------------------------------------------------------------------------

// I'm not completely sure about the terms used here; correct as needed
#declare Amplitude=1;
#declare Cycles=3;
#declare StartAngle=pi*3/2;

#declare WaveStartX=-5;
#declare WaveWidth=10;

#declare ItemAmnt=50;
#declare Item=
box { -1,1 scale <1,.1,5>*.2 pigment { rgb <1,0,0> } finish { specular .5 } }

//---

#declare Index=0;
#while(Index<ItemAmnt)
  #declare PosX=WaveWidth*Index/ItemAmnt;
  #declare Angle=StartAngle+2*pi*Cycles*PosX/WaveWidth;
  #declare PosY=Amplitude*sin(Angle);
  #declare RotAngle=atan2(Amplitude*cos(Angle)*2*pi*Cycles/WaveWidth,1);
  #declare PosX=PosX+WaveStartX;
  object
  { Item
    rotate z*degrees(RotAngle)
    translate <PosX,PosY,0>
  }
  #declare Index=Index+1;
#end

//---

camera { location -z*20 look_at 0 angle 35 }
light_source { <100,150,-100> 1 }

//-------------------------------------------------------------------------


  Real coders are not afraid of mathematics!

-- 
main(i){char*_="BdsyFBThhHFBThhHFRz]NFTITQF|DJIFHQhhF";while(i=
*_++)for(;i>1;printf("%s",i-70?i&1?"[]":" ":(i=0,"\n")),i/=2);} /*- Warp. -*/


Post a reply to this message

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