POV-Ray : Newsgroups : povray.general : Sphere with longitudes and latitudes? : Re: Sphere with longitudes and latitudes? Server Time
31 Jul 2024 10:25:46 EDT (-0400)
  Re: Sphere with longitudes and latitudes?  
From: Trevor G Quayle
Date: 8 Jan 2008 23:00:00
Message: <web.47844606a8d0eaa2ae8612c0@news.povray.org>
Again, this time I've cored out the gridlines where not needed.  This partly
removes the thick line down the center, but not completely depending on the
settings.

-tgq


//START

camera {
  location  <5,10,-10>
  right     x*image_width/image_height
  look_at   <0.0, 0.0,  0.0>
  angle 12
}

light_source {
  <30, 50, -40>
  rgb <1, 1, 1>
}

plane {
  y, -1
  pigment {rgb 1}
}

//HSL to RGB
#declare tHSL=function(H,C){(H/360+C/3)-floor(H/360+C/3)}
#declare qHSL=function(H,S,L){select(L-1/2,L*(1+S),L+S-L*S)}
#declare pHSL=function(H,S,L){2*L-qHSL(H,S,L)}
#declare CHSL=function(H,S,L,C)
{
  select(
    -S
  ,//S>0
    select(
      tHSL(H,C)-1/6
    ,//tc<1/6
      pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*tHSL(H,C)
    ,
      select(
        tHSL(H,C)-1/2
      ,//tc<1/2
        qHSL(H,S,L)
      ,
        select(
          tHSL(H,C)-2/3
        ,//tc<2/3
          pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*(2/3-tHSL(H,C))
        ,//esle
          pHSL(H,S,L)
        )
      )
    )
  ,//S=0
    L
  )
}
#declare RHSL=function (H,S,L){CHSL(H,S,L,+1)}
#declare GHSL=function (H,S,L){CHSL(H,S,L, 0)}
#declare BHSL=function (H,S,L){CHSL(H,S,L,-1)}
//END HSL to RGB


#declare LatDiv=6;    //Number of Latitude divisions, used for long too
(degrees= 90/LatDiv)
#declare GRDTHK=0.01;  //Line thickness for 1 unit radius sphere

#declare FX=function(x){360/(LatDiv*4)*int(x*LatDiv*4+0.5)}
#declare FY=function(y){int(y*LatDiv*2+0.5)/(LatDiv*2)}
#declare FZ=function(y){int(y*LatDiv+0.5)/LatDiv}

#declare FR= function(x,y,z){RHSL(FX(x),FZ(z),FY(y))}
#declare FG= function(x,y,z){GHSL(FX(x),FZ(z),FY(y))}
#declare FB= function(x,y,z){BHSL(FX(x),FZ(z),FY(y))}

#declare HSL=
pigment{
  average
  pigment_map{
    [function{   FR(x,y,z)   } color_map{[0 rgb 0][1 rgb <3,0,0>]}]
    [function{   FG(x,y,z)   } color_map{[0 rgb 0][1 rgb <0,3,0>]}]
    [function{   FB(x,y,z)   } color_map{[0 rgb 0][1 rgb <0,0,3>]}]
  }
  warp{spherical}
}

#declare AA=sin(GRDTHK/2);//GRDTHK*LatDiv/2/(pi*2/4);
#declare ABC=pigment{rgb 1}

#declare LAT=
union{
  #local i=+90/LatDiv/2;#while(i<90)
    difference{
      cone{0,0,2*y,tan(radians(i))*2 translate -y/sin(radians(i))*AA}
      cone{0,0,2*y,tan(radians(i))*2 translate y/sin(radians(i))*AA}
    }
    difference{
      cone{0,0,-2*y,tan(radians(i))*2 translate y/sin(radians(i))*AA}
      cone{0,0,-2*y,tan(radians(i))*2 translate -y/sin(radians(i))*AA}
    }
  #local i=i+90/(LatDiv);#end
}

#declare LONG=
difference{
  union{
    #local i=+90/LatDiv/2;#while(i<180)
      cylinder{-z*sin(GRDTHK/2),z*sin(GRDTHK/2),1.1 rotate y*i}
    #local i=i+90/(LatDiv);#end
  }
  sphere{0,1/LatDiv/2}
  cone{0,0,2*y,tan(radians(90/LatDiv/2))*2}
  cone{0,0,-2*y,tan(radians(90/LatDiv/2))*2}
}

#declare LAY=
  union{
    cone{0,0,2*y,tan(radians(90/LatDiv/2))*2}
    cone{0,0,-2*y,tan(radians(90/LatDiv/2))*2}
   scale LatDiv
  }

#declare PLay=
pigment{
  object{
    LAY
    pigment{rgb 0}
    pigment{rgb 1}
  }
}

#declare PLat=
pigment{
  object{
    LAT
    pigment{onion scale 1/LatDiv
      pigment_map{
        [0.5-AA*LatDiv HSL scale LatDiv]
        [0.5-AA*LatDiv PLay]
        [0.5+AA*LatDiv PLay]
        [0.5+AA*LatDiv HSL scale LatDiv]
      }
    }
    pigment{rgb 0}
  }
}

#declare PGrid=
pigment{
  object{
    LONG
    pigment{PLat}
    pigment{rgb 0}
  }
}

difference{
  sphere{0,1}
  box{0,<1,1,-1>}
  pigment{PGrid}
  finish{ambient 0 diffuse 0.5}
}

//END


Post a reply to this message

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