POV-Ray : Newsgroups : povray.text.scene-files : Source code for "Almost Sphere Spirals" Server Time
1 Jul 2024 03:13:10 EDT (-0400)
  Source code for "Almost Sphere Spirals" (Message 1 to 3 of 3)  
From: Tor Olav Kristensen
Subject: Source code for "Almost Sphere Spirals"
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

From: R  Suzuki
Subject: Re: Source code for "Almost Sphere Spirals"
Date: 28 Jan 2002 04:25:12
Message: <3c5518f8@news.povray.org>
"Tor Olav Kristensen"  wrote in message
>At 24. January 2002 I posted an image to povray.binaries.images.
>Below is the source for it.

Thanks.  That is interesting. 

>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. 

I see.  I've encountered the same problem in the carpet project.  
That is due to 'mod' function.  The first parameter of 'mod' function 
should be positive in such cases.  
So, the below macro will work as expected.

R. Suzuki

------------------------------
#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) +TwoPi,
        DivAngle
      ) - GapAngle,

      select(
        mod(
          atan2(z, x) - PhiFn(x, y, z) +
          select(atan2(z, x) - PhiFn(x, y, z), TwoPi, 0) +TwoPi,
          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) +TwoPi,
              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) +TwoPi,
              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) +TwoPi,
              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) +TwoPi,
              DivAngle
            ) + GapAngle
          ),

          Rmin
        )
      ),

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

#end // macro SphereSpiralsFunction


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Source code for "Almost Sphere Spirals"
Date: 29 Jan 2002 19:15:35
Message: <3C573A68.1141192F@hotmail.com>
"R. Suzuki" wrote:
> 
> "Tor Olav Kristensen"  wrote in message
> >At 24. January 2002 I posted an image to povray.binaries.images.
> >Below is the source for it.
> 
> Thanks.  That is interesting.
> 
> >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.
> 
> I see.  I've encountered the same problem in the carpet project.
> That is due to 'mod' function.  The first parameter of 'mod' function
> should be positive in such cases.
> So, the below macro will work as expected.

Thank you Ryoichi.

I have now done some quick tests on my
(much faster) PC at work.

And it seems that your suggestion to add
2*pi after some of my select() expressions
did fix the problem.

So, does this mean that the mod() function
is not working as it should ?

(Or were my math-expressions wrong ?)

Anyway, I think that I will experiment
more to see if I can get totally rid of
those 6 select() expressions.


Tor Olav


Post a reply to this message

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