• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

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

Status
Not open for further replies.
Level 6
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?
 
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.
 
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.
Back
Top