// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 /* "Mesh Torus" for POV-Ray by Tor Olav Kristensen 2024-12-29 http://subcube.com, https://github.com/t-o-k Based on work for MathMod by Abderrahman Taha and for POV-Ray by kurtz le pirate */ // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 #version 3.7; #include "colors.inc" #include "functions.inc" global_settings { assumed_gamma 1.80 max_trace_level 5 } default { finish { ambient 0.00 emission 0.40 diffuse 0.60 } } // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 #declare Major_Radius = 7.0; #declare Minor_Radius = 4.0; #declare Major_NoOfBands = 12; #declare Minor_NoOfBands = 36; #declare BandSize = 0.08; #declare Major_W = 0.7; #declare Minor_W = 1.3; #declare Amplitude = 0.2; #declare Roundness = 0.5; #declare MaxGradient = 2.0; // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 #declare tau = 2*pi; #declare ModFn = function(a, b) { select(a, b - mod(-a, b), mod(+a, b)) }; #declare Major_HNB = Major_NoOfBands/2; #declare Minor_HNB = Minor_NoOfBands/2; #declare Major_Interval = tau/Major_NoOfBands; #declare Minor_Interval = tau/Minor_NoOfBands; #declare Major_AngleFn = function(a) { (a + select(a, +Major_Interval, -Major_Interval))*Major_W } ; #declare Minor_AngleFn = function(a) { (a + select(a, +Minor_Interval, -Minor_Interval))*Minor_W } ; #declare Major_BandFn = function(a_maj, a_min, r_min) { f_sphere( Major_AngleFn(ModFn(a_min, 2*Major_Interval) - Major_Interval), (r_min + Amplitude*cos(a_maj*Minor_HNB))*Roundness, 0, BandSize ) } ; #declare Minor_BandFn = function(a_maj, a_min, r_min) { f_sphere( Minor_AngleFn(ModFn(a_maj, 2*Minor_Interval) - Minor_Interval), (r_min - Amplitude*cos(a_min*Major_HNB))*Roundness, 0, BandSize ) } ; #declare Major_PrecalcFn2A = function(r_maj, y, a_maj) { Major_BandFn( a_maj, atan2(y, r_maj) + Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Minor_Radius) // r_min ) } ; #declare Major_PrecalcFn2B = function(r_maj, y, a_maj) { Major_BandFn( a_maj, atan2(y, r_maj) - Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Minor_Radius) // r_min ) } ; #declare Minor_PrecalcFn2A = function(r_maj, y, a_maj) { Minor_BandFn( a_maj, atan2(y, r_maj) + Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Minor_Radius) // r_min ) } ; #declare Minor_PrecalcFn2B = function(r_maj, y, a_maj) { Minor_BandFn( a_maj, atan2(y, r_maj) - Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Minor_Radius) // r_min ) } ; #declare Major_PrecalcFn1A = function { Major_PrecalcFn2A( f_sphere(x, 0, z, Major_Radius), // r_maj y, atan2(z, x) + Minor_Interval/2 // a_maj ) } ; #declare Major_PrecalcFn1B = function { Major_PrecalcFn2B( f_sphere(x, 0, z, Major_Radius), // r_maj y, atan2(z, x) - Minor_Interval/2 // a_maj ) } ; #declare Minor_PrecalcFn1A = function { Minor_PrecalcFn2A( f_sphere(x, 0, z, Major_Radius), // r_maj y, atan2(z, x) + Minor_Interval/2 // a_maj ) } ; #declare Minor_PrecalcFn1B = function { Minor_PrecalcFn2B( f_sphere(x, 0, z, Major_Radius), // r_maj y, atan2(z, x) - Minor_Interval/2 // a_maj ) } ; #declare vSize = Major_Radius*<1, 0, 1> + Minor_Radius*<1, 1, 1>; #declare vSize = vSize + <1.0, 1.0, 1.0>; #declare Major_BandsA = isosurface { function { Major_PrecalcFn1A(x, y, z) } max_gradient MaxGradient contained_by { box { -vSize, +vSize } } } #declare Major_BandsB = isosurface { function { Major_PrecalcFn1B(x, y, z) } max_gradient MaxGradient contained_by { box { -vSize, +vSize } } } #declare Minor_BandsA = isosurface { function { Minor_PrecalcFn1A(x, y, z) } max_gradient MaxGradient contained_by { box { -vSize, +vSize } } } #declare Minor_BandsB = isosurface { function { Minor_PrecalcFn1B(x, y, z) } max_gradient MaxGradient contained_by { box { -vSize, +vSize } } } // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 #declare Pigment_Major_Radius = Major_Radius; #declare Pigment_Minor_Radius = Minor_Radius; #declare Pigment_Major_NoOfBands = Major_NoOfBands; #declare Pigment_Minor_NoOfBands = Minor_NoOfBands; // #declare Pigment_BandSize = BandSize; #declare Pigment_BandSize = 0.05; #declare Pigment_Major_W = Major_W; #declare Pigment_Minor_W = Minor_W; #declare Pigment_Amplitude = Amplitude; // #declare Pigment_Roundness = Roundness; #declare Pigment_Roundness = 0.2; #declare Pigment_MaxGradient = MaxGradient; // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 #declare Pigment_Major_HNB = Pigment_Major_NoOfBands/2; #declare Pigment_Minor_HNB = Pigment_Minor_NoOfBands/2; #declare Pigment_Major_Interval = tau/Pigment_Major_NoOfBands; #declare Pigment_Minor_Interval = tau/Pigment_Minor_NoOfBands; #declare Pigment_Major_AngleFn = function(a) { (a + select(a, +Pigment_Major_Interval, -Pigment_Major_Interval))*Pigment_Major_W } ; #declare Pigment_Minor_AngleFn = function(a) { (a + select(a, +Pigment_Minor_Interval, -Pigment_Minor_Interval))*Pigment_Minor_W } ; #declare Pigment_Major_BandFn = function(a_maj, a_min, r_min) { f_sphere( Pigment_Major_AngleFn(ModFn(a_min, 2*Pigment_Major_Interval) - Pigment_Major_Interval), (r_min + Pigment_Amplitude*cos(a_maj*Pigment_Minor_HNB))*Pigment_Roundness, 0, Pigment_BandSize ) } ; #declare Pigment_Minor_BandFn = function(a_maj, a_min, r_min) { f_sphere( Pigment_Minor_AngleFn(ModFn(a_maj, 2*Pigment_Minor_Interval) - Pigment_Minor_Interval), (r_min - Pigment_Amplitude*cos(a_min*Pigment_Major_HNB))*Pigment_Roundness, 0, Pigment_BandSize ) } ; #declare Pigment_Major_PrecalcFn2A = function(r_maj, y, a_maj) { Pigment_Major_BandFn( a_maj, atan2(y, r_maj) + Pigment_Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Pigment_Minor_Radius) // r_min ) } ; #declare Pigment_Major_PrecalcFn2B = function(r_maj, y, a_maj) { Pigment_Major_BandFn( a_maj, atan2(y, r_maj) - Pigment_Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Pigment_Minor_Radius) // r_min ) } ; #declare Pigment_Minor_PrecalcFn2A = function(r_maj, y, a_maj) { Pigment_Minor_BandFn( a_maj, atan2(y, r_maj) + Pigment_Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Pigment_Minor_Radius) // r_min ) } ; #declare Pigment_Minor_PrecalcFn2B = function(r_maj, y, a_maj) { Pigment_Minor_BandFn( a_maj, atan2(y, r_maj) - Pigment_Major_Interval/2, // a_min f_sphere(r_maj, y, 0, Pigment_Minor_Radius) // r_min ) } ; #declare Pigment_Major_PrecalcFn1A = function { Pigment_Major_PrecalcFn2A( f_sphere(x, 0, z, Pigment_Major_Radius), // r_maj y, atan2(z, x) + Pigment_Minor_Interval/2 // a_maj ) } ; #declare Pigment_Major_PrecalcFn1B = function { Pigment_Major_PrecalcFn2B( f_sphere(x, 0, z, Pigment_Major_Radius), // r_maj y, atan2(z, x) - Pigment_Minor_Interval/2 // a_maj ) } ; #declare Pigment_Minor_PrecalcFn1A = function { Pigment_Minor_PrecalcFn2A( f_sphere(x, 0, z, Pigment_Major_Radius), // r_maj y, atan2(z, x) + Pigment_Minor_Interval/2 // a_maj ) } ; #declare Pigment_Minor_PrecalcFn1B = function { Pigment_Minor_PrecalcFn2B( f_sphere(x, 0, z, Pigment_Major_Radius), // r_maj y, atan2(z, x) - Pigment_Minor_Interval/2 // a_maj ) } ; #declare PailleB = color rgb <0.971878, 0.967498, 0.788232>; #declare Major_ColorMap = color_map { [ 0.50 color rgb <0.4, 0.0, 0.6> ] [ 0.50 color rgb <1.0, 1.0, 1.0> ] } #declare Minor_ColorMap = color_map { [ 0.50 color rgb <1.0, 1.0, 1.0> ] [ 0.50 color rgb <0.1, 0.1, 0.5> ] } union { object { Major_BandsA pigment { function { Pigment_Major_PrecalcFn1A(x, y, z) + 0.50 } color_map { Major_ColorMap } } } object { Major_BandsB pigment { function { Pigment_Major_PrecalcFn1B(x, y, z) + 0.50 } color_map { Major_ColorMap } } } object { Minor_BandsA pigment { function { Pigment_Minor_PrecalcFn1A(x, y, z) + 0.50 } // 0.51 color_map { Minor_ColorMap } } } object { Minor_BandsB pigment { function { Pigment_Minor_PrecalcFn1B(x, y, z) + 0.50 } // 0.51 color_map { Minor_ColorMap } } } rotate -50*z rotate -10*y } // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 sky_sphere { pigment { function { abs(y) } color_map { [ 0.0 color 0.50*SlateBlue ] [ 1.0 color 1.25*White ] } } } #declare AR = image_width/image_height; camera { location <29, 14, 24> right AR*x look_at <0.0, -0.6, 0.0> angle 44 } light_source { <75, 50, 44> color White // shadowless } // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 /* // To visualize where the pigment functions change sign #declare vPigment_Size = Pigment_Major_Radius*<1, 0, 1> + Pigment_Minor_Radius*<1, 1, 1>; #declare vPigment_Size = vPigment_Size + <1.0, 1.0, 1.0>; #declare Pigment_MajorBandsA = isosurface { function { Pigment_Major_PrecalcFn1A(x, y, z) } max_gradient Pigment_MaxGradient contained_by { box { -vPigment_Size, +vPigment_Size } } } #declare Pigment_MajorBandsB = isosurface { function { Pigment_Major_PrecalcFn1B(x, y, z) } max_gradient Pigment_MaxGradient contained_by { box { -vPigment_Size, +vPigment_Size } } } #declare Pigment_MinorBandsA = isosurface { function { Pigment_Minor_PrecalcFn1A(x, y, z) } max_gradient Pigment_MaxGradient contained_by { box { -vPigment_Size, +vPigment_Size } } } #declare Pigment_MinorBandsB = isosurface { function { Pigment_Minor_PrecalcFn1B(x, y, z) } max_gradient Pigment_MaxGradient contained_by { box { -vPigment_Size, +vPigment_Size } } } union { object { Pigment_MajorBandsA pigment { White/2 + Magenta/2 } } object { Pigment_MajorBandsB pigment { White/2 + Blue/2 } } object { Pigment_MinorBandsA pigment { White/2 + Green/2 } } object { Pigment_MinorBandsB pigment { White/2 + Cyan/2 } } rotate -50*z rotate -10*y } */ // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10