How to obtain Barycentric Coordinates of a point in a triangle?
17 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Roger Stafford
2013-8-3
编辑:Roger Stafford
2013-8-3
I've read over the 'cartesianToBarycentric' documentation. Here's a couple of observations. a) Your matrix T does not contain the triangle [1 2 3], so 'cartesianToBarycentric' cannot reference it in finding barycentric coordinates. You need to revise T to contain that triangle before calling on 'triangulation' and set ti to that triangle. b) For your point in PC, in TR.ConnectivityList(1,3) you selected the third vertex of the first triangle, which is ID 3 in P, so naturally you will get barycentric coordinates of 0 0 1. You need to either give that fourth point of P directly without referencing TR.Points or else reference it as the ID = 4 vertex in any one of those first three triangles of T - that is, you could write TR.ConnectivityList(1,2) since that is ID 4 in your present T, for example. Here's what I would try:
T = [1 4 3
1 4 2
3 4 2
1 2 3]
TR = triangulation(T,P);
ti = 4; % The triangle in T you are referencing
PC = TR.Points(TR.ConnectivityList(1,2),:) % The point in question
or
PC = P(4,:); % Give the point directly without using TR.Points
I hope all this makes sense. This is something I have not worked with.
更多回答(2 个)
Roger Stafford
2013-8-3
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
2018-9-19
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computational Geometry 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!