How to calculate distance to point when there is an obstacle in the way?












1














I'm writing a genetic algorithm program where "cells" have to make their way to a point that is located behind an obstacle that they have to get to. The structure looks something like this



        target

---------------------

cell pool


where the cells come from the pool and have to get around the obstacle and make their way to the target. My question is how I should go about calculating the distance from a cell to the target? I need this because I am going to dynamically color the closest cell each frame. My guess would be to essentially find the closest edge of the obstacle (left or right side) and draw a line to that, then bee line it to the target, and add the lengths of those two lines together, but I was wondering if there was a more optimal way.



Thank you for your help!










share|cite|improve this question






















  • If you know the coordinates of the target, the cell, and the obstacle, you can stitch together two straight lines to get the distance, right? Or do you have more complicated obstacles in the way?
    – Adrian Keister
    Nov 28 at 17:43










  • Right now it's static, but the obstacle will move left to right eventually. Probably should have stated that in the OP, my apologies.
    – Tristin Baker
    Nov 28 at 17:45










  • I assume that that doesn't change the calculation now that I think of it though, because I'll still have all that info frame-by-frame.
    – Tristin Baker
    Nov 28 at 17:46










  • Ok, so I would just make two calculations. 1. $d_1=$ distance from cell to LHS of obstacle + distance from LHS of obstacle to target. 2. $d_2=$ distance from cell to RHS of obstacle + distance from RHS of obstacle to target. Then you would write $d=min(d_1, d_2).$
    – Adrian Keister
    Nov 28 at 17:51










  • Appreciate the help @AdrianKeister!
    – Tristin Baker
    Nov 28 at 17:53


















1














I'm writing a genetic algorithm program where "cells" have to make their way to a point that is located behind an obstacle that they have to get to. The structure looks something like this



        target

---------------------

cell pool


where the cells come from the pool and have to get around the obstacle and make their way to the target. My question is how I should go about calculating the distance from a cell to the target? I need this because I am going to dynamically color the closest cell each frame. My guess would be to essentially find the closest edge of the obstacle (left or right side) and draw a line to that, then bee line it to the target, and add the lengths of those two lines together, but I was wondering if there was a more optimal way.



Thank you for your help!










share|cite|improve this question






















  • If you know the coordinates of the target, the cell, and the obstacle, you can stitch together two straight lines to get the distance, right? Or do you have more complicated obstacles in the way?
    – Adrian Keister
    Nov 28 at 17:43










  • Right now it's static, but the obstacle will move left to right eventually. Probably should have stated that in the OP, my apologies.
    – Tristin Baker
    Nov 28 at 17:45










  • I assume that that doesn't change the calculation now that I think of it though, because I'll still have all that info frame-by-frame.
    – Tristin Baker
    Nov 28 at 17:46










  • Ok, so I would just make two calculations. 1. $d_1=$ distance from cell to LHS of obstacle + distance from LHS of obstacle to target. 2. $d_2=$ distance from cell to RHS of obstacle + distance from RHS of obstacle to target. Then you would write $d=min(d_1, d_2).$
    – Adrian Keister
    Nov 28 at 17:51










  • Appreciate the help @AdrianKeister!
    – Tristin Baker
    Nov 28 at 17:53
















1












1








1







I'm writing a genetic algorithm program where "cells" have to make their way to a point that is located behind an obstacle that they have to get to. The structure looks something like this



        target

---------------------

cell pool


where the cells come from the pool and have to get around the obstacle and make their way to the target. My question is how I should go about calculating the distance from a cell to the target? I need this because I am going to dynamically color the closest cell each frame. My guess would be to essentially find the closest edge of the obstacle (left or right side) and draw a line to that, then bee line it to the target, and add the lengths of those two lines together, but I was wondering if there was a more optimal way.



Thank you for your help!










share|cite|improve this question













I'm writing a genetic algorithm program where "cells" have to make their way to a point that is located behind an obstacle that they have to get to. The structure looks something like this



        target

---------------------

cell pool


where the cells come from the pool and have to get around the obstacle and make their way to the target. My question is how I should go about calculating the distance from a cell to the target? I need this because I am going to dynamically color the closest cell each frame. My guess would be to essentially find the closest edge of the obstacle (left or right side) and draw a line to that, then bee line it to the target, and add the lengths of those two lines together, but I was wondering if there was a more optimal way.



Thank you for your help!







geometry trigonometry






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Nov 28 at 17:41









Tristin Baker

61




61












  • If you know the coordinates of the target, the cell, and the obstacle, you can stitch together two straight lines to get the distance, right? Or do you have more complicated obstacles in the way?
    – Adrian Keister
    Nov 28 at 17:43










  • Right now it's static, but the obstacle will move left to right eventually. Probably should have stated that in the OP, my apologies.
    – Tristin Baker
    Nov 28 at 17:45










  • I assume that that doesn't change the calculation now that I think of it though, because I'll still have all that info frame-by-frame.
    – Tristin Baker
    Nov 28 at 17:46










  • Ok, so I would just make two calculations. 1. $d_1=$ distance from cell to LHS of obstacle + distance from LHS of obstacle to target. 2. $d_2=$ distance from cell to RHS of obstacle + distance from RHS of obstacle to target. Then you would write $d=min(d_1, d_2).$
    – Adrian Keister
    Nov 28 at 17:51










  • Appreciate the help @AdrianKeister!
    – Tristin Baker
    Nov 28 at 17:53




















  • If you know the coordinates of the target, the cell, and the obstacle, you can stitch together two straight lines to get the distance, right? Or do you have more complicated obstacles in the way?
    – Adrian Keister
    Nov 28 at 17:43










  • Right now it's static, but the obstacle will move left to right eventually. Probably should have stated that in the OP, my apologies.
    – Tristin Baker
    Nov 28 at 17:45










  • I assume that that doesn't change the calculation now that I think of it though, because I'll still have all that info frame-by-frame.
    – Tristin Baker
    Nov 28 at 17:46










  • Ok, so I would just make two calculations. 1. $d_1=$ distance from cell to LHS of obstacle + distance from LHS of obstacle to target. 2. $d_2=$ distance from cell to RHS of obstacle + distance from RHS of obstacle to target. Then you would write $d=min(d_1, d_2).$
    – Adrian Keister
    Nov 28 at 17:51










  • Appreciate the help @AdrianKeister!
    – Tristin Baker
    Nov 28 at 17:53


















If you know the coordinates of the target, the cell, and the obstacle, you can stitch together two straight lines to get the distance, right? Or do you have more complicated obstacles in the way?
– Adrian Keister
Nov 28 at 17:43




If you know the coordinates of the target, the cell, and the obstacle, you can stitch together two straight lines to get the distance, right? Or do you have more complicated obstacles in the way?
– Adrian Keister
Nov 28 at 17:43












Right now it's static, but the obstacle will move left to right eventually. Probably should have stated that in the OP, my apologies.
– Tristin Baker
Nov 28 at 17:45




Right now it's static, but the obstacle will move left to right eventually. Probably should have stated that in the OP, my apologies.
– Tristin Baker
Nov 28 at 17:45












I assume that that doesn't change the calculation now that I think of it though, because I'll still have all that info frame-by-frame.
– Tristin Baker
Nov 28 at 17:46




I assume that that doesn't change the calculation now that I think of it though, because I'll still have all that info frame-by-frame.
– Tristin Baker
Nov 28 at 17:46












Ok, so I would just make two calculations. 1. $d_1=$ distance from cell to LHS of obstacle + distance from LHS of obstacle to target. 2. $d_2=$ distance from cell to RHS of obstacle + distance from RHS of obstacle to target. Then you would write $d=min(d_1, d_2).$
– Adrian Keister
Nov 28 at 17:51




Ok, so I would just make two calculations. 1. $d_1=$ distance from cell to LHS of obstacle + distance from LHS of obstacle to target. 2. $d_2=$ distance from cell to RHS of obstacle + distance from RHS of obstacle to target. Then you would write $d=min(d_1, d_2).$
– Adrian Keister
Nov 28 at 17:51












Appreciate the help @AdrianKeister!
– Tristin Baker
Nov 28 at 17:53






Appreciate the help @AdrianKeister!
– Tristin Baker
Nov 28 at 17:53

















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
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
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3017449%2fhow-to-calculate-distance-to-point-when-there-is-an-obstacle-in-the-way%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • 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.


Use MathJax to format equations. MathJax reference.


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





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2fmath.stackexchange.com%2fquestions%2f3017449%2fhow-to-calculate-distance-to-point-when-there-is-an-obstacle-in-the-way%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen