Clear Filters
Clear Filters

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 views (last 30 days)
I have a list of triangles of the mesh and point cloud. the question is :how to determine each point belongs to a triangle
  5 Comments

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 26 Feb 2016
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 Comments
Roger Stafford
Roger Stafford on 27 Feb 2016
Edited: Roger Stafford on 27 Feb 2016
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?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!