POV-Ray : Newsgroups : povray.general : 2D function to 3D tube Server Time
23 May 2024 17:29:39 EDT (-0400)
  2D function to 3D tube (Message 5 to 14 of 34)  
<<< Previous 4 Messages Goto Latest 10 Messages Next 10 Messages >>>
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


 

From: Droj
Subject: Re: 2D function to 3D tube
Date: 22 Dec 2022 18:55:00
Message: <web.63a4ed40560d61682a0260b33b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> > 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

My goodness! I will try this. Your heart curve loks much smoother than mine.

I already had in the back of my mind that it had to do with the atan2 but I'm
not a mathematician.

I really appreciate your help and I'll try your solution with other curves, too.

In the not too distant future I will try to produce some nice Lissajous curves.

Thanks again


Post a reply to this message

From: Droj
Subject: Re: 2D function to 3D tube
Date: 22 Dec 2022 18:55:00
Message: <web.63a4ee36560d61682a0260b33b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "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

I copied that .inc file and see what it does.

Thanks


Post a reply to this message

From: Droj
Subject: Re: 2D function to 3D tube
Date: 22 Dec 2022 19:10:00
Message: <web.63a4f0e6560d61682a0260b33b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> 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.

Well, I guess I take it as is - means no sphere as cap.

You are right: the left side is a bit different - may be some kind of heart
desease?

All in all it looks great!


Post a reply to this message

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

Hi Oswald,

I had some time to look at:
https://www.frassek.org/3d-mathe/funktionsgraph-als-rohr-r%C3%B6hre/

And I see where you're getting all of your code from, and I'm a bit disappointed
that it isn't working "out of the box" like they seem to imply.


While I'm happy I puzzled out some things to get the shape to look right, it's
certainly not a general solution, which would be highly desirable.  I can
envision using this to make text, offset curves, and generate signed distance
functions for all manner of shapes.

I would encourage you to keep working on this, and perhaps step through some
larger values of u and render some representative frames such as are illustrated
here:

https://image.jimcdn.com/app/cms/image/transf/dimension=301x1024:format=jpg/path/scee86bccd27a6ab2/image/idb0be97f0344a
7c5/version/1573907965/konstruktion-des-funktionsgraphs-als-rohr-r%C3%B6hre.jpg

Then it would be easier to see what is going wrong, and hopefully puzzle out
why.

It would be very nice indeed to be able to pass a function into a macro that
would render a pipe/tube graph for that function.

I would also keep in mind any differences in axis orientation, since it seems
that their Y and Z axes are switched.

- Bill


Post a reply to this message

<<< Previous 4 Messages Goto Latest 10 Messages Next 10 Messages >>>

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