1
$\begingroup$

I have a series of points arranged on a grid of parallelograms. I know the width and height of the grid, and so I know the boundary of each parallelogram.

Given an arbitrary $x$, $y$ point, I want to find the vertices that bound that point (or, pragmatically, just the lower left hand vertex).

In the example below, I know that vertex $n$ is at $x=(n\mod 4)/4$, $y=n/12$. With the $x,y$ point shown, I want to find vertex #$2$, because $x,y$ is within the parallelogram bounded by vertices $2,3,6,7.$ (Don't worry about edge conditions -- I can handle those.)

I'm pretty sure there's a closed form for this using floor and mod, but my brain appears unwilling to produce it. Find the bounding parallelogram

$\endgroup$

1 Answer 1

1
$\begingroup$

Okay, I think I found the "aha" in coordinate transformation. If we define

x' = x
y' = y - x/3

then the parallelograms become squares. And then it's trivial to find the index of the lower left vertex:

i = floor(x*4)/4 + 4 * floor(y'/3);
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .