Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspxI know it’s been a little while since my last post, and I apologize. I’ll try and keep the posts a little more frequent moving forward.
In the last post, we briefly encountered barycentric coordinates and loosely defined them as the coefficientsen-USTelligent Evolution Platform Developer Build (Build: 5.6.50428.7875)re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10496107Sat, 01 Feb 2014 16:03:11 GMT91d46819-8472-40ad-a661-2c78acb4018c:10496107Reza Nourai - MSFT<p>Nice article! I like the real world examples of accuracy problems.</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10496107" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10492767Sat, 25 Jan 2014 21:29:05 GMT91d46819-8472-40ad-a661-2c78acb4018c:10492767Logic<p>I wrote a complete article about point in triangle test. It shows the barycentric, parametric and dot product based methods.</p>
<p>Then it deals with the accuracy problem occuring when a point lies exactly on one edge (with examples). Finally it exposes a complete new method based on point to edge distance.</p>
<p><a rel="nofollow" target="_new" href="http://totologic.blogspot.fr/2014/01/accurate-point-in-triangle-test.html">totologic.blogspot.fr/.../accurate-point-in-triangle-test.html</a></p>
<p>Enjoy !</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10492767" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10487090Sun, 05 Jan 2014 16:59:31 GMT91d46819-8472-40ad-a661-2c78acb4018c:10487090Reza Nourai - MSFT<p>Thanks for catching the spelling error :)</p>
<p>Yes, you're right. Since each are positive and we show their sum <= 1, we don't need to verify that r & t are individually <= 1. I've updated the post to reflect that.</p>
<p>Thanks!</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10487090" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10487081Sun, 05 Jan 2014 15:24:48 GMT91d46819-8472-40ad-a661-2c78acb4018c:10487081Valentine<p>And correct "piont" to "point" and "> 0" to ">= 0" in comment :)</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10487081" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10487079Sun, 05 Jan 2014 15:10:46 GMT91d46819-8472-40ad-a661-2c78acb4018c:10487079Valentine<p>return (r <= 1 && t <= 1 && r + t <= 1);</p>
<p>can be replaced by</p>
<p>return (r + t <= 1);</p>
<p>because r and t are both >=0.</p>
<p>Nice post!</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10487079" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10449694Tue, 17 Sep 2013 05:37:09 GMT91d46819-8472-40ad-a661-2c78acb4018c:10449694Reza Nourai - MSFT<p>Thanks Michael, glad that it helped.</p>
<p>If your goal is to test that the projection of a point onto a 3D triangle is inside that triangle, then you can make it work for 3D with very little modification. The points A, B, and C are all going to be coplanar since they are on a triangle. The values s and t are ratios, which hold up just fine in 3D as well. The only interesting part is the point P that you're testing. You'll want to find the projection of P onto the plane of ABC, say we call that Q, and then you can test that Q is inside of ABC using this method.</p>
<p>While I haven't tried it, it seems reasonable that you might be able to extend this further into 3D by considering a 3D point and a tetrahedron instead of a triangle. You could just pick a vertex A, and then take the 3 edge vectors that extend from that vertex, call then u, v, and w. Then you'd find the ratios a, b, and c along each edge vector (instead of s and t) using similar derivation to the above.</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10449694" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10449608Mon, 16 Sep 2013 20:34:05 GMT91d46819-8472-40ad-a661-2c78acb4018c:10449608Michael<p>Great post. Finally I understood some math I was missing.</p>
<p>So would this code be working in 3D, without projecting triangles to 2D plane, or should I use something different. For example: use Crammer rule to solve for 3D space?</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10449608" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10206426Mon, 05 Sep 2011 19:38:06 GMT91d46819-8472-40ad-a661-2c78acb4018c:10206426Reza Nourai - MSFT<p>Hi Vektor, I think my last reply got lost so I'll reply again.</p>
<p>You're absolutely right. You pointed out a pretty big oversight on my part and I've corrected the blog to reflect the right solution. Since we are taking the norm of the equation, the signs of r and t got lost, so checking for > 0 at the end was meaningless. I've corrected it to determine the signs earlier before taking the norm, with an explanation of how we do that.</p>
<p>Thanks for catching that!</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10206426" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10206177Mon, 05 Sep 2011 07:16:28 GMT91d46819-8472-40ad-a661-2c78acb4018c:10206177vektor<p>Hi,</p>
<p>Nice post. But I have a question. According to your post, it appears that r and t never go below 0 because you are only working with vector lengths. Ideally, when we test a point outside the triangle, either or both the values of r and t must be < 0. </p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10206177" width="1" height="1">re: Barycentric Coordinates and Point in Triangle Testshttp://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx#10195351Fri, 12 Aug 2011 22:54:48 GMT91d46819-8472-40ad-a661-2c78acb4018c:10195351BakerCo<p>Thanks a lot your blog is very helpful to me please keep it up I am looking forward to the physics stuff. Thanks again</p>
<p>BakerCo</p>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10195351" width="1" height="1">