For example we have a circle and triangle. We need to check if at given $(m, n)$ coordinate triangle is intersecting with circle (area).

Circle center is fixed at $(100, 100)$ with radius $R = 50$. Triangle corners coordinates vary: $$ A(x_1, y_1)\quad B(x_2, y_2)\quad C(x_3, y_3). $$

Circle equation is: $(x - 100)^2 + (y - 100)^2 = 50^2$. If $(m - 100)^2 + (n - 100)^2 - 50^2$ is below or equal zero, it means that $(m, n)$ coordinate is inside circle.

Now I want to extend this to one/simple formula, which on a simple more/less/equal condition would evaluate if $(m, n)$ is inside both circle and triangle. Is this possible? What triangle formula should I use and what condition should I look for?

You might ask why I want to construct simple formula. Well, I am working on a problem, where I want to brutally scan certain coordinates region and to each coordinate assign number from which it would be obvious if this coordinate is both inside triangle and circle or not.

I have read (triangle case) that I should check barycentric coordinates for equality greater than zero. I did understand how it works, just not sure how could I simplify everything into one equation.

EDIT2: http://totologic.blogspot.fr/2014/01/accurate-point-in-triangle-test.html

  • $\begingroup$ Hint: a triangle is comprised of three piecewise lines. When you have a boundary that's piecewise, there's no easy way of simplifying - you're not doing a line integral, so I don't think Green's Theorem would be very helpful. Wrap equations with dollar signs to get math formatting. Edit: Are you asking for a way to see what points on the circle intersect with the triangle, a way of finding which segments of the triangle lie within the circle, or something else? $\endgroup$ – Eli Berkowitz Dec 10 '15 at 2:01

A "single equation" way to find if point $P=(m,n)$ lies inside triangle $ABC$ is the following: $$ |(x_2 - x_1) (y_1 - n) - (x_1 - m) (y_2 - y_1)| +\\ |(x_3 - x_2) (y_2 - n) - (x_2 - m) (y_3 - y_2)| +\\ |(x_1 - x_3) (y_3 - n) - (x_3 - m) (y_1 - y_3)| =\\ |(x_1 - x_3) (y_3 - y_2) - (x_3 - x_2) (y_1 - y_3)| $$ The three expressions inside absolute value on the LHS are twice the areas of triangles $ABP$, $BCP$ and $CAP$. Their sum is equal to twice the area of $ABC$, which is on the RHS, if an only if $P$ is inside $ABC$, otherwise it is greater.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.