POV-Ray : Newsgroups : povray.text.scene-files : Source code for "Almost Sphere Spirals" : Source code for "Almost Sphere Spirals" Server Time
3 Jul 2024 02:13:50 EDT (-0400)
  Source code for "Almost Sphere Spirals"  
From: Tor Olav Kristensen
Date: 27 Jan 2002 19:35:55
Message: <3C549C14.A9009E4@online.no>
At 24. January 2002 I posted an image to povray.binaries.images.
Below is the source for it.

Here are links to that post:
http://news.povray.org/povray.binaries.images/21703/
news://news.povray.org/3C508AF7.260EBD52%40hotmail.com

The SphereSpiralsFunction() below is optimized for speed rather than
for understandability. If you wish to have a look at a more readable
version of it, you can find one within the source code in this post:

"Souce code for "The remains of an iso sphere: Take 2""
http://news.povray.org/povray.text.scene-files/20990/
news://news.povray.org/3C2D2372.3E564379%40hotmail.com
(28. Dec. 2001 to this group)

Note that when I rendered this image, a small defect appeared at the
"south pole" of the sphere. I'm not sure what causes this. (It might
be caused by the very high (or infinite) gradient for the iso-surface
function at the "poles".)


Tor Olav


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

#version 3.5; // Beta 9

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

/*
  Quote from "rad_def.inc":
  "DO NOT FORGET TO USE THE +QR/Radiosity=on OPTION"
*/

global_settings {
  radiosity { Rad_Settings(Radiosity_OutdoorHQ, on, off) }
}

#declare Nothing = 1E-10;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Modified versions of a texture once made by Gilles Tran

#declare GillesTexMod1 =
texture {
  pigment {
    bozo
    color_map {
      [ 0 color White*0.7 ]
      [ 1 color White*1.1 ]
    }
  }
  normal {
    agate 0.3
    scale 1.6
  }
  finish {
    ambient 0
    diffuse 0.8
    specular 0.1
    roughness 0.1
    metallic
    brilliance 1
  }
  scale 0.4
}

#declare GillesTexMod2 =
texture {
  pigment {
    crackle solid
    color_map {
      [ 0 color White*0.5 ]
      [ 1 color White*0.9 ]
    }
  }
  normal {
    granite 0.9
    scale 3
  }
  finish {
    ambient 0
    diffuse 0.8
    specular 0.1
    roughness 0.1
    metallic
    brilliance 1
  }
  scale 0.4
}

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

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

  #local TwoPi = 2*pi;
  #local DivAngle = TwoPi/NrOfBands;
  #local GapAngle = DivAngle*GapRatio;
  #local HalfGapAngle = GapAngle/2;

  function {
    select(
      mod(
        atan2(z, x) - PhiFn(x, y, z) +
        select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0),
        DivAngle
      ) - GapAngle,

      select(
        mod(
          atan2(z, x) - PhiFn(x, y, z) +
          select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0),
          DivAngle
        ) - HalfGapAngle,

        f_sphere(
          x - Rmaj*f_r(x, 0, z)/(Nothing + f_r(x, y, z))*
          cos(
            atan2(z, x) -
            mod(
              atan2(z, x) - PhiFn(x, y, z) +
              select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0),
              DivAngle
            )
          ),

          y - Rmaj*y/(Nothing + f_r(x, y, z)),

          z - Rmaj*f_r(x, 0, z)/(Nothing + f_r(x, y, z))*
          sin(
            atan2(z, x) -
            mod(
              atan2(z, x) - PhiFn(x, y, z) +
              select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0),
              DivAngle
            )
          ),

          Rmin
        ),
        
        f_sphere(
          x - Rmaj*f_r(x, 0, z)/(Nothing + f_r(x, y, z))*
          cos(
            atan2(z, x) -
            mod(
              atan2(z, x) - PhiFn(x, y, z) +
              select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0),
              DivAngle
            ) + GapAngle
          ),

          y - Rmaj*y/(Nothing + f_r(x, y, z)),

          z - Rmaj*f_r(x, 0, z)/(Nothing + f_r(x, y, z))*
          sin(
            atan2(z, x) -
            mod(
              atan2(z, x) - PhiFn(x, y, z) +
              select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0),
              DivAngle
            ) + GapAngle
          ),

          Rmin
        )
      ),

      abs(f_sphere(x, y, z, Rmaj)) - Rmin
    )
  }

#end // macro SphereSpiralsFunction

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

#declare NegOne = Nothing - 1;
#declare PosOne = 1 - Nothing;

#declare K = 1.8; // 2.1 // "Twisting rate"

#declare Rmajor = 3.0;
#declare Rminor = 0.1;

/*
// A more understandable, but slower version of the macro call below.

#declare ClampFn = function(N, Min, Max) { max(Min, min(N, Max)) }

#declare yFn =
function { ClampFn(y/(Nothing + f_r(x, y, z)), NegOne, PosOne) }

#declare SphereSpiralsFn = 
SphereSpiralsFunction(
  Rmajor,
  Rminor,
  function { ln(2/(1 - yFn(x, y, z)) - 1)/K },
  4,
  1/2
) 
*/

#declare SphereSpiralsFn = 
SphereSpiralsFunction(
  Rmajor,
  Rminor,
  function {
    ln(
      2/(1 - max(NegOne, min(y/(Nothing + f_r(x, y, z)), PosOne))) - 1
    )/K
  },
  4,
  1/2
) 

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

isosurface {
  function { SphereSpiralsFn(x, y, z) }
  max_gradient 4 // 115 // 250 // 4000 // ...
//  accuracy 1E-12
  contained_by { sphere { <0, 0, 0>, Rmajor + Rminor + 0.01 } }
  texture { GillesTexMod1 }
  rotate 180*x 
  rotate 32*y
//  no_shadow
}

plane {
  y, -(Rmajor + Rminor + 2.5)
  texture { GillesTexMod2 }
}

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

sky_sphere {
  pigment {
    gradient y
    color_map {
      [ 0 White ]
      [ 1 rgb <0.25, 0.46, 0.80>*0.9 ]
    }
  }
}

light_source {
  <34, 29, -16>*4
  color rgb <0.76, 0.62, 0.34>
  area_light
  2*x, 2*z,
  4, 4
  circular
  orient
  adaptive 1
  jitter
}

camera {
  location <0, 21.7, -10.5>
  look_at <-2.5, 0, 0>
  angle 34
}

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


Post a reply to this message

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