0
\$\begingroup\$

enter image description herei want to move point along spiral like hexagon for example i want to traverse the whole area and my player (point) is standing where i have placed it manually. now i want to start from this point and move outwards in concentric hexagonal path so that it moves along a bigger hexagon each time till it has covered the entire area. kindly suggest me how to develop such algorithm in c++ or simple c.

\$\endgroup\$
  • \$\begingroup\$ Your question's wording is rather unclear, would you try to re-phrase it? Some image would be also nice. \$\endgroup\$ – wondra Aug 24 '15 at 17:24
  • \$\begingroup\$ i have added an image to help you understand the question :) \$\endgroup\$ – user70342 Aug 24 '15 at 18:05
0
\$\begingroup\$

Lets say player is at origin, and you have (any convex shape should work) your inner-most hexagon defined as array vec2 shape[6]. The simplest algorithm would be:

int windingsNo; //=some value
const int vertexCount = 6;
vec2 shape[vertexCount];
float scale = 1.f;
for(int w = 0; w < windingsNo; w++)
{
  for(int v = 0; v < vertexCount; v++)
  {
    scale *= 1.1; // or += .1f
    player.MoveTo(shape[v] * scale); 
  }
   //if you wish non-spiral path like on image, move scaling here, requires one more move().
}

or in other words: 1) move onto inner-most shape 2) move on vertex with index +1 on +1 bigger shape. This has the upside you can make gradually bigger absolute size difference if you put relative scaling (e.g. scale *= 1.1) in the inner loop. Translating the path to the desired location is now trivial.

\$\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.