# map 2d coordinates to 1d index using blender drivers is there a clean way to convert a 2d vector ( from relative position between two objects ) to 1d index using blender drivers? it should be extendable to add more items later . it is useful to control a grease pencil frame with 'Time Offset' fixed modifier. • Pythagorean theorem applied for distance in python: ((op2.x-op1.x)**2+(op2.y-op1.y)**2)**0.5 Does this work for what you need? Oct 10, 2020 at 20:43
• round() or int() can convert to indexing number for you Oct 10, 2020 at 20:45
• @ZargulTheWizard that gives distance , distance is 1d . i want a 2d panel , then convert it to 1d Oct 10, 2020 at 20:45
• ? It converts the 2d to 1d, I had assumed to have the 2d you'd just leave one axis out. Oct 10, 2020 at 20:47
• @ZargulTheWizard you'r right but that gives a symmetrical square on diagonal axis. Oct 10, 2020 at 20:49

I don't know if there is a solution to grease pencil related but in a shader node you could use a formular like

Index = Row * GridWith + Column

to get an index from a 2d Point.

• ...I just did this answer again, but more readymade XD Oct 18, 2020 at 2:35
• After I thought through it, I realized your answer was same as mine :) Oct 18, 2020 at 2:36

To translate global position into a position in a grid:

Basically, if the grid can have numeric identities in reading order...

This relies on the grid being cartessian, and made of one meter cells. I placed the corner of the top left cell at the origin. Conversion to polar coordinates is probably possible, but more complicated (need to know I'm on the right track first so no wasted work, you know ;-)

#round(pos.x-0.5)+round(-pos.y-0.5)*GRID_X_SIZE