I see.

So if quad-grid is result of meshing then you have to implement your mapping method from ground.

To be able to do 2d-mapping you have to determine inaginary **u** and **v** direction of your quad grid.

So we have quad-polylines, let QPi be an arbitrary quad-polyline.

Create two lists of integers, UCoord and VCoord which will be coordiante of our QP in mapping2DArray.

Create one list of Guids, qpGuids where we store guid of particular QP.

So for fist QP we process we will have qpGuids[0]= QP.Guid, UCoord[0]= u-coordinate, VCoord[0]= v-coordinate.

For second QP we will have qpGuids[1]= QP.Guid, UCoord[1]= u-coordinate, VCoord[]= v-coordinate, and so on.

We also create collection of all available QPs not yet processed, QPsToProcess.

Start with selecting any QPi. i=0.

Remove QPi from collection QPsToProcess.

QPi will be center of our mappingArray, CurrentU= 0, CurrentV=0. (mappingArray can have negative index as well - see following).

So we have first qpGuids[0]= QP.Guid, UCoord[0]= CurrentU (=0), VCoord[0]= CurrentV (=0).

Choose one edge on QP and define it as *u* direction (direction from center of QP to that edge).

Choose neighboring edge on QP, next segment of polyline (in direction of polyline points) and define it as *v* direction.

So now we have u and v direction.!

Now we move to neghbouring QPs. There are 4 dirrection we can move +u, -u, +v and -v.

Lets do it for +u direction, it is analog for any other direction. We move to +u only if there is neighbour QP there.

So you have origin QP, QP0.

Increased i++. Neigbour QP, QP1…

Condition that QP1 is neighbour of of QP0 (and vice versa) is that +u segment of QP0 is equal to - (-u) segment of QP1.

It is important that all QPs have same orientation = polylines have points oriented in same direction,

It means that QP0 ‘+u’ is LINE( QP0[0], QP0[1] ), and QP1 ‘-u’ is LINE( QP1[2], QP1[3] ), so

QP0[0] = QP1[3], QP0[1] = QP1[2] which gives us that :

QP0 ‘+u’ segment = - QP1 ‘-u’ segment

So you have to compare QP which is being currently porccessed with previous one and sort the polyline points if neccesary.

So becasue we moved to +u direction and found neighbur there QPi:

CurrentU= 1, CurrentV=0.

and we can write to our lists following

qpGuids[1]= QP.Guid,

UCoord[1]= CurrentU (=1),

VCoord[1]= CurrentV (=0).

Remove QPi from collection QPsToProcess.

And we can go on.

And obviously we can do it as recursion for all 4 directions!

Radovan