Skip to main content

computational geometry - Is there a numerical method/built-in to calculate the boundary of a set of graphs?


Recently, I encounted a geometry problem in my work. For a curve-family that owns the following parametric equation: $$E(t,\theta)= \begin{pmatrix} x_E(t,\theta) \\ y_E(t,\theta) \end{pmatrix}$$


where, $\theta \in [0,2\pi]$ and $t\in [0,1]$


Traditionally, I could apply the envelope theory to solve the points that located in the boundary.


$$\frac{\partial x_E(t,\theta)}{\partial t}\frac{\partial y_E(t,\theta)}{\partial \theta}-\frac{\partial x_E(t,\theta)}{\partial \theta}\frac{\partial y_E(t,\theta)}{\partial t}=0 \qquad (1)$$


So for the fixed $t_i$, the parameter of envelope-point $\theta_i$ could be solved with equation$(1)$


Here is a normal instance that using above theory(denoted envelope-point with $\color{blue} \square$).


enter image description here



Obvisouly, I can connect $P_{0,1}, P_{1,1}, \dots P_{4,1}$ and $P_{0,2},P_{1,2},\dots P_{4,2}$ in sequence to achieve the boundary/envelope.


However, for the complicated case, there are only some envelope-points(denoted with $\color{blue} \square$) on the boundary/envelope. That is, the envelope theory will unapplicable.


enter image description here


So my question is:



  • Is there a numerical method/built-in to calculate the boundary?(and achieve the coordinates of points that located on the boundary)




Update


Here are some data



coeff = {{{0., -5., 0}, {-5.2203, 0., 1.7945}}, 
{{-0.4188, -4.9846, 0.1071}, {-5.3218, 0.3923, 2.0267}},
{{-0.8583, -4.9384, 0.1765}, {-5.4189, 0.7822, 2.3088}},
{{-1.3234, -4.8618, 0.2192}, {-5.5122, 1.1672, 2.6475}},
{{-1.8203, -4.7553, 0.2473}, {-5.6022, 1.5451, 3.0486}},
{{-2.3568, -4.6194, 0.2742}, {-5.6897, 1.9134, 3.5173}},
{{-2.9427, -4.455, 0.3147}, {-5.7755, 2.27, 4.0578}},
{{-3.5912, -4.2632, 0.3857}, {-5.8604, 2.6125, 4.6738}},
{{-4.3197, -4.0451, 0.5068}, {-5.9456, 2.9389, 5.368}},
{{-5.1524, -3.802, 0.7017}, {-6.0327, 3.2472, 6.1428}},

{{-6.1237, -3.5355, 1.}, {-6.1237, 3.5355, 7.}}};

coeff2 = {{{0., -5., 0}, {-5.2203, 0., 1.7945}},
{{-0.4188, -4.9846, 0.3754}, {-5.3218, 0.3923, 1.8307}},
{{-0.8583, -4.9384, 0.6792}, {-5.4189, 0.7822, 1.8663}},
{{-1.3234, -4.8618, 0.9146}, {-5.5122, 1.1672, 1.9093}},
{{-1.8203, -4.7553, 1.0855}, {-5.6022, 1.5451, 1.9672}},
{{-2.3568, -4.6194, 1.1959}, {-5.6897, 1.9134, 2.047}},
{{-2.9427, -4.455, 1.2502}, {-5.7755, 2.27, 2.1556}},
{{-3.5912, -4.2632, 1.2528}, {-5.8604, 2.6125, 2.2995}},

{{-4.3197, -4.0451, 1.2087}, {-5.9456, 2.9389, 2.4846}},
{{-5.1524, -3.802, 1.1229}, {-6.0327, 3.2472, 2.7164}},
{{-6.1237, -3.5355, 1.}, {-6.1237, 3.5355, 3.}}};

which are the coefficient of ellipse. Namely, {{a,b,c},{d,e,f}}


$\begin{cases} x=a \sin\theta+b \cos\theta +c \\ y=d \sin\theta +e \cos\theta +f \\ \end{cases}$


ellipsePoints[{mat1_, mat2_}] :=
{mat1.{Sin[#], Cos[#], 1},
mat2.{Sin[#], Cos[#], 1}} & /@ Range[0, 2 Pi, 0.02 Pi]


points = Flatten[ellipsePoints /@ coeff, 1];
points2 = Flatten[ellipsePoints /@ coeff2, 1];

Thanks for RunnyKine's alphaShapes2D[] with diferent threshold :1,3


reg = RegionBoundary@alphaShapes2D[points, 1];
Show[{reg, ListPlot[points, AspectRatio -> Automatic]}, Axes -> True]

reg2 = RegionBoundary@alphaShapes2D[points, 3];
Show[{reg2, ListPlot[point2s, AspectRatio -> Automatic]}, Axes -> True]


enter image description here



Answer



Here is another answer inspired by Rahul's answer that also uses only built-in functions:


RegionBoundary @ DiscretizeGraphics @ Graphics[Polygon /@ ellipsePoints /@ coeff]

Mathematica graphics


RegionBoundary@
DiscretizeGraphics@Graphics[Polygon /@ ellipsePoints /@ coeff2]

enter image description here



RegionBoundary@
DiscretizeGraphics@
Graphics[Polygon /@
Table[
Table[
RotationMatrix[m].{2 + 5 Cos[x], 3 + 6 Sin[x]},
{x, 0, 2 Pi, 0.02 Pi}], {m, 0, Pi, Pi/20}]]

enter image description here


Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...