Zermelo
Junior Member
- Joined
- Jan 7, 2021
- Messages
- 148
Hello, let there be a triangle ABC in the Cartesian plane - A(x1, y1), B(x2, y2), C(x3, y3) are the vertices - and let's consider a point [math]X (x_0, y_0)[/math] outside of the triangle. I want to find the minimum distance from point X to the triangle ABC. My thoughts are: let's measure the distance of point X to the vertices A, B, C, and then measure the distance of X to each of the triangle's sides. Then the distance is the minimum of these measures. But my problem is, how to determine the distance from the triangle's sides?
I can easily compute the distance of the point X to a line connecting points A, B, aka it's the distance of X to the projection of X to the line. But the projected point doesn't have to be on the triangle's side, that's what I can't solve. Is there any way to check if the projected point is indeed on a triangle's side? My first hunch is checking if the projected point (xp, yp) satisfies [math]min\{x_1, x_2, x_3\} < x_p < max\{x_1, x_2, x_3\} \land min\{y_1, y_2, y_3\} < y_p < max\{y_1, y_2, y_3\}[/math]. Is there any other way of checking this? Or even better, is there a whole other way of solving this problem? Keep in mind that I have to program this algorithm so it works for any triangle, so sketching it out is not a viable solution. I had an idea of seperating the outside of the triangle to 6 regions, and using the distance to lines or vertices depending on which region the point X belongs to, but this seems like a lot harder thing to do abstractly, for every possible triangle.
I can easily compute the distance of the point X to a line connecting points A, B, aka it's the distance of X to the projection of X to the line. But the projected point doesn't have to be on the triangle's side, that's what I can't solve. Is there any way to check if the projected point is indeed on a triangle's side? My first hunch is checking if the projected point (xp, yp) satisfies [math]min\{x_1, x_2, x_3\} < x_p < max\{x_1, x_2, x_3\} \land min\{y_1, y_2, y_3\} < y_p < max\{y_1, y_2, y_3\}[/math]. Is there any other way of checking this? Or even better, is there a whole other way of solving this problem? Keep in mind that I have to program this algorithm so it works for any triangle, so sketching it out is not a viable solution. I had an idea of seperating the outside of the triangle to 6 regions, and using the distance to lines or vertices depending on which region the point X belongs to, but this seems like a lot harder thing to do abstractly, for every possible triangle.