フィルターのクリア

How to obtain Barycentric Coordinates of a point in a triangle?

12 ビュー (過去 30 日間)
WellEatenPanda
WellEatenPanda 2013 年 8 月 2 日
回答済み: Atia Najafi 2018 年 9 月 19 日
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.

採用された回答

Roger Stafford
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.
  1 件のコメント
WellEatenPanda
WellEatenPanda 2013 年 8 月 4 日
Thank you for explaining the meaning of the variable ti as it was not clear in the documentation and for showing how to copy the matrix elements.
If you would plot the triangulation with triplot(), you would see a triangle made out of 3 faces, which is where the probelm lied as I misunderstood the shape that the triangle has to take.

サインインしてコメントする。

その他の回答 (2 件)

Roger Stafford
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
  2 件のコメント
WellEatenPanda
WellEatenPanda 2013 年 8 月 3 日
Yes, I did do that on paper, but I would like to use that function so I could quickly check my answers and do that for 3D coordinates, if possible.
WellEatenPanda
WellEatenPanda 2013 年 8 月 3 日
Finally I managed to get the function working. I created the triangle from 3 faces, when only one face was needed and the fourth point should've been in matrix PC. It was kind of obvious, I don't know why I did that.
Thank you for the help and for clarifying the coordinates as I'm just starting to learn this.

サインインしてコメントする。


Atia Najafi
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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by