Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Finding an element along a path
    text
    copied!<p><strong>I have not marked this question Answered yet.<br> The current accepted answer got accepted automatically because of the Bounty Time-Limit</strong></p> <hr> <p><em>With reference to <a href="https://stackoverflow.com/questions/505040/developing-a-robocode-type-game-with-net-for-a-school-assignment">this programming game</a> I am currently building.</em></p> <p>As you can see from the above link, I am currently building a game in where user-programmable robots fight autonomously in an arena.</p> <hr> <p>Now, I need a way to detect if a robot has detected another robot in a particular angle (depending on where the turret may be facing):</p> <p><a href="http://img21.imageshack.us/img21/7839/robotdetectionrg5.jpg" rel="nofollow noreferrer">alt text http://img21.imageshack.us/img21/7839/robotdetectionrg5.jpg</a></p> <p>As you can see from the above image, I have drawn a kind of point-of-view of a tank in which I now need to emulate in my game, as to check each point in it to see if another robot is in view.</p> <p>The bots are just canvases that are constantly translating on the Battle Arena (another canvas). </p> <p>I know the heading the turret (the way it will be currently facing), and with that, I need to find if there are any bots in its path(and the path should be defined in kind of 'viewpoint' manner, depicted in the image above in the form of the red 'triangle'. I hope the image makes things more clear to what I am trying to convey. </p> <p>I hope that someone can guide me to what math is involved in achieving this problem.</p> <hr> <p><strong>[UPDATE]</strong></p> <p>I have tried the calculations that you have told me, but it's not working properly, since as you can see from the image, bot1 shouldn't be able to see Bot2 . Here is an example :</p> <p><a href="http://img12.imageshack.us/img12/7416/examplebattle2.png" rel="nofollow noreferrer">alt text http://img12.imageshack.us/img12/7416/examplebattle2.png</a></p> <p>In the above scenario, Bot 1 is checking if he can see Bot 2. Here are the details (according to <a href="https://stackoverflow.com/questions/559437/wpf-finding-an-element-along-a-path/632903#632903">Waylon Flinn's answer</a>):</p> <pre><code>angleOfSight = 0.69813170079773179 //in radians (40 degrees) orientation = 3.3 //Bot1's current heading (191 degrees) x1 = 518 //Bot1's Center X y1 = 277 //Bot1's Center Y x2 = 276 //Bot2's Center X y2 = 308 //Bot2's Center Y cx = x2 - x1 = 276 - 518 = -242 cy = y2 - y1 = 308 - 277 = 31 azimuth = Math.Atan2(cy, cx) = 3.0141873380511295 canHit = (azimuth &lt; orientation + angleOfSight/2) &amp;&amp; (azimuth &gt; orientation - angleOfSight/2) = (3.0141873380511295 &lt; 3.3 + 0.349065850398865895) &amp;&amp; (3.0141873380511295 &gt; 3.3 - 0.349065850398865895) = true </code></pre> <p>According to the above calculations, Bot1 can see Bot2, but as you can see from the image, that is not possible, since they are facing different directions.</p> <p>What am I doing wrong in the above calculations?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload