POV-Ray : Newsgroups : povray.text.scene-files : Souce code for "The remains of an iso sphere: Take 2 " : Souce code for "The remains of an iso sphere: Take 2 " Server Time
3 Jul 2024 02:40:05 EDT (-0400)
  Souce code for "The remains of an iso sphere: Take 2 "  
From: Tor Olav Kristensen
Date: 28 Dec 2001 20:59:22
Message: <3C2D2372.3E564379@hotmail.com>
Below is the source code for the image that I posted
to povray.binaries.images 28. Dec. 2001. (My PC's month
setting was wrongly set to November, so that message
may appear to be posted in that month.)

Here's links to that thread:
news://news.povray.org/3C04C246.6EF2A5AB%40hotmail.com
http://news.povray.org/povray.binaries.images/20965/


Tor Olav

P.S.:
The code also contains settings for several other
"Sphere Spirals" images.


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2001 by Tor Olav Kristensen
// Email: tor### [at] hotmailcom
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5; // Beta

#include "colors.inc"
#include "functions.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro SphereSpiralsFunction(Rmaj, Rmin, PhiFn, NrOfBands, GapRatio)

  #local DivAngle = 2*pi/NrOfBands;
  #local GapAngle = DivAngle*GapRatio;
/*
  #local CosAlpaFn =
    function { x/sqrt(x^2 + z^2) }
  #local SinAlpaFn =
    function { z/sqrt(x^2 + z^2) }
*/
  #local CosBetaFn =
    function { sqrt(x^2 + z^2)/sqrt(x^2 + y^2 + z^2) }
  #local SinBetaFn =
    function { y/sqrt(x^2 + y^2 + z^2) }

  #local AngleFn = function { atan2(z, x) }
  #local AdjAngleFn = function(a) { a + select(a, 2*pi, 0) }

  #local ModAngleFn =
    function {
      mod(AdjAngleFn(AngleFn(x, y, z) - PhiFn(x, y, z)), DivAngle)
    }
  #local Angle0Fn =
    function { AngleFn(x, y, z) - ModAngleFn(x, y, z) }
  #local Angle2Fn = function { Angle0Fn(x, y, z) + GapAngle }

  function {
    select(
      ModAngleFn(x, y, z) - GapAngle,
      select(
        ModAngleFn(x, y, z) - GapAngle/2,
        f_sphere(
          x - Rmaj*CosBetaFn(x, y, z)*cos(Angle0Fn(x, y, z)),
          y - Rmaj*SinBetaFn(x, y, z),
          z - Rmaj*CosBetaFn(x, y, z)*sin(Angle0Fn(x, y, z)),
          Rmin
        ),
        f_sphere(
          x - Rmaj*CosBetaFn(x, y, z)*cos(Angle2Fn(x, y, z)),
          y - Rmaj*SinBetaFn(x, y, z),
          z - Rmaj*CosBetaFn(x, y, z)*sin(Angle2Fn(x, y, z)),
          Rmin
        )
      ),
      abs(f_sphere(x, y, z, Rmaj)) - Rmin
    )
  }

#end // macro SphereSpiralsFunction

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Set up different functions to control the twisting of the bands.
// Then call the macro above with these functions as parameters and
// different settings for the number of bands and the ratio between
// the gaps and the bands.

#declare Rmajor = 3.0;
#declare Rminor = 0.2;
// Decrease Rminor above to e.g. 0.02 to see clearer the effect of
// the GapRatio parameter.


#declare PhiFns =
array[6] {
  function { 0 },
  function { y/Rmajor*pi },
  function { exp(y/3) },
  function { y/4 + f_noise3d(0, y, 0) },
  function { y/2 - f_noise3d(x, y, z) }
  function {
    1 - 2*
    f_noise3d(
      Rmajor*x/f_sphere(x, y, z, 0),
      Rmajor*y/f_sphere(x, y, z, 0),
      Rmajor*z/f_sphere(x, y, z, 0)
    )
  }
}


#declare SphereSpiralsFns = array[6]

#declare SphereSpiralsFns[0] = 
SphereSpiralsFunction(
  Rmajor, Rminor, function { PhiFns[0](x, y, z) },  8, 2/3
) 

#declare SphereSpiralsFns[1] = 
SphereSpiralsFunction(
  Rmajor, Rminor, function { PhiFns[1](x, y, z) }, 20, 2/3
) 

#declare SphereSpiralsFns[2] = 
SphereSpiralsFunction(
  Rmajor, Rminor, function { PhiFns[2](x, y, z) },  6, 2/3
) 

#declare SphereSpiralsFns[3] = 
SphereSpiralsFunction(
  Rmajor, Rminor, function { PhiFns[3](x, y, z) }, 12, 3/4
) 

#declare SphereSpiralsFns[4] = 
SphereSpiralsFunction(
  Rmajor, Rminor, function { PhiFns[4](x, y, z) }, 20, 3/5
) 

#declare SphereSpiralsFns[5] = 
SphereSpiralsFunction(
  Rmajor, Rminor, function { PhiFns[5](x, y, z) }, 20, 1/2
) 

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Define the iso-surface and texture it.

#declare FnChoice = 2; // Also try the other values; from 0 to 5

#declare SphereRemainsIso =
isosurface {
  function { SphereSpiralsFns[FnChoice](x, y, z) }
//  max_gradient 10
  contained_by { sphere { <0, 0, 0>, Rmajor + Rminor } }
}

object {
  SphereRemainsIso
  texture {
    pigment { color Blue + White }
    finish {
    	ambient 0
    	diffuse 1
    	specular 1
    	roughness 0.02
    	brilliance 2
    }
  }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color (Blue + Cyan)/4 }

light_source {
  <-2, 3, -2>*100 // *0
  color White
  shadowless
}

camera {
  location <-9, 0, -5>
  look_at <0, 0, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
/*
// For the curious:
// Try to replace the function returned in the SphereSpiralsFunction
// macro with this code and then render with FnChoice set to 0.

  #local Angle1Fn =
    function {
      Angle0Fn(x, y, z) +
      select(ModAngleFn(x, y, z) - DivAngle/2, 0, DivAngle)
    }

  function {
    min(
      f_sphere(
        x - Rmaj*CosBetaFn(x, y, z)*cos(Angle1Fn(x, y, z)),
        y - Rmaj*SinBetaFn(x, y, z),
        z - Rmaj*CosBetaFn(x, y, z)*sin(Angle1Fn(x, y, z)),
        Rmin
      ),
      f_sphere(
        x - Rmaj*CosBetaFn(x, y, z)*cos(Angle2Fn(x, y, z)),
        y - Rmaj*SinBetaFn(x, y, z),
        z - Rmaj*CosBetaFn(x, y, z)*sin(Angle2Fn(x, y, z)),
        Rmin
      )
    )
  }

*/
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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