UV mapping a sub-section of a function

Talk about anything at all....

UV mapping a sub-section of a function

Postby Bald Eagle » Fri Sep 07, 2018 12:53 am

Good evening folks,
I have a little project I've been working on, and have a bit of a puzzle I could use some assistance with figuring out.

It a computer graphics (hobby) thing, but it's also a logic/math issue, which I figure the Calc people ought to be great at. :)

I have a large grid that we can assume to be square, and that I then "roll" into a cylinder, and then bend that tube around into a circle to form --- a torus.

I'd like to trace a path around that torus as done here:
https://math.stackexchange.com/question ... to-a-torus

And that would be easy - except that I'm trying to do this by tracing the path on the square BEFORE it gets wrapped into a torus (UV mapping), and because I have a specific way I need to evaluate the function due to the nature of the grid (Bezier patches)

So, I think that the 2D pattern which would give me the correct final 3D path would be a series of diagonal lines stacked in a unit square, with the right edge of the top line corresponding with the left edge of the next line below it (or swap right with left - no matter)
I'm thinking a linear function down, and a mod(A,B) function to give the diagonal lines.

But then here's the tricky part:
I need to plot the points of this trace in each sub-square of the global grid separately, with the range in each square being 0-1 in either dimension, and need to keep track of the designation the square in horizontal and vertical directions.

So, for the folks who are following this all so far,
I have an array of Bezier bicubic patches, each with 16 control points, that are arranged into a rectangular grid.
They are numbered 0 to N1 in the horizontal direction, and 0 to N2 in the vertical direction.
I need to programmatically loop through a range of values (let's call it Theta) and know which Bezier-patch space I'm in : which array element I'm operating on.

Then, I need to start at one end of that patch, and depending upon the [i][j] location in that patch (both ranging from 0 to 1), use the field of Bernstein polynomials and control point weights to calculate the location of that point on the patch. I have already worked out the macros to do that part (with help ;) ) and just need to figure out the system of organizing the input data for that macro, which are the "global" U,V coordinates, or the large array element designations, and the individual u,v values of each bicubic patch.
something like:
macro (U, V, u, v)

Any advice, suggestions, thoughts, solutions? :)

OpenOffice 4.1.1 on Windows 7
Bald Eagle
Posts: 59
Joined: Wed Apr 19, 2017 9:22 pm

Re: UV mapping a sub-section of a function

Postby Bald Eagle » Tue Sep 11, 2018 9:10 pm

I've managed to work most of it out, and I've gotten it to give the expected results with a circle and the diagonal lines.
Briefly, I construct two arrays with ranges for the u and the v of the individual patches
Then I compare the x and y values of the function to the start and end to find what patch I'm on.
Then I subtract the start value from the function result and ivide by the range of that patch to get a 0-1 parameterization for each patch.

The following is code in POV-Ray SDL, so you can see where I'm going with this.

The last thing I need to do is take the "global" and "local" uv coordinates and translate those to coordinates on the surface of the Bezier bicubic patch.
Still a few bugs left there, but I can see the light at the end of the tunnel. :)

Almost there...

#for (U, 0, UU)
#declare UArray [U] = <U, U*UStep, (U+1)*UStep>;

#for (V, 0, VV)
#declare VArray [V] = <V, V*VStep, (V+1)*VStep>;

// Determines which Bezier patch in array the function coordinates fall on
#macro ThisPatch (XVal, YVal)

//#local _Patch = <0, 0>;
#local _Patch = array [6];

#for (U, 0, UU)
//#debug concat ("Testing ", Scalar (YVal, 3, 0), " vs ", Vector (UArray [U], 3, 0), " \n")
#if (YVal >= UArray [U].y & YVal <= UArray [U].z)
//#local _Patch = _Patch + <UArray [U].x, 0, 0>;
#local _Patch [0] = UArray [U].x;
#local _Patch [1] = UArray [U].y;
#local _Patch [2] = UArray [U].z;

#ifndef (_Patch [0]) #debug "_Patch [0] U not defined \n" #end

#for (V, 0, VV)
#if (XVal >= VArray [V].y & XVal <= VArray [V].z)
//#local _Patch = _Patch + <0, VArray [V].x, 0>;
#local _Patch [3] = VArray [V].x;
#local _Patch [4] = VArray [V].y;
#local _Patch [5] = VArray [V].z;


// Determines where on individual Bezier patch function coordinates are
#macro PatchUV (XVal, YVal)
#local Range = ThisPatch (XVal, YVal);
#local ThisU = (YVal - Range [1]) / (Range [2]- Range [1]);
#local ThisV = (XVal - Range [4]) / (Range [5]- Range [4]);
<ThisV, ThisU, 0>
OpenOffice 4.1.1 on Windows 7
Bald Eagle
Posts: 59
Joined: Wed Apr 19, 2017 9:22 pm

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest