# Mapping onto Quads Meshes and Nurbs

What you’re looking for are generalised barycentric coordinates, of which probably the most popular form is mean value coordinates.

There’s also a generalisation of this to map points in 3d within closed meshes, which is what I implemented for the Mesh Cage Morph (Skeleton fattener + mesh cage morph)

but along the way, I also tried the 2d polygon version:
meanvaluecoordinates2d.gh (13.7 KB)

4 Likes

Hi Daniel Piker,

In some cases I get error:

1. Second vector is zero-length after projection onto the Plane

Do you know how to solve it?

Mapping_Piker.gh (25.2 KB)

I realised I posted the wrong version above - the points it was using were shifted by 1 around the polygon. Here’s a fixed version:
meanvaluecoordinates2d2.gh (17.8 KB)

As for the error - this happens when an input point lies exactly on one of the vertices of the reference polygon. In this case the weighting of that vertex should be set to 1, and all other weights set to zero. I included this check in the 3d cage morph component, but not in this little test definition.

Dear Daniel,

Thank you very much for the definition.

It seems perfect for polygonal mapping.
As for the quad mapping I think the linear interpolation of NurbsSurface results in linear distortions which for now fits me even building the nurbs surface. But for polygonal it works perfect.

Great.
One other thing I forgot to mention to watch out for - that definition is assuming the points to be mapped and the reference polygon are in the XY plane. If not, you’d need to fit a plane to them and measure the angles in that plane to avoid distortion:

Thanks. I have another question about mapping.

I would like to apply conformal mapping to a quad mesh by projecting it on another mesh.

What kind of qualities this mesh must contain? Would it be good to use kangaroo inscribed circle goal in order to preserve quad angles, while deforming it?

To illustrate the problem I point to ABF++ method, which is for sure too complex especially for these closed meshes. But is there any method in Kangaroo or Rhino in general that can help me to unflatten simple 3D mesh using conformal mapping? And then I want to map tiles back from 2D to 3D.

https://www.cs.ubc.ca/~sheffa/ABF++/abf.htm

Or maybe the question is more simple with simpler meshes, for instance how can I distort a mesh in Kangaroo that the result is always con-formally distorted?

Yes, if you make a circle packing mesh on your surface, and another circle packing mesh with same combinatorics (on a plane, or on another surface), the mapping between them is conformal.

If your mesh is topologically a disc or a sphere, things are much easier. Also, it depends on how much area distortion is acceptable. Conformal mappings preserve angles, but for doubly curved surfaces this always comes at the cost of some area distortion. This can be reduced by including seams and cone singularities, as shown in your image. Choosing where to put these, and doing the splitting complicates things though.

Anyway, assuming you can treat it as a disc without excessive area distortion, you can flatten it with a Tutte embedding (just using zero length springs guarantees it will be crossing free in the plane). Then if you optimise both the planar one and the one on the surface (while keeping them on these) for tangent incircles, you have a conformal mapping.

There are other ways of doing this with Kangaroo though -
I’ll post some examples tonight. I also have somewhere a goal for the cross ratio energy given in ‘conformal equivalence of triangle meshes’, that might be a way to do this with fewer steps.

Thanks it would nice to get an example:)

I tried Tutte algorithm from Starling, but the mapping get very distorted or I probably do not know how to map it properly.

While mapping on squished surface produces better results, which I believe it is some sort of conformal mapping, but I do not believe it is good of doing that. Thus I am search for a mesh unflattenning method.

I want to replicate the same methodology described here when reciprocal elements are projected to mesh with very small deviation: https://songpenghit.github.io/Publication/projects/2013-SIGGRAPH-RFStructure/index.htm To map polylines instead of using mesh edge rotation.

1 Like

The Tutte embedding will generally be far from conformal - I was saying you can use that to get an initial planar mapping, and then optimise it to be conformal.

Probably the simplest way, that would work for something like the example you showed, is to triangulate your curved mesh, apply Angle goals to each triangle (and no Length goal), and an OnPlane goal.
If there aren’t too many undercuts this is sometimes all you need. For more complex shapes though, you might need to also temporarily apply other goals such as smoothing to help guide it into the plane without folding over itself

conformal_flatten.gh (60.8 KB)

Here’s a simple example (needs Kangaroo 2.5). The flattening probably works best if you remesh to a good triangulation first. For more complex shapes you probably need other ways of preventing foldovers (such as constraining the boundary and using zero length springs for the interior, then gradually applying the angle goal).

Also, it’s not in Rhino*, but there’s a very nice standalone software for mesh flattening recently released:

*though in theory I think the libraries could be called from a plugin, which could be neat…

7 Likes

Wow, thank you very much.

I tried the definition with current food4rhino version, which 2.42. By 2.5 do you mean there would be a future release soon?

And one more bit, in my case I have to reduce angle strength goal to 0.01, if leave it 1 it explodes, 0.1 value have artifacts. Is it because I do not have 2.5 version?

It’s there on food4rhino, just scroll to the bottom of the list.
Also yes, in 2.5 I fixed an old issue with the angle goal where it behaved differently dependent on model scale.

1 Like

Was this the old issue where an elastica would go all zig-zaggy when the polyline edges were too short?

Exactly. Also where it would get super slow when the curves where many units long

1 Like

YES, that’s awesome. Team bendy rides again

Thanks, it is nice to see how close it is to the surface squish command. All I do not if needed but adding mesh spring preserves the scaling of the mesh. Also for the projection, the mesh is not overlapping if the plane projection strength is very slowly increased, I am wondering if there could be a custom goal which strength increase within iterations:)

With mesh springs, right side surface squish command from rhino:

without:

I loaded Boundary-First-Flattening from github page to grasshopper.

It runs quite nicely.

The longest part is obj to mesh converter that takes time as BFS is realtime.

I will also try to do this with C++ app to get real time manipulation.

Here is a quad mesh from triangular mesh:

10 Likes

This is wonderful work. Thanks, Daniel!
Native Kangaroo 2 components along with quad remeshing in Rhino7 WIP has greatly advanced some bending active structure work that I am currently assisting with.
The (BBF) boundary first flattening will take it that much further and allow for multiple ways into realizing structures either pre or post Kangaroo solver.

I added BFF from Keenan Crane to NGon plugin if you want to try. There is an example file.

1 Like