POV-Ray : Newsgroups : povray.newusers : function help : Re: function help Server Time
5 Sep 2024 02:20:10 EDT (-0400)
  Re: function help  
From:
Date: 12 Feb 2002 06:32:45
Message: <efrh6u0866ofda0qlah7uqb21vmpc9dvq6@4ax.com>
On Tue, 12 Feb 2002 10:18:54 -0000, "Mick Hazelgrove"
<mic### [at] mhazelgrovefsnetcouk> wrote:
> No they don't produce the pattern I need - I need several spirals,
> spiral arms all radiating out from the center point. I need
> control over the tightness of the spirals and the number of arms.

I see. I think I can help you.

Let's create scene for testing

#include "math.inc"
plane{-z 0
  pigment{/* ... */}
  translate z*2
}
light_source{-100*z 1}
// camera default

/* ... */ is a place we will put stuff of spiral. Put next things into this
place and render each step.

Let's create not twisted pattern showing angle around origin.

    function{(atan2(x,y))/(2*pi)}

Then let's limit it to specified angle. All we need is to adjust value of
angle around origin to value of pattern in <0,1> range. Values outside range
should be clipped. We need parameter angle to adjust width of spiral area.
This could look this way:

    #local Angle=90;
    function{
      clip(
        adj_range2(
          atan2(abs(x),y),
          0,radians(Angle)/2,
          1,0
        ),
        0,1
      )
    }

Now wee need to add twisting. We have to rotate our fan according to distance
to origin. So we need additional parameter to describe rotation at first unit
radius.

    #local Angle=10;
    #local Rotate=90;
    #local Fan=function{
      clip(
        adj_range2(
          atan2(abs(x),y),
          0,radians(Angle)/2,
          1,0
        ),
        0,1
      )
    }
    #local Rot_Z=function(x,y,z,A)
        {Fan(x*cos(A)+y*sin(A),-x*sin(A)+y*cos(A),z)}
    function{Rot_Z(x,y,z,radians(Rotate)*f_r(x,y,z))}

Now we have ready stuff macro to create one-arm spiral with width of arm and
speed of twisting controlled by parameters. All you need now is to create
several arms (with different twisting and width), adjust, and combine as one
function. Also it could be worth to add initial rotation for arm. So here is
final sample scene.

//START
#version 3.5
#include "functions.inc"
#include "math.inc"
#macro Arm(Angle,Rotate,Init_Rotate)
  #local Fan=function{
    clip(
      adj_range2(
        atan2(abs(x),y),
        0,radians(Angle)/2,
        1,0
      ),
      0,1
    )
  }
  #local Rot_Z=function(x,y,z,A)
     {Fan(x*cos(A)+y*sin(A),-x*sin(A)+y*cos(A),z)}
  function{Rot_Z(x,y,z,radians(Init_Rotate)+radians(Rotate)*f_r(x,y,z))}
#end
plane{-z 0
  pigment{
    #local F1=Arm(5,50,0);
    #local F2=Arm(10,70,90);
    #local F3=Arm(20,90,180);
    #local F4=Arm(40,110,270);
    function{max(F1(x,y,z),F2(x,y,z),F3(x,y,z),F4(x,y,z))}
  }
  translate z*2
}
light_source{-100*z 1}
// END

I hope you like it.

ABX


Post a reply to this message

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