Finding out if a point is inside a triangle is quite easy when coordinates are given, but how do you find out when only data available are:
- triangle's edges sizes
- distance from the point to triangle vertices
?
Finding out if a point is inside a triangle is quite easy when coordinates are given, but how do you find out when only data available are:
?
Copyright © 2021 JogjaFile Inc.
Let's call the 3 vertices of the reference triangle $A,B,C$, the unknown point $X$ and the 6 given distances $a-f$, as indicated in the picture above.
The choice of which of the 3 given triangle sides you call $a,b$ and $c$, resp., is not important, the problem is symmetric for that. However, once that is fixed, it makes a difference which of the 3 distances of X to the triangle vertices you call $d,e$ and $f$. Let's for the moment assume that you how to assign the 3 given length to the vertices.
We will also need the angles $\angle BXC = \alpha, \angle CXA = \beta$ and $\angle AXB = \gamma$ (not shown in picture).
If $X$ is inside the triangle, then $\alpha + \beta + \gamma = 360°$. If $X$ is outside of the triangle, then the larger of the 3 angles is the sum of the 2 other angles. If $X$ is on one side, one of the angles will be 180° exactly.
So we need to find the values of those 3 angles, which is easy using the cosine-theorem. For example in the $\bigtriangleup XBC$ we have
$$ a^2 = f^2 + e^2 - 2ef \cos (\alpha),$$ which can be transformed into $$\cos (\alpha) = \frac{f^2+e^2-a^2}{2ef}$$.
The cosine function is reversable in $[0,180°]$, so this gives you an easy way to calculate $\alpha$. Use the same way to calculate $\beta$ and $\gamma$, then check which condition ($\alpha + \beta + \gamma = 360°$ or the larger of the 3 angles is the sum of the other 2) checks out.
If neither is true (up to reasonable numerical accuracy), then the initial conditions are impossible. Note that the question is overdetermined. If you don't know $f$ (assuming a configuration as shown in the picture), then besides the shown point inside the triangle, $X$ could be the point that is the reflection of the shown point $X$ on the line $AB$. So with $a-e$ given, only 2 values of $f$ lead to existing configurations.
Let's come back to the initial problem of assigning the 3 values gives as 'distance of unknown point X to the vertices of the triangle' to the concrete vertices $A,B$ and $C$. There are 6 possible ways to do that (permutations), so you have to make the above calculation 6 times.
Normally I would assume that exactly one of those calculations leads to a possible configuration and the other 5 don't. Then you can use that one result from the possible configuration.
However, there might be cases where more than one permutation gives a possible result. For example, if the reference triangle is equilateral, then it doesn't matter how you assign the distances. If all possible configuration lead to the same result, good.
But I can't exclude the possibility that there might be values of $a-f$ where different permutations give possible configurations, but leading to different results: In one permutation $X$ is inside, in another it is outside. The you don't know what is true without knowing the correct permutation.