POV-Ray : Newsgroups : povray.general : 2D function to 3D tube Server Time
25 Apr 2024 08:20:02 EDT (-0400)
  2D function to 3D tube (Message 11 to 20 of 34)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
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

From: Droj
Subject: Re: 2D function to 3D tube
Date: 23 Dec 2022 13:15:00
Message: <web.63a5eef4560d61682ad5f62e3b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "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/idb0be97f034
4a
> 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

Hi Bill,

first of all thank you so much for encouraging me to follow up this matter and
for spending your time (may be wasting your time) to put me on the right track.

Well, I felt the same disappointment when I used the functions of B. Frassek's
page. I also tested the cardiode, the astroide and Archimeds spiral.
Same thing: flat tube in some parts!

I'm still looking for the air pump!

I spent some time to read what Wikipedia says about atan2 function.
Well, it gave me a nice headache but didn't clear the muddy waters.
The only thing I realised is that the function has to change depending on the
quadrants the graph passes.

BTW I used the macro:

#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
but Povray at once complaint about 'undeclared tau'.
Can you give me a hint what that macro does? I am ignorant I know!

I promise to be persistant and as being a chemist I can be very persistant.

- Oswald


Post a reply to this message

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

> I spent some time to read what Wikipedia says about atan2 function.
> Well, it gave me a nice headache but didn't clear the muddy waters.
> The only thing I realised is that the function has to change depending on the
> quadrants the graph passes.

Well, I did do a lot of sleuthing last night, and got a nice diagram with the
curve, vertical circle, tangent line, angle, and rotated circle.  Seemed to work
very nicely on y=pow(x,2).

Going back to your original unedited scene, it's clear that at the very least
you have the arguments for atan2 switched - it's atan2 (y, x).  You also need to
use QY in both F1 and F2.
Im my homebrew code, I'm using atan2 (f'(x)*x, x), since that's going to be each
cathetus of the right triangle representing the tangent line and the x-axis.

That's going to require some refactoring to deal with the parametric vs implicit
 equations, but I went and did that....

.... but after that, I can't seem to straighten out the atan2 issue in your scene
code - and I'm suspecting that it may be an issue with the way that meshmaker
handles the generation of the triangles.  It may be straddling regions such that
the sides of the curve get switched, or something similar.

Hopefully I'll give it a further look and see if that's the issue.   I'm going
to try to make a much finer mesh and see if that minimizes or even eliminates
the problem.

> BTW I used the macro:
>
> #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
> but Povray at once complaint about 'undeclared tau'.
> Can you give me a hint what that macro does? I am ignorant I know!
>
> I promise to be persistant and as being a chemist I can be very persistant.

Excellent - fellow chemist here, persistence just didn't pay off as much as it
needed to in that field.  :(

tau is simply 2*pi (available in v3.8), so you can either replace that, or just
put a line near the beginning of the scene:

#declare tau = 2*pi;

I'm confident that this is a solvable problem.

-BW


Post a reply to this message


Attachments:
Download 'tubecurves.png' (117 KB)

Preview of image 'tubecurves.png'
tubecurves.png


 

From: Bald Eagle
Subject: Re: 2D function to 3D tube
Date: 23 Dec 2022 15:25:00
Message: <web.63a60e2c560d61681f9dae3025979125@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> I'm confident that this is a solvable problem.


As I said.   Success!   :)

Looks like all you have to do is change these two lines:

I got the atan to give me a "clean" curve, but it was really skinny.   "maybe
that's just rotated 90 deg from what it should be...?
So I got rid of the pi/2.  No idea _why_ that works...   yet.


#declare PHI = function (u) {-atan2( FdY(u), FdX(u) ) + pi/2*0};

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


Post a reply to this message


Attachments:
Download 'tube_heartcurve.png' (46 KB)

Preview of image 'tube_heartcurve.png'
tube_heartcurve.png


 

From: Droj
Subject: Re: 2D function to 3D tube
Date: 24 Dec 2022 10:45:00
Message: <web.63a71d3e560d6168baa940d23b2af915@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
>
> > I'm confident that this is a solvable problem.
>
>
> As I said.   Success!   :)
>
> Looks like all you have to do is change these two lines:
>
> I got the atan to give me a "clean" curve, but it was really skinny.   "maybe
> that's just rotated 90 deg from what it should be...?
> So I got rid of the pi/2.  No idea _why_ that works...   yet.
>
>
> #declare PHI = function (u) {-atan2( FdY(u), FdX(u) ) + pi/2*0};
>
> #declare F1 = function(u,v) {QY(v)*sin(PHI(u)) + FX(u)};

Heureka and congratulations! You solved that 'pain in the backside'.

I adapted the POV-script according to the functions above and it looks great!
Changing QX to QY in F1 did the trick. And right, the pi/2 produces a
very, very flat curve almost like a ribbon.

I will try to do some fine tuning as the heart curve still has an inconsistency
where the dip is.

But all in all it's a beauty and I'm definitely happy.

I wish you a Merry Christmas and thank you so much.

Oswald


Post a reply to this message

From: Droj
Subject: Re: 2D function to 3D tube
Date: 24 Dec 2022 15:35:00
Message: <web.63a76234560d6168baa940d23b2af915@news.povray.org>
"Droj" <803### [at] drojde> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > "Bald Eagle" <cre### [at] netscapenet> wrote:
> >
> > > I'm confident that this is a solvable problem.
> >
> >
> > As I said.   Success!   :)
> >
> > Looks like all you have to do is change these two lines:
> >
> > I got the atan to give me a "clean" curve, but it was really skinny.   "maybe
> > that's just rotated 90 deg from what it should be...?
> > So I got rid of the pi/2.  No idea _why_ that works...   yet.
> >
> >
> > #declare PHI = function (u) {-atan2( FdY(u), FdX(u) ) + pi/2*0};
> >
> > #declare F1 = function(u,v) {QY(v)*sin(PHI(u)) + FX(u)};
>
> Heureka and congratulations! You solved that 'pain in the backside'.
>
> I adapted the POV-script according to the functions above and it looks great!
> Changing QX to QY in F1 did the trick. And right, the pi/2 produces a
> very, very flat curve almost like a ribbon.
>
> I will try to do some fine tuning as the heart curve still has an inconsistency
> where the dip is.
>
> But all in all it's a beauty and I'm definitely happy.
>
> I wish you a Merry Christmas and thank you so much.
>
> Oswald

PS:
Your solution works with simple Lissajous functions, too.

This is a great Christmas present!


Post a reply to this message


Attachments:
Download 't_lissa1_3_4.png' (469 KB)

Preview of image 't_lissa1_3_4.png'
t_lissa1_3_4.png


 

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

> > I will try to do some fine tuning as the heart curve still has an inconsistency
> > where the dip is.

Yeah - not sure if that's the math or the macro.
It seems to be right at the beginning of the curve, so maybe instead of going
from 0 - 2pi, maybe start at pi/180 and see if that trims off the cruft.


> Your solution works with simple Lissajous functions, too.
>
> This is a great Christmas present!

I'm glad it's all working out - it definitely took a lot of staring at the code,
trying to see what each operation did and why, and even stupidly staring at
documentation I wrote myself until I finally figured out what I needed to do and
why.

https://news.povray.org/povray.binaries.images/thread/%3Cweb.606b78af565eea121f9dae3025979125%40news.povray.org%3E/

Those polynomial curves look super interesting.  It would be nice to have macros
to render all three types of curves, plus just the 2D offset curve(s).

Anyway, I'm glad you like it, and have a Merry Christmas.

- BW


Post a reply to this message

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

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