// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 /* "Mesh Torus" written for MathMod by Abderrahman Taha 2019-11-02 Rewritten for POV-Ray by kurtz le pirate 2024-12-24, lb Simplified, debugged, optimized and reformatted by Tor Olav Kristensen 2024-12-29 */ // ===== 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; // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10 #declare tau = 2*pi; #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 ModFn = function(a, b) { select(a, b - mod(-a, b), mod(+a, b)) }; #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>; isosurface { function { min( Major_PrecalcFn1A(x, y, z), Major_PrecalcFn1B(x, y, z), Minor_PrecalcFn1A(x, y, z), Minor_PrecalcFn1B(x, y, z) ) } max_gradient 2 contained_by { box { -vSize, +vSize } } pigment { color rgb <0.971878, 0.967498, 0.788232> } // Paille 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 ] } } } light_source { <75, 50, 44> color White // shadowless } #declare AR = image_width/image_height; camera { location <29, 14, 24> right AR*x look_at <0.0, -0.6, 0.0> angle 44 } // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 ======= 8 ======= 9 ======= 10