point in a slice of a circle?

Started by
1 comment, last by chris1234 22 years, 2 months ago
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
Advertisement
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.
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.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement