POV-Ray : Newsgroups : povray.pov4.discussion.general : Feature request: nonlinear scaling : Feature request: nonlinear scaling Server Time
3 May 2024 06:35:52 EDT (-0400)
  Feature request: nonlinear scaling  
From: philguy
Date: 22 May 2009 05:15:00
Message: <web.4a166bd8be4096595a8d9d390@news.povray.org>
In some of my pov-projects I came up with a helpful way of manipulating objects
- something I call "nonlinear scaling". For instance, when I have an upright
cylinder and I want to make it "wavy", I would set the x- and z-scaling to
depend on the y-coordinate. Here's a code snippet:

#declare slicecount = 0;
#declare delta_y = .01;
#while (slicecount < 5)
intersection{
  cylinder{<0,0,0>,<0,5,0>,1 pigment{rgb <0,1,.5>}}
  box{<-2,0,-2>,<2,delta_y,2> pigment{rgb <0,1,.5>}translate y*slicecount}
scale<sin(slicecount*5)/3+2/3,1,sin(slicecount*5)/3+2/3>}
#declare slicecount = slicecount + delta_y;
#end

If you render this, you see the original cylinder{<0,0,-3>,<0,5,-3>,1
pigment{rgb <0,.5,1>}} was transformed just as I wanted. I could use any
arbitrary function for scaling in any direction. Okay, I could use some
isosurface with this, bun once you exchange the cylinder with a larger csg this
is no longer an option.

Why "feature request"? If you render the above, you will see black artifacts on
the cylinder. Even increasing delta_y to ever so minute amounts will not
eliminate these (but parsing times soar). So it would be neat-o if there were
some way of "optimizing" that, just like the difference between placing a
million spheres and the sphere sweep.

Alternatively, is there any other way to achieve something like this? Or maybe
reduce the spots? I am aware that povray programm(ing/er) time is scarce and
precious, but maybe somebody has a flash of genius :) Or just share your
thoughts on this.


Attached is the image for the following code:

camera{location<20,10,0>*.6 look_at <0,0,0> right x*2}
light_source{<10,20,10> rgb <1,1,1>}
plane{y,0 pigment {rgb 1}}

cylinder{<0,0,-6>,<0,5,-6>,1 pigment{rgb <0,.5,1>}}

#declare slicecount = 0;
#declare delta_y = .01;
#while (slicecount < 5)
intersection{
  cylinder{<0,0,0>,<0,5,0>,1 pigment{rgb <0,1,.5>}}
  box{<-2,0,-2>,<2,delta_y,2> pigment{rgb <0,1,.5>}translate y*slicecount}
scale<sin(slicecount*5)/3+2/3,1,sin(slicecount*5)/3+2/3> translate z*-3}
#declare slicecount = slicecount + delta_y;
#end

#declare c1 = <0,0,-1>;
#declare c2 = <0,0,1>;
#declare c3 = <0,1,0>;
#declare c4 = <0,2,0>;
#declare c5 = <0,3,-1>;
#declare c6 = <0,3,1>;

#declare stickguy = union{
cylinder{c1,c3,.1}
cylinder{c2,c3,.1}
cylinder{c3,c4,.1}
cylinder{c4,c5,.1}
cylinder{c4,c6,.1}
torus{.5,.1 rotate z*90 translate y*3}}

object{stickguy pigment{rgb <1,.5,0>} rotate y*45 translate z*6}

#declare slicecount_2 = 0;
#declare delta_y_2 = .05;
#while (slicecount_2 < 5)
intersection{
  object{stickguy pigment{rgb <1,0,.5>}}
  box{<-2,0,-2>,<2,delta_y_2,2> pigment{rgb <0,1,.5>}translate y*slicecount_2}
translate x*1 scale<sin(slicecount_2*5)/4+.75,1,1> translate x*-1 rotate y*45
translate z*3}
#declare slicecount_2 = slicecount_2 + delta_y_2;
#end


Post a reply to this message


Attachments:
Download 'nonlin2.png' (38 KB)

Preview of image 'nonlin2.png'
nonlin2.png


 

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