thank youvery much but,if there is a coordinates of triangle (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) how to determine the points of the triangle object belongs
I have a list of triangles of the mesh and point cloud. the question is :how to determine each point belongs to a triangle
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a list of triangles of the mesh and point cloud. the question is :how to determine each point belongs to a triangle
채택된 답변
Roger Stafford
2016년 2월 26일
Let the points (x1,y1), (x2,y2), and (x3,y3) be the three vertices of a triangle, and let (x,y) be some arbitrary point. Define:
c1 = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
p1 = (x2-x) *(y3-y) -(x3-x) *(y2-y) ;
c2 = (x3-x2)*(y1-y2)-(x1-x2)*(y3-y2);
p2 = (x3-x) *(y1-y) -(x1-x) *(y3-y) ;
c3 = (x1-x3)*(y2-y3)-(x2-x3)*(y1-y3);
p3 = (x1-x) *(y2-y) -(x2-x) *(y1-y) ;
Then the point (x,y) lies inside or on the triangle if:
sign(c1)*sign(p1) >= 0 & sign(c2)*sign(p2) >= 0 & sign(c3)*sign(p3) >= 0
댓글 수: 2
Roger Stafford
2016년 2월 27일
편집: Roger Stafford
2016년 2월 27일
Two points.
1) My apologies! I made the computations more complicated than they need be. The quantities c1, c2, and c3 are all identically equal, so you need only calculate one of them. They are each twice the signed area of the (straight-lined) triangle. with the sign determined by whether (x1,y1), (x2,y2), (x3,y3) are in counterclockwise or clockwise order around the triangle.
2) In answer to your question of triangles in three-dimensional space, that is a somewhat different situation. Your arbitrary point (x,y,z) has to be shown to lie in the same plane as that of the triangle, if that is what you mean by "belongs to", in addition to satisfying three inequalities. Do you want me to show how this is to be determined?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!