0
$\begingroup$

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.

$\endgroup$
7
$\begingroup$

Use RegionMember:

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}}]
}]

enter image description here

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

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

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