Finding closest possible coordinatesHow to check if a possible path exist?How do I find out which DOM element has the focus?Where can I find documentation on formatting a date in JavaScript?Easy interview question got harder: given numbers 1..100, find the missing number(s)Getting the closest string matchFind an integer not among four billion given onesFind object by id in an array of JavaScript objectsHow to find time complexity of an algorithmIs it possible to apply CSS to half of a character?Detecting 3D collision between a triangle and a rotating sphereFinding closest x,y coordinates

How to not starve gigantic beasts

Checks user level and limit the data before saving it to mongoDB

Was there a Viking Exchange as well as a Columbian one?

Implications of cigar-shaped bodies having rings?

Size of electromagnet needed to replicate Earth's magnetic field

What are the characteristics of a typeless programming language?

What happened to Captain America in Endgame?

How do I check if a string is entirely made of the same substring?

Is it idiomatic to construct against `this`

Is this homebrew Wind Wave spell balanced?

Two field separators (colon and space) in awk

Which big number is bigger?

Elements other than carbon that can form many different compounds by bonding to themselves?

Dynamic SOQL query relationship with field visibility for Users

How come there are so many candidates for the 2020 Democratic party presidential nomination?

How to fry ground beef so it is well-browned

How to have a sharp product image?

What term is being referred to with "reflected-sound-of-underground-spirits"?

Providing evidence of Consent of Parents for Marriage by minor in England in early 1800s?

How does Captain America channel this power?

Multiple options vs single option UI

A Paper Record is What I Hamper

How could Tony Stark make this in Endgame?

555 timer FM transmitter



Finding closest possible coordinates


How to check if a possible path exist?How do I find out which DOM element has the focus?Where can I find documentation on formatting a date in JavaScript?Easy interview question got harder: given numbers 1..100, find the missing number(s)Getting the closest string matchFind an integer not among four billion given onesFind object by id in an array of JavaScript objectsHow to find time complexity of an algorithmIs it possible to apply CSS to half of a character?Detecting 3D collision between a triangle and a rotating sphereFinding closest x,y coordinates






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have x,y coordinates board like this:



enter image description here



the board is up to 100x100.



Where myPosition is gold, destinations is green and collisions is red. myPosition is object destinations and collisions are array of objects:



let myPosition=x:0,y:0;
let destinations = [x: 0, y: 5, x: 2, y: 0, x: 2, y: 2];
let collisions = [x: 1, y: 0,x: 1, y: 1,x: 1, y: 2,x: 1, y: 3,x: 1, y: 4,x: 2, y: 1,x: 2, y: 0,x: 2, y: 1]


With this code (live demo) I'm able to find nearest destination but it doesn't know about collisions at all. I can not figure how to write algorithm which additionally would check for collision and give ouput 0,5 in above scenerio.



There is also assumption that we can not move diagonally.



I found this SO answer which seems to provide answer to my question but I can not get it to work with my input arrays.










share|improve this question






















  • This sounds to me like you're looking for a pathing solution, the first that comes to mind is a-star ( a* ) see: buildnewgames.com/astar . a* is also mentioned in the SO answer you referenced

    – Steven Stark
    Mar 22 at 17:44












  • even your current solution is wrong as it calculates squared distance so it allows diagonal moves. You want to do something like bfs

    – juvian
    Mar 22 at 17:46











  • I found A* library but in usage github.com/prettymuchbryce/easystarjs#usage there is grid with 0 and 1 where I believe 0 is walkable and 1 is not. Can I somehow convert my object/arrays to grid like this?

    – BT101
    Mar 22 at 18:46

















0















I have x,y coordinates board like this:



enter image description here



the board is up to 100x100.



Where myPosition is gold, destinations is green and collisions is red. myPosition is object destinations and collisions are array of objects:



let myPosition=x:0,y:0;
let destinations = [x: 0, y: 5, x: 2, y: 0, x: 2, y: 2];
let collisions = [x: 1, y: 0,x: 1, y: 1,x: 1, y: 2,x: 1, y: 3,x: 1, y: 4,x: 2, y: 1,x: 2, y: 0,x: 2, y: 1]


With this code (live demo) I'm able to find nearest destination but it doesn't know about collisions at all. I can not figure how to write algorithm which additionally would check for collision and give ouput 0,5 in above scenerio.



There is also assumption that we can not move diagonally.



I found this SO answer which seems to provide answer to my question but I can not get it to work with my input arrays.










share|improve this question






















  • This sounds to me like you're looking for a pathing solution, the first that comes to mind is a-star ( a* ) see: buildnewgames.com/astar . a* is also mentioned in the SO answer you referenced

    – Steven Stark
    Mar 22 at 17:44












  • even your current solution is wrong as it calculates squared distance so it allows diagonal moves. You want to do something like bfs

    – juvian
    Mar 22 at 17:46











  • I found A* library but in usage github.com/prettymuchbryce/easystarjs#usage there is grid with 0 and 1 where I believe 0 is walkable and 1 is not. Can I somehow convert my object/arrays to grid like this?

    – BT101
    Mar 22 at 18:46













0












0








0








I have x,y coordinates board like this:



enter image description here



the board is up to 100x100.



Where myPosition is gold, destinations is green and collisions is red. myPosition is object destinations and collisions are array of objects:



let myPosition=x:0,y:0;
let destinations = [x: 0, y: 5, x: 2, y: 0, x: 2, y: 2];
let collisions = [x: 1, y: 0,x: 1, y: 1,x: 1, y: 2,x: 1, y: 3,x: 1, y: 4,x: 2, y: 1,x: 2, y: 0,x: 2, y: 1]


With this code (live demo) I'm able to find nearest destination but it doesn't know about collisions at all. I can not figure how to write algorithm which additionally would check for collision and give ouput 0,5 in above scenerio.



There is also assumption that we can not move diagonally.



I found this SO answer which seems to provide answer to my question but I can not get it to work with my input arrays.










share|improve this question














I have x,y coordinates board like this:



enter image description here



the board is up to 100x100.



Where myPosition is gold, destinations is green and collisions is red. myPosition is object destinations and collisions are array of objects:



let myPosition=x:0,y:0;
let destinations = [x: 0, y: 5, x: 2, y: 0, x: 2, y: 2];
let collisions = [x: 1, y: 0,x: 1, y: 1,x: 1, y: 2,x: 1, y: 3,x: 1, y: 4,x: 2, y: 1,x: 2, y: 0,x: 2, y: 1]


With this code (live demo) I'm able to find nearest destination but it doesn't know about collisions at all. I can not figure how to write algorithm which additionally would check for collision and give ouput 0,5 in above scenerio.



There is also assumption that we can not move diagonally.



I found this SO answer which seems to provide answer to my question but I can not get it to work with my input arrays.







javascript algorithm collision nearest-neighbor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 17:40









BT101BT101

2092626




2092626












  • This sounds to me like you're looking for a pathing solution, the first that comes to mind is a-star ( a* ) see: buildnewgames.com/astar . a* is also mentioned in the SO answer you referenced

    – Steven Stark
    Mar 22 at 17:44












  • even your current solution is wrong as it calculates squared distance so it allows diagonal moves. You want to do something like bfs

    – juvian
    Mar 22 at 17:46











  • I found A* library but in usage github.com/prettymuchbryce/easystarjs#usage there is grid with 0 and 1 where I believe 0 is walkable and 1 is not. Can I somehow convert my object/arrays to grid like this?

    – BT101
    Mar 22 at 18:46

















  • This sounds to me like you're looking for a pathing solution, the first that comes to mind is a-star ( a* ) see: buildnewgames.com/astar . a* is also mentioned in the SO answer you referenced

    – Steven Stark
    Mar 22 at 17:44












  • even your current solution is wrong as it calculates squared distance so it allows diagonal moves. You want to do something like bfs

    – juvian
    Mar 22 at 17:46











  • I found A* library but in usage github.com/prettymuchbryce/easystarjs#usage there is grid with 0 and 1 where I believe 0 is walkable and 1 is not. Can I somehow convert my object/arrays to grid like this?

    – BT101
    Mar 22 at 18:46
















This sounds to me like you're looking for a pathing solution, the first that comes to mind is a-star ( a* ) see: buildnewgames.com/astar . a* is also mentioned in the SO answer you referenced

– Steven Stark
Mar 22 at 17:44






This sounds to me like you're looking for a pathing solution, the first that comes to mind is a-star ( a* ) see: buildnewgames.com/astar . a* is also mentioned in the SO answer you referenced

– Steven Stark
Mar 22 at 17:44














even your current solution is wrong as it calculates squared distance so it allows diagonal moves. You want to do something like bfs

– juvian
Mar 22 at 17:46





even your current solution is wrong as it calculates squared distance so it allows diagonal moves. You want to do something like bfs

– juvian
Mar 22 at 17:46













I found A* library but in usage github.com/prettymuchbryce/easystarjs#usage there is grid with 0 and 1 where I believe 0 is walkable and 1 is not. Can I somehow convert my object/arrays to grid like this?

– BT101
Mar 22 at 18:46





I found A* library but in usage github.com/prettymuchbryce/easystarjs#usage there is grid with 0 and 1 where I believe 0 is walkable and 1 is not. Can I somehow convert my object/arrays to grid like this?

– BT101
Mar 22 at 18:46












1 Answer
1






active

oldest

votes


















0














I used pathFinding.js library and finding is very simple:



currentPath = finder.findPath(heroCoords.x, 
heroCoords.y,
monstersCoords[i].x,
monstersCoords[i].y,
currentGrid);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305115%2ffinding-closest-possible-coordinates%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I used pathFinding.js library and finding is very simple:



    currentPath = finder.findPath(heroCoords.x, 
    heroCoords.y,
    monstersCoords[i].x,
    monstersCoords[i].y,
    currentGrid);





    share|improve this answer



























      0














      I used pathFinding.js library and finding is very simple:



      currentPath = finder.findPath(heroCoords.x, 
      heroCoords.y,
      monstersCoords[i].x,
      monstersCoords[i].y,
      currentGrid);





      share|improve this answer

























        0












        0








        0







        I used pathFinding.js library and finding is very simple:



        currentPath = finder.findPath(heroCoords.x, 
        heroCoords.y,
        monstersCoords[i].x,
        monstersCoords[i].y,
        currentGrid);





        share|improve this answer













        I used pathFinding.js library and finding is very simple:



        currentPath = finder.findPath(heroCoords.x, 
        heroCoords.y,
        monstersCoords[i].x,
        monstersCoords[i].y,
        currentGrid);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 13:30









        BT101BT101

        2092626




        2092626





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305115%2ffinding-closest-possible-coordinates%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현