28 Apr 2021

How to test if a point is inside a sector?

收藏到CSDN网摘

If we have a sector (partial circle) defined by the centre C, radius R, starting angle point S, and ending angle point E. How can we test if a given point P is inside or outside the sector? The idea is to define 2 function: the one is to test if one vector can be obtained by rotating from another vector clockwise (or anti-clockwise if needed); the other is to test if the distance from the point to the centre is less than or equal to the radius. Then, the problem becomes 3 tests: (1) clockwise rotation from starting vector to the point; (2) anti-clockwise rotation from the ending vector to the point; and (3) the distance from P to C is less than R.

How to test if a point is inside of a triangle?

收藏到CSDN网摘

To determine if a point P is inside or outside a given triangle defined by 3 vertices P1, P2, and P3. The edges can be calculated first as 3 vectors: P12 = P1-P2; P23 = P2-P3; P31 = P3-P1. Then, its a simple task.