Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:04:10+00:00 2026-05-11T07:04:10+00:00

I have not marked this question Answered yet. The current accepted answer got accepted

  • 0

I have not marked this question Answered yet.
The current accepted answer got accepted automatically because of the Bounty Time-Limit


With reference to this programming game I am currently building.

As you can see from the above link, I am currently building a game in where user-programmable robots fight autonomously in an arena.


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):

alt text http://img21.imageshack.us/img21/7839/robotdetectionrg5.jpg

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.

The bots are just canvases that are constantly translating on the Battle Arena (another canvas).

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.

I hope that someone can guide me to what math is involved in achieving this problem.


[UPDATE]

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 :

alt text http://img12.imageshack.us/img12/7416/examplebattle2.png

In the above scenario, Bot 1 is checking if he can see Bot 2. Here are the details (according to Waylon Flinn’s answer):

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 < orientation + angleOfSight/2) && (azimuth > orientation - angleOfSight/2)        = (3.0141873380511295 < 3.3 + 0.349065850398865895) && (3.0141873380511295 > 3.3 - 0.349065850398865895)        = true 

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.

What am I doing wrong in the above calculations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:04:10+00:00Added an answer on May 11, 2026 at 7:04 am

    The angle between the robots is arctan(x-distance, y-distance) (most platforms provide this 2-argument arctan that does the angle adjustment for you. You then just have to check whether this angle is less than some number away from the current heading.


    Edit 2020: Here’s a much more complete analysis based on the updated example code in the question and a now-deleted imageshack image.

    1. Atan2: The key function you need to find an angle between two points is atan2. This takes a Y-coordinate and X-coordinate of a vector and returns the angle between that vector and the positive X axis. The value will always be wrapped to lie between -Pi and Pi.

    2. Heading vs Orientation: atan2, and in general all your math functions, work in the ‘mathematical standard coordinate system’, which means an angle of ‘0’ corresponds to directly east, and angles increase counterclockwise. Thus, an ‘mathematical angle’ of Pi / 2 as given by atan2(1, 0) means an orientation of ’90 degrees counterclockwise from due east’, which matches the point (x=0, y=1). ‘Heading’ is a navigational idea that expresses orientation is a clockwise angle from due north.

      • Analysis: In the now-deleted imageshack image, your ‘heading’ of 191 degrees corresponded to a south-south-west direction. This actually an trigonometric ‘orientation’ of -101 degrees, or -1.76. The first issue in the updated code is therefore conflating ‘heading’ and ‘orientation’. you can get the latter from the former by orientation_degrees = 90 - heading_degrees or orientation_radians = Math.PI / 2 - heading_radians, or alternatively you could specify input orientations in the mathematical coordinate system rather than the nautical heading coordinate system.
    3. Checking that an angle lies between two others: Checking that an vector lies between two other vectors is not as simple as checking that the numeric angle value is between, because of the way the angles wrap at Pi/-Pi.

      • Analysis: in your example, the orientation is 3.3, the right edge of view is orientation 2.95, the left edge of view is 3.65. The calculated azimith is 3.0141873380511295, which happens to be correct (it does lie between). However, this would fail for azimuth values like -3, which should be calculated as ‘hit’. See Calculating if an angle is between two angles for solutions.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer This works for me: int DoDOS(string parms) { Process p=new… May 11, 2026 at 3:53 pm
  • added an answer There are lots of questions here about creating 'Business' IDs… May 11, 2026 at 3:53 pm
  • added an answer To be able to create an index view, the view… May 11, 2026 at 3:53 pm

Related Questions

I have a question about this question . I posted a reply there but
I have posted a question before, Moving away from VSS , in which I
Code styling question here. I looked at this question which asks if the .NET
Background I am trying to create a copy of a business object I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.