I have a planar convex polygonal region Rc
. I would like to triangulate it such that
every triangle is nonobtuse. I was hoping that the MeshRefinementFunction
option would indeed "refine the simplex" when the function (fob
in my case) returns T, to quote the documentation.
R = DiscretizeRegion[Rc
, MeshRefinementFunction -> fob
, MeshQualityGoal -> "Maximal"
, PerformanceGoal -> "Quality"]
But the above code does not in fact refine every triangle. E.g., 60 of the 478 triangles below are obtuse—not terribly obtuse, but obtuse (max angle approx. $113^\circ$).
I am aware that it is not straightforward to refine for nonobtuseness. Does the meshing function just give up after a few tries?
By request, some ugly code for fob
:
TriLengths[{a_, b_, c_}] := Module[{A, B, C},
A = Sqrt[(b - a).(b - a)] // N;
B = Sqrt[(c - b).(c - b)] // N;
C = Sqrt[(a - c).(a - c)] // N;
Return[{A, B, C}]
];
TriAngles[{a_, b_, c_}] :=
Module[{A, B, C, \[Alpha], \[Beta], \[Gamma]},
{A, B, C} = TriLengths[{a, b, c}];
\[Beta] = ArcCos[ (C^2 + A^2 - B^2)/(2 C A)] // N;
\[Gamma] = ArcCos[ (A^2 + B^2 - C^2)/(2 A B)] // N;
\[Alpha] = ArcCos[ (B^2 + C^2 - A^2)/(2 B C )] // N;
Return[ { \[Beta], \[Gamma], \[Alpha]}];
];
fob[vlist_, area_] := Module[{\[Alpha], \[Beta], \[Gamma]},
{\[Alpha], \[Beta], \[Gamma]} = TriAngles[vlist] // N;
If[Max[{\[Alpha], \[Beta], \[Gamma]}] <= \[Pi]/2,
Return[False],
Return[True](*obtuse:refine*)
]];
(*Test*)
{a, b, c} = {{0, 0}, {0, 1}, {-1, 2}};
Print[TriAngles[{a, b, c}]];
fob[{a, b, c}, 999]
fob
is? $\endgroup$tang[v1_?VectorQ, v2_?VectorQ, v3_?VectorQ] := Module[{n1 = Normalize[v1 - v2], n2 = Normalize[v3 - v2]}, 2 ArcTan[Norm[n1 + n2], Norm[n1 - n2]]]
. This determines the angle at vertexv2
; you can then usetang @@@ Partition[pts, 3, 1, 2]
to get all the angles. $\endgroup$