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$

closed as off-topic by Carl Woll, Daniel Lichtblau, LCarvalho, Henrik Schumacher, MarcoB Jun 20 at 6:01

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

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
  • $\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.