c# - How can I put these points (x,y) in order? -


i have a* algorithm implemented, find way between 2 coordinates, , works (pretty much).

after that, need show circle, going step step through path

problem is, order coordinates added list, (then) show them, based on x, y; and, sometimes, has change directions, like: left, left, left, up, up, up, left, left, down, down, left, up, up, up.

i have tried order them x, y, ascending , descending , vice versa, but, because of direction changes, not work circle go step step.

so, had idea, not sure, on how it:

first: create list, , set ids each point. second: make initial point path made, id 0 third: add other coords:

private async void showanimation(int size)     {         int idofmap = 0;         int xplus = 1;         int yplus = 1;         mapa = new mapa();         list<mapa> resultmap = new list<mapa>();          foreach (mapa camino in mapa.mapacamino)         {             if (camino.x == initialstore_x && camino.y == initialstore_y)             {                 a.x = camino.x;                 a.y = camino.y;                 a.id = idofmap.tostring();                 resultmap.add(a);                 idofmap++;             }             (var = 0; < mapa.mapacamino.count; i++)             {                 if (camino.x == a.x)                 {                     if (camino.y == (a.y + yplus) || camino.y == (a.y - yplus))                     {                      }                 }             }          } 

(that have far)

now problem comes when has go up, instance; after going down:

yplus = 5, after going down ... , next time had check y, need yplus 4. , same thing may happen x (besides have check when camino.x == a.x + xplus, etc)

so, way have items, in list, ordered point point b?

this code snipet, in case helps:

private void showroute(ienumerable<point> path, int size)     {         canvas mycanvas1 = new canvas();         canvas mycanvas2 = new canvas();          (int y = 0; y <= this.map.getlength(1)-1; y++)         {             (int x = 0; x < this.map.getlength(0); x++)             {                 //set initial point                 if (this.searchparameters.startlocation.equals(new point(x, y)))                 {                     mycanvas1.background = new solidcolorbrush(colors.red);                     mycanvas1.height = size;                     mycanvas1.width = size;                     canvas.settop(mycanvas1, (y) * size);                     canvas.setleft(mycanvas1, (x) * size);                     myparentcanvas.children.add(mycanvas1);                 }                     //set end point                 else if (this.searchparameters.endlocation.equals(new point(x, y)))                 {                     mycanvas2.background = new solidcolorbrush(colors.blue);                     mycanvas2.height = size;                     mycanvas2.width = size;                     canvas.settop(mycanvas2, (y) * size);                     canvas.setleft(mycanvas2, (x) * size);                     myparentcanvas.children.add(mycanvas2);                 }                     //add whole path list                 else if (this.map[x, y] == true)                 {                      if (path.where(p => p.x == x && p.y == y).any())                     {                         mapa pathtogo = new mapa();                         pathtogo.x = x;                         pathtogo.y = y;                         mapa.mapacamino.add(pathtogo);                     }                 }             }         }         //show path in map         foreach (var camino in mapa.mapacamino)         {             imagebrush yellowdot = new imagebrush();             yellowdot.imagesource = new bitmapimage(new uri("ms-appx:/imagenes/pathtooz.png", urikind.absolute));              canvas mycanvas3 = new canvas();             mycanvas3.background = yellowdot;             mycanvas3.height = (size + 2);             mycanvas3.width = (size + 2);             canvas.settop(mycanvas3, (camino.y) * size);             canvas.setleft(mycanvas3, (camino.x) * size);              myparentcanvas.children.add(mycanvas3);         }         showanimation(size);     } 


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -