POV-Ray : Newsgroups : povray.text.scene-files : Source code for "Sheared supertori" image Server Time
25 May 2024 08:07:09 EDT (-0400)
  Source code for "Sheared supertori" image (Message 1 to 2 of 2)  
From: Tor Olav Kristensen
Subject: Source code for "Sheared supertori" image
Date: 23 Jan 2010 23:54:58
Message: <4b5bd2a2@news.povray.org>
Below is the source code for the image I posted here:

http://news.povray.org/povray.binaries.images/message/<4b5a4460%40news.povray.org>
Newsgroup: povray.binaries.images
Date: 23rd January 2010
Subject: Sheared supertori   	

Tor Olav

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2010 by Tor Olav Kristensen, except for the textures
// Email: t o r . o l a v . k [_A_T_] g m a i l . c o m
// http://subcube.com
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#include "colors.inc"
#include "rad_def.inc"
#include "shapes.inc" // For Supertorus() macro
//#include "transforms.inc" // For Shear_Trans() macro

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

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

#macro ShearTrans(vA, vB, vC)

   #if (vdot(vA, vcross(vB, vC)) = 0)
     #error "Bad vectors passed to ShearTrans macro"
   #else
     transform {
       matrix <
         vA.x, vA.y, vA.z,
         vB.x, vB.y, vB.z,
         vC.x, vC.y, vC.z,
            0,    0,    0
       >
     }
   #end // if

#end // macro ShearTrans

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

// Modified versions of a texture once made by Gilles Tran
// His website is here: http://www.oyonale.com

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

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

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

#declare Rmaj = 4.0;
#declare Rmin = 1.0;

#declare Cmaj = 1/2;
#declare Cmin = 1/2;

#declare Acc = 1e-3;
#declare MaxGrad = 1.0;

#declare S_Torus = Supertorus(Rmaj, Rmin, Cmaj, Cmin, Acc, MaxGrad)

#declare S = 1.0; // Amount of shearing

#declare Rbig = Rmaj + Rmin;

#declare T = 2*Rbig;
#declare D = 3*Rbig;


#declare ZZ =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       < 0, +1,  0>,
       < 0,  0, +1>
     )
     translate < 0,  0,  0>
   }

#declare PZ =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       <+S, +1,  0>,
       < 0,  0, +1>
     )
     translate <+T,  0,  0>
   }

#declare MZ =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       <-S, +1,  0>,
       < 0,  0, +1>
     )
     translate <-T,  0,  0>
   }

#declare ZP =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       < 0, +1, +S>,
       < 0,  0, +1>
     )
     translate < 0,  0, +T>
   }

#declare ZM =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       < 0, +1, -S>,
       < 0,  0, +1>
     )
     translate < 0,  0, -T>
   }

#declare PP =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       <+S, +1, +S>,
       < 0,  0, +1>
     )
     translate <+T,  0, +T>
   }

#declare MP =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       <-S, +1, +S>,
       < 0,  0, +1>
     )
     translate <-T,  0, +T>
   }

#declare MM =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       <-S, +1, -S>,
       < 0,  0, +1>
     )
     translate <-T,  0, -T>
   }

#declare PM =
   object {
     S_Torus
     ShearTrans(
       <+1,  0,  0>,
       <+S, +1, -S>,
       < 0,  0, +1>
     )
     translate <+T,  0, -T>
   }


#declare Wall1 =
   union {
     object { ZZ }
     object { PZ }
     object { MZ }
     object { ZP }
     object { ZM }
     object { PP }
     object { MP }
     object { MM }
     object { PM }
   }

#declare Wall2 =
   union {
//    object { ZZ }
     object { PZ }
     object { MZ }
     object { ZP }
     object { ZM }
     object { PP }
     object { MP }
     object { MM }
     object { PM }
   }


union {
// PosY
   object {
     Wall1
     rotate 0*z
     translate +D*y
   }
// NegY
   object {
     Wall1
     rotate 180*z
     translate -D*y
   }
// NegX
   object {
     Wall1
     rotate +90*z
     translate -D*x
   }
// PosX
   object {
     Wall2
     rotate -90*z
     translate +D*x
   }
// NegZ
   object {
     Wall1
     rotate -90*x
     translate -D*z
   }
// PosZ
   object {
     Wall1
     rotate +90*x
     translate +D*z
   }
   texture { Gilles_Tex_Mod1 }
//  pigment { color White }
}


object {
   ZZ
   texture { Gilles_Tex_Mod1 }
//  pigment { color White }
   rotate 30*y
   translate (T + D)*x
   translate -D*y
}


plane {
   y, -(D + S)
   texture { Gilles_Tex_Mod2 }
//  pigment { color White }
}

// ===== 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 {
   <4, 3, 4>*30
   color rgb <0.76, 0.62, 0.34>
   area_light
   2*x, 2*z,
   4, 4
   circular
   orient
   adaptive 1
   jitter
}

/*
light_source {
   <4, 3, 4>*30
   color White
//  shadowless
}
*/

camera {
   location <5, 4, -6>*10
   look_at <-8, 0, -8>
   angle 70
}

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


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Source code for "Sheared supertori" image
Date: 24 Jan 2010 00:04:20
Message: <4b5bd4d4@news.povray.org>
Tor Olav Kristensen wrote:
> 
> Below is the source code for the image I posted here:
> 
> http://news.povray.org/povray.binaries.images/message/<4b5a4460%40news.povray.org> 
> 
> Newsgroup: povray.binaries.images
> Date: 23rd January 2010
> Subject: Sheared supertori      

And here is some alternative source code that will produce the same
(or a very similar) image.

In this version matrices are used to do all the shears, reorientations
and translations.

Tor Olav

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2010 by Tor Olav Kristensen, except for the textures
// Email: t o r . o l a v . k [_A_T_] g m a i l . c o m
// http://subcube.com
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#include "colors.inc"
#include "rad_def.inc"
//#include "shapes.inc" // For Supertorus() macro
//#include "transforms.inc" // For Matrix_Trans() macro

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

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

#macro SuperTorusFunction(RadMaj, RadMin, CtrlMaj, CtrlMin)

   #local SuperCylFn =
     function(_a, _b, _r, _p) {
       pow(pow(abs(_a), _p) + pow(abs(_b), _p), 1/_p) - _r
     }
   #local PwrMin = 2/CtrlMin;
   #local PwrMaj = 2/CtrlMaj;

   function {
     SuperCylFn(SuperCylFn(x, z, RadMaj, PwrMaj), y, RadMin, PwrMin)
   }

#end // macro SuperTorusFunction


#macro SuperTorus(RadMaj, RadMin, CtrlMaj, CtrlMin, Accuracy, MaxGradient)

   #local RadBig = RadMaj + RadMin;

   isosurface {
     SuperTorusFunction(RadMaj, RadMin, CtrlMaj, CtrlMin)
     threshold 0
     contained_by {
       box {
         -<RadBig, RadMin, RadBig>,
         +<RadBig, RadMin, RadBig>
       }
     }
     max_gradient MaxGradient
     accuracy Accuracy
   }

#end // macro SuperTorus


#macro MatrixTrans(vA, vB, vC, vD)

   #if (vdot(vA, vcross(vB, vC)) = 0)
     #error "Bad vectors passed to MatrixTrans macro"
   #else
     transform {
       matrix <
         vA.x, vA.y, vA.z,
         vB.x, vB.y, vB.z,
         vC.x, vC.y, vC.z,
         vD.x, vD.y, vD.z
       >
     }
   #end // if

#end // macro MatrixTrans

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

// Modified versions of a texture once made by Gilles Tran
// His website is here: http://www.oyonale.com

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

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

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

#declare Rmaj = 4.0;
#declare Rmin = 1.0;

#declare Cmaj = 1/2;
#declare Cmin = 1/2;

#declare Acc = 1e-3;
#declare MaxGrad = 1.0;

#declare S_Torus = SuperTorus(Rmaj, Rmin, Cmaj, Cmin, Acc, MaxGrad)

#declare S = 1.0; // Amount of shearing

#declare Rbig = Rmaj + Rmin;

#declare T = 2*Rbig;
#declare D = 3*Rbig;


// rotate 0*z
#declare PosY =
union {
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, +1,  0>,
       < 0,  0, +1>,
       < 0, +D,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, +1,  0>,
       < 0,  0, +1>,
       <+T, +D,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, +1,  0>,
       < 0,  0, +1>,
       <-T, +D,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, +1, +S>,
       < 0,  0, +1>,
       < 0, +D, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, +1, -S>,
       < 0,  0, +1>,
       < 0, +D, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, +1, +S>,
       < 0,  0, +1>,
       <+T, +D, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, +1, +S>,
       < 0,  0, +1>,
       <-T, +D, +T>
     )
   }
object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, +1, -S>,
       < 0,  0, +1>,
       <-T, +D, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, +1, -S>,
       < 0,  0, +1>,
       <+T, +D, -T>
     )
   }
}


// rotate 180*z
#declare NegY =
union {
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       < 0, -1,  0>,
       < 0,  0, +1>,
       < 0, -D,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       <-S, -1,  0>,
       < 0,  0, +1>,
       <-T, -D,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       <+S, -1,  0>,
       < 0,  0, +1>,
       <+T, -D,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       < 0, -1, +S>,
       < 0,  0, +1>,
       < 0, -D, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       < 0, -1, -S>,
       < 0,  0, +1>,
       < 0, -D, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       <-S, -1, +S>,
       < 0,  0, +1>,
       <-T, -D, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       <+S, -1, +S>,
       < 0,  0, +1>,
       <+T, -D, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       <+S, -1, -S>,
       < 0,  0, +1>,
       <+T, -D, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <-1,  0,  0>,
       <-S, -1, -S>,
       < 0,  0, +1>,
       <-T, -D, -T>
     )
   }
}


// rotate 90*z
#declare NegX =
union {
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1,  0,  0>,
       < 0,  0, +1>,
       <-D,  0,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1, +S,  0>,
       < 0,  0, +1>,
       <-D, +T,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1, -S,  0>,
       < 0,  0, +1>,
       <-D, -T,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1,  0, +S>,
       < 0,  0, +1>,
       <-D,  0, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1,  0, -S>,
       < 0,  0, +1>,
       <-D,  0, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1, +S, +S>,
       < 0,  0, +1>,
       <-D, +T, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1, -S, +S>,
       < 0,  0, +1>,
       <-D, -T, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1, -S, -S>,
       < 0,  0, +1>,
       <-D, -T, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, +1,  0>,
       <-1, +S, -S>,
       < 0,  0, +1>,
       <-D, +T, -T>
     )
   }
}


// rotate -90*z
#declare PosX =
union {
/*
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1,  0,  0>,
       < 0,  0, +1>,
       <+D,  0,  0>
     )
   }
*/
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1, -S,  0>,
       < 0,  0, +1>,
       <+D, -T,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1, +S,  0>,
       < 0,  0, +1>,
       <+D, +T,  0>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1,  0, +S>,
       < 0,  0, +1>,
       <+D,  0, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1,  0, -S>,
       < 0,  0, +1>,
       <+D,  0, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1, -S, +S>,
       < 0,  0, +1>,
       <+D, -T, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1, +S, +S>,
       < 0,  0, +1>,
       <+D, +T, +T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1, +S, -S>,
       < 0,  0, +1>,
       <+D, +T, -T>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       < 0, -1,  0>,
       <+1, -S, -S>,
       < 0,  0, +1>,
       <+D, -T, -T>
     )
   }
}


// rotate -90*x
#declare NegZ =
union {
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0,  0, -1>,
       < 0, +1,  0>,
       < 0,  0, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S,  0, +1>,
       < 0, +1,  0>,
       <+T,  0, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S,  0, +1>,
       < 0, +1,  0>,
       <-T,  0, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, -S, +1>,
       < 0, +1,  0>,
       < 0, +T, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, +S, +1>,
       < 0, +1,  0>,
       < 0, -T, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, -S, +1>,
       < 0, +1,  0>,
       <+T, +T, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, -S, +1>,
       < 0, +1,  0>,
       <-T, +T, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, +S, +1>,
       < 0, +1,  0>,
       <-T, -T, -D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, +S, +1>,
       < 0, +1,  0>,
       <+T, -T, -D>
     )
   }
}


// rotate 90*x
#declare PosZ =
union {
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0,  0, +1>,
       < 0, -1,  0>,
       < 0,  0, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S,  0, +1>,
       < 0, -1,  0>,
       <+T,  0, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S,  0, +1>,
       < 0, -1,  0>,
       <-T,  0, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, -S, +1>,
       < 0, -1,  0>,
       < 0, -T, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       < 0, +S, +1>,
       < 0, -1,  0>,
       < 0, +T, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, -S, +1>,
       < 0, -1,  0>,
       <+T, -T, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, -S, +1>,
       < 0, -1,  0>,
       <-T, -T, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <-S, +S, +1>,
       < 0, -1,  0>,
       <-T, +T, +D>
     )
   }
   object {
     S_Torus
     MatrixTrans(
       <+1,  0,  0>,
       <+S, +S, +1>,
       < 0, -1,  0>,
       <+T, +T, +D>
     )
   }
}


union {
   object { NegX }
   object { PosX }
   object { NegY }
   object { PosY }
   object { NegZ }
   object { PosZ }
   texture { Gilles_Tex_Mod1 }
//  pigment { color White }
}


object {
   S_Torus
   texture { Gilles_Tex_Mod1 }
//  pigment { color White*0.7 }
   rotate 30*y
   translate (T + D)*x - D*y
}


plane {
   y, -16
   texture { Gilles_Tex_Mod2 }
//  pigment { color White }
}

// ===== 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 {
   <4, 3, 4>*30
   color rgb <0.76, 0.62, 0.34>
   area_light
   2*x, 2*z,
   4, 4
   circular
   orient
   adaptive 1
   jitter
}

/*
light_source {
   <4, 3, 4>*30
   color White
//  shadowless
}
*/

camera {
   location <5, 4, -6>*10
   look_at <-8, 0, -8>
   angle 70
}

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


Post a reply to this message

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