POV-Ray : Newsgroups : povray.advanced-users : sinewave wrapped around a cylinder Server Time
1 Nov 2024 05:22:14 EDT (-0400)
  sinewave wrapped around a cylinder (Message 1 to 8 of 8)  
From: Leef me
Subject: sinewave wrapped around a cylinder
Date: 1 Oct 2007 03:00:01
Message: <web.47009a15630ef383892adb1d0@news.povray.org>
I have seen a drinking glass design that has metal embedded in it. The shape
seems to be a sinewave, or rather 4 periods of a sinewave.

I tried to create a shape that would be useful for this and to allow for
other uses, such as truncating a cylinder to reveal the sinewave on the
end.

Using the code to create a tube-like shape works fine. Trying to use this
tube to truncate the cylinder take much longer to render. And because I
used sphere to form the shape, the edge is somewhat beveled.

I saw gregjohn's thread "Describing a perfect circle with a spline" but I
don't understand much from that discussion.

Any suggestions on alternate ways to accomplish the difference or to create
the shape so that render time is reduced? Perhaps there are some simple
shapes that could be combined to better advantage.

I was trying to use a spline and thought it needed x,y,z coordinates, so I
never thought to use vrotate. Here is my code:



#version 3.6;


// this code creates a spline that represents 4 periods of a sine wave,
//  this spline is "wrapped" around a cylinder

// the difference object takes much longer to render when the 360 spheres
are part of the difference


global_settings {
  assumed_gamma 1.0
}

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

camera {
        orthographic
  location  <0, 0,-25>
  angle 0
  look_at   <0.0, 0.0,  0.0>
}

#declare ampl=1;
#declare pi2 = pi*2;
#declare pistep= pi/180;

#declare  zangle=0 ;

#declare sphere_spline = spline {linear_spline

#while (zangle<pi2)

        #declare radi=10;

        #declare zy = ampl*sin(4*zangle);
        #declare cosq=radi*cos(zangle+pistep*clock*360);
        #declare sinq=radi*sin(zangle+pistep*clock*360);

               zangle < cosq, zy*1 , sinq >

        #declare zangle = zangle + pistep;

#end


}


difference {


                // outside of cylinder
                cylinder {
                  <0,-5, 0>,<0,5, 0>  radi     open
                        pigment { color rgbt<0,1,1,.5>}
                        }

                // carve out inside of cylinder
                cylinder {
                  <0,-5, 0>,<0,5, 0>  radi-.1     open
                        pigment { color rgbt<0,1,1,.5>}
                        }

        #if(1)   // 0= disable spline, which reduces render time

                // spline to form edge of cylinder
                #declare ctr = 0;
                #while (ctr < pi2)
                  sphere {
                    sphere_spline(ctr) 2 //scale<1,2,1>
                        pigment { color rgbt<0,1,1,.5>}

                  }
                  #declare ctr = ctr + pistep;

        #end


#end


}



light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <0, 00, -50>
}

Thanks in advance,

Leef_me


Post a reply to this message

From: Christian Froeschlin
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 06:27:47
Message: <4700cba3$1@news.povray.org>
Leef_me wrote:

> Any suggestions on alternate ways to accomplish the difference or to create
> the shape so that render time is reduced? Perhaps  there are some simple
> shapes that could be combined to better advantage.

Using a parametric object or isosurface might be less cludgy
than chaining spheres along a spline but not necessarily faster.
But maybe you can get away using a texture instead of geometry:

cylinder
{
   0,5*y,1

   pigment
   {
     function {y-sin(x*8*pi)}
     color_map
     {
       [0    color rgbt 1]
       [0.5  color rgbt 1]
       [0.51 color rgb  1]
       [1    color rgb  1]
     }

     warp
     {
       cylindrical
     }

     scale 0.5*y

   }

   rotate y
}


Post a reply to this message

From: Trevor G Quayle
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 12:30:00
Message: <web.47012051eb21779cc150d4c10@news.povray.org>
"Leef_me" <nomail@nomail> wrote:
> I have seen a drinking glass design that has metal embedded in it. The shape
> seems to be a sinewave, or rather 4 periods of a sinewave.

Meshes can be very fast comparatively.  Try using a heightfield (mesh
object), you can take advantage of the 'radial' pattern and use 'frequency'
and 'sine_wave' to get the appropriate shapes.

Try this which creates a function from such a pattern and uses it to create
a sine-shaped heightfield of user controllable resoulution

//START
global_settings {
  assumed_gamma 1.0
}

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

camera {
        orthographic
  location  <0, 20,-20>
  angle 0
  look_at   <0.0, 0.0,  0.0>
}

light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <50, 50, 50>
}

#declare PIGGY1 =  pigment{radial sine_wave colour_map{[0 rgb 0][1 rgb 1]}
frequency 4 translate 1/2 rotate -x*90} //radial pigment with 4 periods,
sine_wave shape
#declare Func1A = function {pigment{PIGGY1}} //convert to function

difference{
  cylinder{0,y*5,10}
  cylinder{-y*1,y*6,9}
  height_field{function 100,100
{pattern{function{Func1A(x,y,z).gray}}}//100,100 = resoltution, can be
adjusted accordingly
    smooth
    translate <-1/2,0,-1/2> scale <20,3,20>
  }
  pigment{rgb 1}
}
//END

-tgq


Post a reply to this message

From: Alain
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 15:22:32
Message: <470148f8$1@news.povray.org>
Leef_me nous apporta ses lumieres en ce 2007/10/01 02:56:
> I have seen a drinking glass design that has metal embedded in it. The shape
> seems to be a sinewave, or rather 4 periods of a sinewave.
> 
> I tried to create a shape that would be useful for this and to allow for
> other uses, such as truncating a cylinder to reveal the sinewave on the
> end.
> 
> Using the code to create a tube-like shape works fine. Trying to use this
> tube to truncate the cylinder take much longer to render. And because I
> used sphere to form the shape, the edge is somewhat beveled.
> 
> I saw gregjohn's thread "Describing a perfect circle with a spline" but I
> don't understand much from that discussion.
> 
> Any suggestions on alternate ways to accomplish the difference or to create
> the shape so that render time is reduced? Perhaps there are some simple
> shapes that could be combined to better advantage.
> 
> I was trying to use a spline and thought it needed x,y,z coordinates, so I
> never thought to use vrotate. Here is my code:
> 
> Thanks in advance,
> 
> Leef_me
> 
> 
> 
When you have a difference, all components see ther bounding box expanded to 
that of the largest component. When rays are shots, they are compared to EVERY 
bounding box, then tested against every components = major slowdown.

Replace your chain of spheres with this:
  blob{threshold 0.1
   #declare ctr = 0;
   #while (ctr < pi2)
         sphere {
         sphere_spline(ctr) 2,1 //scale<1,2,1>
           }
          #declare ctr = ctr + pistep;
	#end
	}
My time went from 3:54 to 0:59!
When using a blob, the bounding is handled differently, and in this case much 
more effeciently.
You can also reduce the number of components: reducing pistep to pi/45 gives the 
same apearance in 0:36.

Another solution would be to use an isosurface. Probably slower that the blob 
option, but giving you an "exact" shape.

-- 
Alain
-------------------------------------------------
You know you've been raytracing too long when you've gained twenty pounds 
sitting at the computer, but can't tell because your beard covers your stomach.
Taps a.k.a. Tapio Vocadlo


Post a reply to this message

From: Leef me
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 17:10:01
Message: <web.47016167eb21779ced05561a0@news.povray.org>
Christian Froeschlin <chr### [at] chrfrde> wrote:
> Leef_me wrote:
>
> > Any suggestions on alternate ways to accomplish the difference or to create
> > the shape so that render time is reduced? Perhaps  there are some simple
> > shapes that could be combined to better advantage.
>
> Using a parametric object or isosurface might be less cludgy
> than chaining spheres along a spline but not necessarily faster.
> But maybe you can get away using a texture instead of geometry:
>
> cylinder
> {
>    0,5*y,1
>
>    pigment
>    {
>      function {y-sin(x*8*pi)}
>      color_map
>      {
>        [0    color rgbt 1]
>        [0.5  color rgbt 1]
>        [0.51 color rgb  1]
>        [1    color rgb  1]
>      }
>
>      warp
>      {
>        cylindrical
>      }
>
>      scale 0.5*y
>
>    }
>
>    rotate y
> }

Thanks CF. Not quite what I was looking for but using the transmit parameter
of rgbt tends to create some interesting effects that comes close to what I
wanted. Though I think I understand the concept of color maps, they scare
me.

Leef_me


Post a reply to this message

From: Leef me
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 17:30:00
Message: <web.47016675eb21779ced05561a0@news.povray.org>
"Trevor G Quayle" <Tin### [at] hotmailcom> wrote:
> "Leef_me" <nomail@nomail> wrote:
> > I have seen a drinking glass design that has metal embedded in it. The shape
> > seems to be a sinewave, or rather 4 periods of a sinewave.
>
> Meshes can be very fast comparatively.  Try using a heightfield (mesh
> object), you can take advantage of the 'radial' pattern and use 'frequency'
> and 'sine_wave' to get the appropriate shapes.
>
> Try this which creates a function from such a pattern and uses it to create
> a sine-shaped heightfield of user controllable resoulution
>
--8<----------8<------------8<------------8<------------8<----------
removed for brevity
--8<------------8<------------8<------------8<------------8<--------
> -tgq

SPOT-ON!  This what I was thinking of exactly. It took me a few tries to
understand how to position it, but I'm getting the idea. I commented out
the (2) cylinder statements to see just the heightfield mesh.

I thought that the 'subtraction' would stop when the heightfield stopped.
But, I see that it truncates the rest of the cylinder regardless of its
length.  I don't undertand how that works.

Leef_me


Post a reply to this message

From: Leef me
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 17:50:00
Message: <web.47016afeeb21779ced05561a0@news.povray.org>
Alain <ele### [at] netscapenet> wrote:
> Leef_me nous apporta ses lumieres en ce 2007/10/01 02:56:
> > I have seen a drinking glass design that has metal embedded in it. The shape
> > seems to be a sinewave, or rather 4 periods of a sinewave.
> >


> When you have a difference, all components see ther bounding box expanded to
> that of the largest component. When rays are shots, they are compared to EVERY
> bounding box, then tested against every components = major slowdown.
>
> Replace your chain of spheres with this:
>   blob{threshold 0.1
>    #declare ctr = 0;
>    #while (ctr < pi2)
>          sphere {
>          sphere_spline(ctr) 2,1 //scale<1,2,1>
>            }
>           #declare ctr = ctr + pistep;
>  #end
>  }
> My time went from 3:54 to 0:59!
> When using a blob, the bounding is handled differently, and in this case much
> more effeciently.
> You can also reduce the number of components: reducing pistep to pi/45 gives the
> same apearance in 0:36.
>
> Another solution would be to use an isosurface. Probably slower that the blob
> option, but giving you an "exact" shape.
>
> --
> Alain
> -------------------------------------------------

Thanks Alain. I got a similar improvement on render time. I didn't try
changing pistep. Trevor's response was what I asked for, but your's is
very useful to know.

Leef_me


Post a reply to this message

From: Trevor G Quayle
Subject: Re: sinewave wrapped around a cylinder
Date: 1 Oct 2007 20:30:01
Message: <web.4701906beb21779c5e73ab330@news.povray.org>
"Leef_me" <nomail@nomail> wrote:
> "Trevor G Quayle" <Tin### [at] hotmailcom> wrote:
>
> SPOT-ON!  This what I was thinking of exactly. It took me a few tries to
> understand how to position it, but I'm getting the idea. I commented out
> the (2) cylinder statements to see just the heightfield mesh.

I've used heightfields for a lot of interesting things, especially once I
figured out how to use and manipulate internal functions for it.

There are some little oddities that take some time to figure out:
-you have to make sure all values are less than or equal to 1, after that it
cycles back to 0 and can give odd results.
-learn how to use scaling and colour mapping to get relative heights
-image_maps and heightfield function patterns read from the x-y plane but
the heightfield is mapped on the x-z plane.  this can be one of the
trickiest to get used to.

>
> I thought that the 'subtraction' would stop when the heightfield stopped.
> But, I see that it truncates the rest of the cylinder regardless of its
> length.  I don't undertand how that works.
>
> Leef_me

I always thought the same at first, but I guess heightfields are infinite in
the +/-y direction like a plane, but are bounded in the x and z directions.

-tgq


Post a reply to this message

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