POV-Ray : Newsgroups : povray.general : 2D function to 3D tube : Re: 2D function to 3D tube Server Time
3 Feb 2023 23:45:52 EST (-0500)
  Re: 2D function to 3D tube  
From: Tor Olav Kristensen
Date: 29 Dec 2022 10:45:00
Message: <web.63adb5ba560d6168f0247f8189db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> > I ran all these through the SimpleMesh macro. See the attached image for
> > the results. I can post the complete source for that if you're interested.
>
> Yes, that would be interesting to look over.
> ...

Here's the code:

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

#version 3.7;

global_settings { assumed_gamma 1.0 }

#include "functions.inc"  // For f_r()
#include "colors.inc"

#declare TAU = 2*pi;

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

#macro SimpleMesh(FnX, FnY, FnZ, MinU, MaxU, MinV, MaxV, SizeI, SizeJ)

    #local LastI = SizeI - 1;
    #local LastJ = SizeJ - 1;
    #local Vertices = array[SizeI][SizeJ];
    #local SpanU = MaxU - MinU;
    #local SpanV = MaxV - MinV;
    #for (I, 0, LastI)
        #local U = MinU + I/LastI*SpanU;
        #for (J, 0, LastJ)
            #local V = MinV + J/LastJ*SpanV;
            #local Vertices[I][J] =
                <FnX(U, V), FnY(U, V), FnZ(U, V)>
            ;
        #end // for
    #end // for

    mesh {
        #for (I, 0, LastI - 1)
            #for (J, 0, LastJ - 1)
                #local p00 = Vertices[I  ][J  ];
                #local p01 = Vertices[I  ][J+1];
                #local p10 = Vertices[I+1][J  ];
                #local p11 = Vertices[I+1][J+1];
                triangle { p00, p10, p11 }
                triangle { p11, p01, p00 }
            #end // for
        #end // for
    }

#end // macro SimpleMesh

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

#declare FnX = function(u) { u };
#declare DFnX = function(u) { 1 };

#declare Fn_Y = array[5];
#declare DFn_Y = array[5];

#declare I = 0;
#declare Fn_Y[I] = function(u) { pow(u, 2) + 1 };
#declare DFn_Y[I] = function(u) { 2*u };

#declare I = I + 1;
#declare Fn_Y[I] = function(u) { 0.4*cos(u)*(-pow(u, 2) + 3) - 1 };
#declare DFn_Y[I] = function(u) { 0.4*(pow(u, 2) - 3)*sin(u) - 0.8*u*cos(u) };

#declare I = I + 1;
#declare Fn_Y[I] = function(u) { u*u*u };
#declare DFn_Y[I] = function(u) { 3*u*u };

#declare I = I + 1;
#declare Fn_Y[I] = function(u) { 4*sinh(u)/cosh(u) + 4 };
#declare DFn_Y[I] = function(u) { 16*pow(cosh(u), 2)/pow(cosh(2*u) + 1, 2) };

#declare I = I + 1;
#declare Fn_Y[I] = function(u) { 8*u/(abs(u) + 1) };
#declare DFn_Y[I] = function(u) { 8/pow(abs(u) + 1, 2) };

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

#declare Nil = 1e-3;

#declare R = 0.15;

#declare Colors =
    array[5] {
        color Red,
        color Green,
        color Blue,
        // color Cyan,
        color Magenta,
        color Yellow
    }
;

#for (I, 0, 4)
    #declare FnY = Fn_Y[I];
    #declare DFnY = DFn_Y[I];
    // Normalized component functions for tangent vector
    #declare N_DFnX =
        function(u) {
            DFnX(u)/f_r(DFnX(u), DFnY(u), 0)
        }
    ;
    #declare N_DFnY =
        function(u) {
            DFnY(u)/f_r(DFnX(u), DFnY(u), 0)
        }
    ;
    object {
        SimpleMesh(
            function(u, v) { -R*cos(v)*N_DFnY(u) + FnX(u) },  // FnX
            function(u, v) { +R*cos(v)*N_DFnX(u) + FnY(u) },  // FnY
            function(u, v) {  R*sin(v) }, // FnZ
            -20, +20,  // MinU, MaxU,
            0 + Nil, TAU - Nil,  // MinV, MaxV
            800 + 1, 26 + 1  // SizeI, Size J
        )
        pigment { color Gray50 + Colors[I] }
    }
    #undef FnY
    #undef DFnY
    #undef N_DFnX
    #undef N_DFnY
#end // for

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

background { color rgb <0.04, 0.02, 0.06> }

light_source {
    -150*z
    color White
    shadowless
}

#declare AR = image_width/image_height;

camera {
   orthographic
   location -85*z + 0.5*y
   direction z
   right AR*x
   up y
   sky y
   angle 15
}

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

(Note that the colors are more saturated than in the image I posted.)

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

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