Home > Mobile >  Is point inside a circle part (2D cone)
Is point inside a circle part (2D cone)

Time:06-25

I need help on how to determine if a point "D" is inside a part of a circle (cone of 180°) of radius "R", center "B". As for the direction of the cone I don't know how to explain it with words so I made a sketch but basically it depends on another point "A".

sketch

An explanation would be good enough but I'm not very good at maths so if you could give me a pseudo code it would be perfect!

Thanks !

CodePudding user response:

What you are looking for is the angle ψ below, to test if it is within certain limits (like /- 90°)

fig1

This can be done by finding the angle ψ between the vectors B-A and D-B.

The angle between them is found using the following dot and cross product rules

fig2 fig3

and the pseudocode using the atan2(dy,dx) function that must programming environments have

v_1.x = B.x-A.x
v_1.y = B.y-A.y
v_2.x = D.x-B.x
v_2.y = D.y-B.y

ψ = atan2( (v_1.x*v_2.y - v_1.y*v_2.x), (v_1.x*v_2.x   v_1.y*v_2.y) )

Note that the result is within and π covering all 4 quadrants

Now just check if abs(ψ) <= π/2.

Take a note of the definition of atan2 since some environments define it as atan2(dx,dy) and some as atan2(dy,dx), where the angle is measured such that dx=r*cos(ψ) and dy=r*sin(ψ).

  • Related