0
$\begingroup$

enter image description here

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.

enter image description here

$\endgroup$
7
  • $\begingroup$ 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? $\endgroup$
    – TheLabCat
    Oct 10, 2020 at 20:43
  • $\begingroup$ round() or int() can convert to indexing number for you $\endgroup$
    – TheLabCat
    Oct 10, 2020 at 20:45
  • $\begingroup$ @ZargulTheWizard that gives distance , distance is 1d . i want a 2d panel , then convert it to 1d $\endgroup$ Oct 10, 2020 at 20:45
  • $\begingroup$ ? It converts the 2d to 1d, I had assumed to have the 2d you'd just leave one axis out. $\endgroup$
    – TheLabCat
    Oct 10, 2020 at 20:47
  • $\begingroup$ @ZargulTheWizard you'r right but that gives a symmetrical square on diagonal axis. $\endgroup$ Oct 10, 2020 at 20:49

2 Answers 2

1
$\begingroup$

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.

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

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.