POV-Ray : Newsgroups : povray.general : 2D function to 3D tube Server Time
26 Dec 2024 12:51:41 EST (-0500)
  2D function to 3D tube (Message 1 to 10 of 34)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Droj
Subject: 2D function to 3D tube
Date: 20 Dec 2022 10:30:00
Message: <web.63a1d45ff7516b3060bf1aa93b2af915@news.povray.org>
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.


Post a reply to this message


Attachments:
Download 'tube_heartcurve.zip' (1 KB)

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 20 Dec 2022 13:45:00
Message: <web.63a20289560d61681f9dae3025979125@news.povray.org>
IIRC, Mike Williams addressed this very thing in his isosurface tutorial.

I can send you a copy - seeing all of the functions converted to POV-Ray scenes
would be great!   :)


- Bill

"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.


Post a reply to this message

From: ingo
Subject: Re: 2D function to 3D tube
Date: 20 Dec 2022 14:35:00
Message: <web.63a20e2e560d616817bac71e8ffb8ce3@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.

Very old but maybe usefull
https://news.povray.org/povray.binaries.utilities/thread/%3CXns94D4AF6BE46A0seed7%40news.povray.org%3E/?ttop=437912&tof
f=100

Then there are the meshmacro include files in the distribution.

Here I have the original macro's, they come with various examples:
https://ingoogni.nl/download/

ingo


Post a reply to this message

From: Droj
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 13:10:00
Message: <web.63a34b34560d61682844deea3b2af915@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.

The meshmaker.inc that comes with Povray 3.7 works definitely great.
To make it a bit clearer where the problem is see:

T_HeartCurve_00a1.png

The glitch is somewhere in my Povray script.

And I can't find out where.

Any ideas?


Post a reply to this message


Attachments:
Download 't_heartcurve_00a1.png' (134 KB)

Preview of image 't_heartcurve_00a1.png'
t_heartcurve_00a1.png


 

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 16:50:00
Message: <web.63a37f2f560d61681f9dae3025979125@news.povray.org>
"Droj" <803### [at] drojde> wrote:

> The meshmaker.inc that comes with Povray 3.7 works definitely great.
> To make it a bit clearer where the problem is see:
>
> T_HeartCurve_00a1.png
>
> The glitch is somewhere in my Povray script.
>
> And I can't find out where.
>
> Any ideas?

I usually kinda suck at this unless I've been doing it for some period of time.

I'm just gonna guess that you need to emulate the way a torus is described
parametrically.

Wolfram gives:

 (c-sqrt(x^2+y^2))^2+z^2=a^2,
(1)
and the parametric equations are

x = (c+acosv)cosu
(2)
y = (c+acosv)sinu
(3)
z = asinv

With c = major radius, a = minor radius, and probably swap y & z axes.

In the Isosurface Tutorial, Mike states that he has a scene that emulates a
sphere sweep and always makes the cross section perpendicular to the spline
axis.  So maybe you can find that file and see what he does.

I posted a zip of all the files here:
http://news.povray.org/povray.off-topic/message/%3C60a2d177%40news.povray.org%3E/#%3C60a2d177%40news.povray.org%3E


Post a reply to this message

From: Droj
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 18:20:00
Message: <web.63a39476560d61682844deea3b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Droj" <803### [at] drojde> wrote:
>
> > The meshmaker.inc that comes with Povray 3.7 works definitely great.
> > To make it a bit clearer where the problem is see:
> >
> > T_HeartCurve_00a1.png
> >
> > The glitch is somewhere in my Povray script.
> >
> > And I can't find out where.
> >
> > Any ideas?
>
> I usually kinda suck at this unless I've been doing it for some period of time.
>
> I'm just gonna guess that you need to emulate the way a torus is described
> parametrically.
>
> Wolfram gives:
>
>  (c-sqrt(x^2+y^2))^2+z^2=a^2,
> (1)
> and the parametric equations are
>
> x = (c+acosv)cosu
> (2)
> y = (c+acosv)sinu
> (3)
> z = asinv
>
> With c = major radius, a = minor radius, and probably swap y & z axes.
>
> In the Isosurface Tutorial, Mike states that he has a scene that emulates a
> sphere sweep and always makes the cross section perpendicular to the spline
> axis.  So maybe you can find that file and see what he does.
>
> I posted a zip of all the files here:
>
http://news.povray.org/povray.off-topic/message/%3C60a2d177%40news.povray.org%3E/#%3C60a2d177%40news.povray.org%3E

Thanks the input! It's highly appreciated.

Can you download and open the zip-file I attached in my first post?
It's the POV script I used.
I am not using a torus but a circle as cross section for the tube that follows
the graph of the heart curve. And the atan2 function - Povray knows this
function it's in math.inc - manages that the angle of the cross section is
perpendicular to the curve of the heart curve.

The question is why are some parts of the tube flatened as indicated in the
image T_HeartCurve_00a1.png??


Post a reply to this message

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 18:55:00
Message: <web.63a39c35560d61681f9dae3025979125@news.povray.org>
"Droj" <803### [at] drojde> wrote:

> Thanks the input! It's highly appreciated.

Certainly.   Every new challenge is a valuable learning experience.

> Can you download and open the zip-file I attached in my first post?
> It's the POV script I used.
> I am not using a torus but a circle as cross section for the tube that follows
> the graph of the heart curve. And the atan2 function - Povray knows this
> function it's in math.inc - manages that the angle of the cross section is
> perpendicular to the curve of the heart curve.

I did that, and looked it over, and played a bit with graphing some of the basic
equations and changing some things around to see the effect.

> The question is why are some parts of the tube flatened as indicated in the
> image T_HeartCurve_00a1.png??

I think that if you take a circle and trace the heart with it, but it rotates
too much / too little while you're going around, you're going to have a
non-orthogonal relationship between the circle and the "spline" - and so the
nearly parallel parts end up "flat".

Try using u/2 in your PHI calc - it partially solves that issue. (hmmm)

Also, use QY (the cos) in F1, since that seems to follow the torus equations in
my analogy.   x = cos v *cos u,      y = cos v * sin u,      z = sin v
                  ^^^

I think that maybe the atan2 isn't quite doing what you want it to do / think
it's doing.  Look like Mike uses vcross to calculate the normals.  Usually
normals are done with vdot?


The relevant files are in the distribution insert menu under meshmaker.

Here's one that I have somewhere on my HDD, so you can see what he's doing.
It's all splines, but maybe you can see what you need to do with the functions
to correct the orientation.


- BW




// Persistence of Vision Ray Tracer Include File
// File: SweepSpline.inc
// For POV Version: 3.5
// Desc: Macro sweeping one spline along another
// SweepSpline Version: 3
// Date: 1-Mar-2004
// Auth: Mike Williams
// Based on an idea by Greg M. Johnson


// Requires makemesh.inc by Ingo Janssen <http://members.home.nl/seedseven/>
//
// Parameters
// Track        A spline that specifies the path along the object
//              The section of the spline between control points 0 and 1 will be
used
// Shape        A spline that describes the cross section
//              The section of the spline between control points 0 and 1 will be
used
// Waist        A spline with x coordinates that specify the radius of the
spheresweep
//              The section of the spline between control points 0 and 1 will be
used
// U            The number of vertices along the path
// V            The number of vertices around the circumpherence
// FileName     The name of the file to whitch the mesh will be written. If is
an
//              empty string (""), no file will be written. If a file name is
given,
//              the macro will first check if it already exists. If that is so,
it
//              will expect a mesh2 with the name "Surface" and try to parse the
//              existing file.

#include "makemesh.inc"

#macro FindPoint(su,sv)

     // Spline point and radius
     #local P = Track(su);
     #local W = vlength(Waist(su).x);

     // Vertex position
     // To prevent flipping, calculate from the previous DRY vector
     #local DRX = W*vnormalize(vcross(DR,DRY));
     #local DRY = W*vnormalize(vcross(DRX,DR));
     P + (Shape(sv).x)*DRX + (Shape(sv).y)*DRY;

#end


#macro SweepSpline(Track,Shape,Waist,U,V,Filename)
#if(strlen(Filename)>0)
  #if(file_exists(Filename))
    #debug concat("\n Parsing mesh2 from file: ", Filename, "\n")
    #local Build=0;
    #include Filename
     object{Surface}
  #else
    #local Build=1;
  #end
#else
  #local Build=1;
#end

#if (Build)
#local Verts = array[U*(V+1)]
#local Norms = array[U*(V+1)]
#local UV    = array[U*(V+1)]

// Calculate the Vertexes, Normals and UV arrays
#local DRY = y; // Arbitrary initial vector that X will be perpendicular to
#local uu=0;
#while (uu<U)
  #local vv=0;
  #while (vv<=V)
     // UV information
     #local su = uu/U;
     #local sv = vv/V;
     #local UV[uu*(V+1)+vv] = <su,sv>;

     // Direction the spline is pointing
     #local DR = Track(su+0.001)-Track(su-0.001);

     // Find some points
     #local P = FindPoint(su,sv);
     #local Verts[uu*(V+1)+vv] = P;

     #local Pu0=P;
     #local Pu1 = FindPoint(su+0.001,sv);
     #if (vlength(Pu1-Pu0)=0)
       #local Pu1 = Pu0;
       #local Pu0 = FindPoint(su-0.001,sv);
     #end

     #local Pv0=P;
     #local Pv1 = FindPoint(su,sv+0.001);
     #if (vlength(Pv1-Pv0)=0)
       #local Pv1 = Pv0;
       #local Pv0 = FindPoint(su,sv-0.001);
     #end

     // calculate the normal
     #local Norms[uu*(V+1)+vv] = vcross(Pu1-Pu0,Pv1-Pv0);

     #local vv=vv+1;
  #end
  #local uu=uu+1;
#end

  BuildWriteMesh2(Verts, Norms, UV, V, U-1, Filename)

#end
#end


Post a reply to this message

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 19:05:00
Message: <web.63a39f26560d61681f9dae3025979125@news.povray.org>
Add this to your scene:

#for (N, 0, tau, tau/180)
 #local X = FX (N);
 #local Y = FY (N);
 sphere {<X/4, Y/4, 0> 0.01 pigment {rgb y}}
 cylinder {0, x 0.05 pigment {rgb z} rotate z*degrees(PHI (N)) translate <X/4,
Y/4, 0>}
#end

Then do the u/2 in the PHI calc

There's a clue in there for sure.


Post a reply to this message

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 19:55:00
Message: <web.63a3aa5d560d61681f9dae3025979125@news.povray.org>
> The question is why are some parts of the tube flatened as indicated in the
> image T_HeartCurve_00a1.png??



Angles.

A torus goes around smoothly, and the outward pointing normal is always pointing
away from the center.
You have a heart / cardioid, and the amount of rotation is 1.5 times that,
because you have that dip in the top of the heart.

I wasn't gonna figure all of that out, but what I did was essentially mirror the
curve by using select, and change the signs.

Try this and see if this is what you're after:  (Not sure about that dip)

    #declare rr = 1.00;
    // Parametric function sets for HeartCurve and their derivatives:
    #declare FX  = function(u) {16*pow(sin(u),3)};
    #declare FdX = function(u) {48*pow(sin(u),2)*cos(u)};

    #declare FY  = function(u) {13*cos(u)-5*cos(2*u)-2*cos(3*u)-cos(4*u)};
    #declare FdY = function(u) {-13*sin(u)+10*sin(2*u)+6*sin(3*u)+4*sin(4*u)};

    // Cross section of tube:
    #declare QX = function(v) {u};
    #declare QY = function(v) {rr*cos(v)};
    #declare QZ = function(v) {rr*sin(v)};

    // Rotation angle of cross section of tube:
    #declare PHI =
    function(u) {
      select (pi-u,

      atan2(abs(FdX((tau-u)/2)), FdY((tau-u)/2)) - pi/2,
      -atan2(abs(FdX(u/2)), FdY(u/2)) + pi/2
      )
     };

    #declare F1 = function(u,v) {QY(v) * cos(PHI(u)) + FX(u)};
    #declare F2 = function(u,v) {QY(v) * sin(PHI(u)) + FY(u)}


- BW


Post a reply to this message

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 21 Dec 2022 21:10:00
Message: <web.63a3bc20560d61681f9dae3025979125@news.povray.org>
Alternatively you could add in a correction just for the inside of the dip, and
then plop a sphere on there as a cap.

That requires some tricky SmoothStep stuff and determining where the sphere need
to be centered.

Still a bit of wonkiness on that left side though - not sure why yet.


Post a reply to this message


Attachments:
Download 'tubeheartcurve.png' (120 KB)

Preview of image 'tubeheartcurve.png'
tubeheartcurve.png


 

Goto Latest 10 Messages Next 10 Messages >>>

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