Background
Looking to trace a path between two points on a hexagonal grid while following the nearest edge.
Problem
Determining the algorithm to constrain the all iterations after the first one to the edge.
Code
Given:
- vac -- The X coordinate of the starting vertex.
- var -- The Y coordinate of the starting vertex.
- vbc -- The X coordinate of the ending vertex.
- vbr -- The Y coordinate of the ending vertex.
- offset_ac -- The X grid offset for the starting central point.
- offset_ar -- The Y grid offset for the starting central point.
We can compute:
- theta -- The angle of the line, in degrees, between the starting and ending points.
- vangle -- The nearest vertex to the line (based on angle).
- vc -- The X coordinate of the first vertex, offset from the center.
- vr -- Ditto for the Y coordinate.
% Compute the direction towards the first segment (to vertex of an edge).
theta := degrees( atantwo( vac, var, vbc, vbr ) );
vangle := round( theta / 60 ) * 60 * pi / 180;
% Calculate the position of the first vertex, offset from the center.
vc := offset_ac + cos( vangle );
vr := offset_ar + sin( vangle );
% Draw a line from the starting point to the ending point.
draw (offset_ac, offset_ar) -- (vc, vr)
withcolor colour_node;
% Draw a circle at the ending coordinate.
draw (vc, vr)
withcolor colour_node
withpen pencircle
scaled vertex_sm;
Output
The current output resembles:

The desired output resembles:

Question
What algorithm can walk the graph between the starting and ending points while the path is constrained to the edges?
Finding the first vertex was simple enough. Conceptually, the given code seems like it could be iterated over with the correct "shifting" of the starting point's offset to the vertex. However, after such a "shift" would the new angles be incorrect by something like a half-width and half-height? And even then, how would you keep the next iteration constrained as depicted in the second diagram?