I have a hexagonal coordinate system as shown here:
(If you'd like a better understanding of the coordinate system, I learned it from here)
I would like to reflect points (hexagons) across given lines. In fact, the only lines I need to reflect across are those defined by the border of (0, 0)
and the other hexagons around it.
For example, the border of (0, 0)
and (1, 0)
creates a line. (0, 1)
and (1, -1)
would both be points on this line. The hexagon bordering (0, 0)
that helps define the line (in this case, (1, 0)
), I'll call the "bordering hexagon".
My question is this: Is there an easier algorithm than the one I describe below that takes the coordinates of the bordering hexagon and another hexagon on the grid (called the objective hexagon), and returns the coordinates of the objective hexagon after a reflection over the line defined by (0, 0)
and the bordering hexagon?
My current method is:
- Use the coordinates of the bordering hexagon as a vector perpendicular to the reflection line
- Take the coordinates of the two bordering hexagons surrounding our original bordering hexagon, and subtract them
(x2-x1, y2-y1)
to get a vector parallel to the reflection line - Use a change of coordinates matrix to convert the coordinates of the objective hexagon into parallel and perpendicular components such that
(perpendicular component)*(perpendicular vector)+(parallel component)*(parallel vector) = (objective hexagon coordinates)
- The result of the reflection is then
(objective hexagon coordinates)+2*(perpendicular component)*(perpendicular vector)
Does anyone know of a better way? This seems fairly complicated for such a seemingly simple problem.
Aucun commentaire:
Enregistrer un commentaire