zurück

POV-Ray sphericals with a twist

The basics

Here you find more info about tweaking spherical projections of radial functions using my POV-Ray package »Sphericals.zip (simply unpack it to a subdirectory of your choice)

I want to show some possible tweaks for these parametric objects by discussing my model script SphericalHarmonics_Twisted.pov

Theory: A radial function gets projected onto a sphere:

R(φ,θ)= sinb(aθ)+cosd(cθ) +  sinf(eφ)+cosh(gφ)

x = R(φ,θ)cos(φ)×sin(θ) 
y = R(φ,θ)sin(φ)×sin(θ)            0 ≤ φ < 2π , 0 ≤ θ ≤π 
z = R(φ,θ)      ×cos(θ)

So the script runs as follows:

// POV-Ray source for modified spherical harmonics 
// Wolfgang.Urban@schule.at
// lots of examples: http://www.lifesmith.com/spharmin.html

   
global_settings {assumed_gamma 1.0}     

#include "math.inc"
#include "colors.inc"
#include "textures.inc"
#include "stones.inc"
#include "woods.inc"

// Values for        a,b,c,d,e,f,g,h  from formula  
#declare M=array[8] {7,1,3,2,4,5,6,4}

// ==========================================================================  
// set radial function and size for automatic scaling
// ==========================================================================  

#declare R=function(phi,theta){
           pow(sin(M[0]*theta),M[1]) + pow(cos(M[2]*theta),M[3])
          +pow(sin(M[4]*phi),  M[5]) + pow(cos(M[6]*phi)  ,M[7]) 
} 
                                 
#declare SH_SIZE  = 18;  // if SH_SIZE != 0: rescaled into [-SH_SIZE,+SH_SIZE]^3

// ==========================================================================  
// set tweaking values if necessary
// ==========================================================================  
 
#declare U_Steps = 300;   // 0..2pi
#declare V_Steps = 150;   // 0..pi    
    
#declare SH_Mode   = 1;   // 0=plain spheric, 1=twisted spheric, 2=cylindric, 
                          // 3=rectangle (no warps)

#declare SH_CZ     = 1;   // relative scaling in height, <0 flips vertical
#declare SH_R0     = 0;   // push out / pull back
#declare SH_Twist  = 0;   // twist along vertical
#declare SH_Spiral = 0;   // horizontal spiraling
#declare SH_RaiseR = 0;   // vertical shift depending on radius 
#declare SH_RaiseRA= 0;   // like SH_RaiseR but using abs(R) 
#declare SH_RaiseH = 0;   // vertical shift depending on theta
 
#include "spherical.inc" 

// ==========================================================================  
// texture
// ========================================================================== 
 
#include "sphericalTextures.inc" 

// UVTex_Phi          red lines along phi
// UVTex_Theta        blue lines along theta
// UVTex_Phi_Trans    transparency + red lines 
// UVTex_Theta_Trans  transparency + blue lines 
// UVTex_Grid         lines for phi and theta   
// UVTex_Grad         gradient along theta   
// UVTex_Grad_Agate   gradient along theta, big agate normal                         
// UVTex_Grad_AgateV  gradient along theta, big agate normal along theta
// UVTex_Grad_Marble  gradient along theta, stripes of marble normal         
// UVTex_Grad_Glow    gradient theta, nice glowing green (try without normal) 
// UVTex_RainbowV     rainbow along theta, ripple normal           
// UVTex_RainbowU     cyclic rainbow along phi 
// UVTex_Line         transparency with diagonal line   
// UVTex_SignOfR      R<0 : red, R>0 : green  

// UVTex_1            blue, red, and a white line  
// UVTex_Checker      chess board
     
// ==========================================================================  
// the scene
// ==========================================================================  
                                                                
camera {
        right    x*image_width/image_height 
        location <0,0,-80>
        look_at  <0,0,0> 
        angle    40      
} 
                     
sky_sphere { pigment { color rgb 0 } }
                     
light_source { < 500,100,-500> rgb <1.0,0.9,0.8> }
light_source { <-100,100,-500> rgb <0.3,0.3,0.5> }
 
                   
object { Surface  
    texture { 
       UVTex_RainbowV   
    }
    rotate  0*y
    rotate 40*x 
}

Render that script to see one of the sherical harmonics as described by Paul Bourke.

First details

Let's step through the script. For easy demonstration I simplify the radial function to
R = cos2(4θ) × sin(2φ)

Its flat mapping looks like

and the spherical projection becomes

Let's tweak that mapping!

Now let's see what those parameters can accomplish:

#declare SH_CZ     = 1;   // relative scaling in height, <0 flips vertical

SH_CZ scales the vertical axis. Here come CZ=0.5 and CZ=2. Not that automatic scaling changes a low height to a greater width.

 

#declare SH_R0     = 0;   // push out / pull back

A constant R0 is added to R. So a positive value expands the figure and makes the positive values (green) dominant. A negative value pulls the points back below zero(red).
Here come R=0.4 and R=-0.2

 

#declare SH_Twist  = 0;   // twist along vertical

That twist rotates points around the vertical axis by adding a portion of theta to phi. Therefore the blobs get stretched horizontally as in this example with SH_Twist = 3;

#declare SH_Spiral = 0;   // horizontal spiraling

Spiraling rotates points according to their R-Value. I use the opposite turning direction for negative Rs, as it looks better by giving nice intersections. An example with SH_Spiral = 5

#declare SH_RaiseR = 0;   // vertical shift depending on radius

Why not modify the theta-value? This can be done according to R. First pic has 2, second -2. I zoomed in to reveal some details.

 

#declare SH_RaiseRA= 0;   // like SH_RaiseR but using abs(R)

Same method, but modifying proportional to abs(R). Value is 2.

#declare SH_RaiseH = 0;   // vertical shift depending on theta

Or simply by rescaling theta itself. See the effect of 2 and -2. The first stretches, the second shrinks.

 

#declare U_Steps = 300;   // 0..2pi
#declare V_Steps = 150;    // 0..pi

A higher resolution like this gives smooth objects. The second image has both numbers set to 30 and shows some nice edges.

 

 

Use crazy combinations of these twists

Doing so can turn our nice little function into a wild bastard!

 

 

Now it's up to you - roll your own pics. And try to use these parameters in some morphing sequences to do some wild animations!