POV-Ray : Newsgroups : povray.general : 2D function to 3D tube Server Time
6 May 2024 02:33:38 EDT (-0400)
  2D function to 3D tube (Message 31 to 34 of 34)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Tor Olav Kristensen
Subject: Re: 2D function to 3D tube
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

From: Droj
Subject: Re: 2D function to 3D tube
Date: 6 Jan 2023 12:05:00
Message: <web.63b85430560d616820e7fc03b2af915@news.povray.org>
"Droj" <803### [at] drojde> wrote:
> I was interested to see how can a 2D curve get a more interesting life in a 3D
> world.
> And I found a promising approach in the Internet on B. Frassek's website
> https://www.frassek.org (sorry, the site is in German but an automatic
> translation is available). Look for 'function graph as pipe/tube'.
> The steps are outlined here:
>
>  - take the parametric function of a circle as cross section for the tube
>  - determin the gradient of the 2D curve you want to use (derivatives must
> exist)
>  - let the center of the cross section travel along the 2D curve (e.g. like
> insulation on a copper wire)
>
> Alas, that's it.
>
> So I started to adapt all the functions to Povray. I am aware that using atan2
> is an unexplicable mystery but what the heck.
>
> The result was sort of sobering as the tube was flatend in some parts and bulgy
> in others.
> I upload the POV-Script I generated to show the problem.
>
> Any suggestions (if there are any) on how to get a perfectly round tube are
> welcome but I need the parametric approach as I want to use the .inc/.obj output
> for more things to come.

Hi to all,

I guess this subject is rather exhausted.

Don't take me wrong I have the highest esteem for those who developed the
meshmaker macros and I am not happy to be the igorant, bloody user finding the
fly in the ointment - provided there is any as there is no proof.

Be assured the meshmaker macros work flawlessly with a heap of parametric
functions I tested.

My thanks to all who took part in this fruitful discussion and for actively
sharing their knowledge.

For the time being I will use Bill's solution to test some more curves and
produce interesting tubes including the .obj/.inc files.

And finally here's something I made in a jiffy - no great artistic work I admit.


Post a reply to this message

From: Droj
Subject: Re: 2D function to 3D tube
Date: 6 Jan 2023 12:30:00
Message: <web.63b85996560d616820e7fc03b2af915@news.povray.org>
"Droj" <803### [at] drojde> wrote:
> "Droj" <803### [at] drojde> wrote:
> > I was interested to see how can a 2D curve get a more interesting life in a 3D
> > world.
> > And I found a promising approach in the Internet on B. Frassek's website
> > https://www.frassek.org (sorry, the site is in German but an automatic
> > translation is available). Look for 'function graph as pipe/tube'.
> > The steps are outlined here:
> >
> >  - take the parametric function of a circle as cross section for the tube
> >  - determin the gradient of the 2D curve you want to use (derivatives must
> > exist)
> >  - let the center of the cross section travel along the 2D curve (e.g. like
> > insulation on a copper wire)
> >
> > Alas, that's it.
> >
> > So I started to adapt all the functions to Povray. I am aware that using atan2
> > is an unexplicable mystery but what the heck.
> >
> > The result was sort of sobering as the tube was flatend in some parts and bulgy
> > in others.
> > I upload the POV-Script I generated to show the problem.
> >
> > Any suggestions (if there are any) on how to get a perfectly round tube are
> > welcome but I need the parametric approach as I want to use the .inc/.obj output
> > for more things to come.
>
> Hi to all,
>
> I guess this subject is rather exhausted.
>
> Don't take me wrong I have the highest esteem for those who developed the
> meshmaker macros and I am not happy to be the igorant, bloody user finding the
> fly in the ointment - provided there is any as there is no proof.
>
> Be assured the meshmaker macros work flawlessly with a heap of parametric
> functions I tested.
>
> My thanks to all who took part in this fruitful discussion and for actively
> sharing their knowledge.
>
> For the time being I will use Bill's solution to test some more curves and
> produce interesting tubes including the .obj/.inc files.
>
> And finally here's something I made in a jiffy - no great artistic work I admit.

Ooops, image is missing


Post a reply to this message


Attachments:
Download 't_heartcurve_00b.png' (262 KB)

Preview of image 't_heartcurve_00b.png'
t_heartcurve_00b.png


 

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 10 Aug 2023 20:10:00
Message: <web.64d57bcb560d61681f9dae3025979125@news.povray.org>
FYI follow-up.

So I was checking out Sam Benge's  code for outlining an object, and was
wondering if he could use f_th, f_ph, and f_r, and wouldn't you know it -
POV-Ray has an inbuilt function for making "tubes" from polynomials:
f_polytubes.  The threshold of the isosurface functions as the thickness
parameter for the tubes.

I'd say that in future versions, the function needs to be updated, a note
provided in the documentation about the non-circularity of the "tube", or some
other improvement to the general state of affairs.

- BW


Post a reply to this message


Attachments:
Download 'polytubes.pov.txt' (2 KB)

<<< Previous 10 Messages Goto Initial 10 Messages

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