• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to check if a point is inside a 2D cone

Status
Not open for further replies.
Level 5
Joined
May 2, 2015
Messages
109
I've been wondering, how to check if a point is inside a 2D cone.
My idea is,
  1. Check if the point is within radius by using group.
  2. Define angleStart and angleEnd and check if the point is within it.
Everything goes fine until I tested in with 270-90 degree (not a cone actually, a hemi-sphere). The system tell me that the point is outside.

Any solution?
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
Can you post your code?

I was doing something similar recently, and found out that Atan2 is defined between -180 and 180 rather than 0 and 360.
So I was getting some incorrect results when I went to a particular angle.

You may be experiencing a similar situation where a function is limited to values you're not expecting.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
Obviously if distance < R, then check (Cos((AngleToCenterOfCone - AngleToPoint))) Greater than or equal to (Cos(HALF_ARC_LENGTH)).
This will technically be a sector, not a cone, but it really doesn't matter that much. As seen used here.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I apply this check in my GroupAddUnitsInCone() function:
JASS:
            set difference = DenormalizeAngleDeg(AngleBetweenCoordinatesDeg(x, y, GetUnitX(FoG), GetUnitY(FoG)) - direction)
            if difference > -size and difference < size then
                call GroupAddUnit(whichGroup, FoG)
            endif
(This is applied after a GroupEnumUnitsInRange() so the range check is already applied.)
What it basically does is it takes the angle from the origin point to the point that you want to check.
Then substract the direction of your cone.
Then make sure that the angle is in -180 to 180 format.
(Aka, if your angle is above 180, then substract 360.)
Then check if the result is closer to 0 than the maximum angle that is allowed (from the center to the edge, so 90-270 would have a 90 degrees maximum angle).)
 
Status
Not open for further replies.
Top