• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# point in a slice of a circle?

This topic is 6179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, for a routine where I want to be able to determine if a unit can see another unit2 I need to check if a certain point (2d) lies withing in an a of a circle....for example the unit2 is standing at point (2, 4) another unit is at point (0,0) and is looking at 0 degrees (straight forward) the unit can see 5 points away in an angle of 45 degrees...know I want to know if the unit can see unit2 at (2, 4) so how would I do this? Chris

##### Share on other sites
to find the angle between the two points use atan( (p2.y-p1.y)/(p2.x-p1.x)). This will return the angle in radians. (multiply times 180/PI if you prefer degrees) The angle could be negative, or in another quadrant so you need to check the sign to find which quadrant it is in, and wrap around by adding 360 if it is negative. Then you can just check if it is within your target angle +/- some odd degrees.

##### Share on other sites
atan2() would allow you to skip the check for the right quadrant. It wouldn''t take much to write your own two parameter atan function, but it would be somewhat pointless when there is already one in the run-time library.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×