How to obtain Barycentric Coordinates of a point in a triangle?
Show older comments
Hello,
I'm trying to find barycentric coordinates of a point p in the triangle with coordinates shown in matrix P, where coordinates of the point are in the last row of the matrix. I have used function cartesianToBarycentric to do this, but I get B = 0 0 1 as the output, which is the barycentric coordinate of the third vertex. There is my code:
P = [-1.17300000000000 -0.952000000000000
-0.199000000000000 1.04800000000000
1.05800000000000 -0.952000000000000
-0.100000000000000 -0.443000000000000]
T = [1 4 3
1 4 2
3 4 2]
TR = triangulation(T,P)
ti = 1
PC = TR.Points(TR.ConnectivityList(1,3),:)
B = cartesianToBarycentric(TR, ti, PC)
Output: B = 0 0 1
I have tried changing the second parameter of the function PC = TR.ConnectivityList(1,3) from 1 to 3, but I still get the initial barycentric coordinates of the three corners. Zero and four doesn't work for the second parameter even though there are 4 vertices.
Can anyone help me with this as I'm completely new with MATLAB. I would be grateful.
Accepted Answer
More Answers (2)
Roger Stafford
on 3 Aug 2013
I am not familiar with the use of the 'cartesianToBarycentric' function, but I do know how to find the barycentric coordinates of a point in a triangle. In your case where the vertices are the first three rows of P and the point in question the fourth row, it would be the solution to the following three linear equations in three unknowns:
-1.173*b1 - 0.199*b2 + 1.058*b3 = -0.1
-0.952*b1 + 1.048*b2 - 0.952*b3 = -0.443
b1 + b2 + b3 = 1
In matlab this can be solved using the matrix division operator:
b = [P(4,:),1]/[P(1:3,:),ones(3,1)];
and the solution is
b = 0.37565822501121 , 0.25450000000000 , 0.36984177498879
Atia Najafi
on 19 Sep 2018
0 votes
Hi Roger Stafford can you please elaborate on your solution? I need to implement this function in simulink, so have to write 'triangulation' and ''cartesianToBarycentric' from scratch. I look forward to hearing back from you. Atia
Categories
Find more on Triangulations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!