# Analytic geometry - triangle [closed]

I have three points: A[1, 2]; B[3, 5] and C[5, 7]

I have some random points, like this: E [4, 4] etc.

I need to check if these random point are a part of the ABC triangle, or not.

## 1 Answer

rmf = RegionMember@Triangle[{{1,2},{3,5},{5,7}}];


Random points:

pts = RandomReal[7, {10^3, 2}];


Use the RegionMember function to find out which points are a part of the triangle:

Tally[rmf @ pts]


{{False, 972}, {True, 28}}

Visualization:

Graphics[{
Red, Point[Pick[pts, rmf@pts, False]],
Blue, Point[Pick[pts, rmf@pts, True]],
Black, RegionBoundary@Triangle[{{1,2},{3,5},{5,7}}]
}]


Sounds like you should ask this question on the Math StackExchange site. To get the relevant equations using Mathematica you could do:

RegionMember[Triangle[{{1,2},{3,5},{5,7}}], {x, y}]


(x | y) ∈ Reals && -(5/2) (-1 + x) + 2 (-2 + y) >= 0 && 2 + 3/2 (-1 + x) - y >= 0 && 3 - x + 2 (-2 + y) - y <= 1

• In which language is this code written? – Cséfalvay Bálint Jun 11 at 19:41
• @CséfalvayBálint It is written in Mathematica of course. What do you expect on the Mathematica StackExchange site? – Carl Woll Jun 11 at 19:42
• Then I chose a wrong side, because I need mathematical equation, or something like that. – Cséfalvay Bálint Jun 11 at 19:52