how can I check that a point is in a triangle?

混江龙づ霸主 提交于 2019-12-04 02:38:50

问题


Hi also consider that I have 4 points and I will have 4 triangles how can I check these four triangles for each point that is the point within the triangles or not. thanks


回答1:


Polygon implements the Shape interface, which provides several contains() methods. Here's a simple example.




回答2:


You need to find the equation for the line created by each side of the triangle, and then for each side, check whether the point in question is on the same side of this line as the third point in the triangle. If all three are on the same side, it is within the triangle. Add bounds checking for cases of a point falling ON one of your sides.



来源:https://stackoverflow.com/questions/4207318/how-can-i-check-that-a-point-is-in-a-triangle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!