要生成一個非常好的圖片,而不使用無數的點,您可能需要使用包含所需區域邊界的點的非均勻分佈。這裏有一個有點像你所描述的例子。我們從三個相切的圓開始。
circPic = Graphics[{Circle[{0, Sqrt[3]}, 1],
Circle[{-1, 0}, 1], Circle[{1, 0}, 1]}]
![Mathematica graphics](https://i.stack.imgur.com/z3BzT.png)
我們寫一個布爾函數,其確定是否在該矩形的一個點{-1/2,1/2}由{0,的Sqrt [3]/2}在於所有的外圓圈並使用它在感興趣的區域生成一些點。
inRegionQ[p:{x_, y_}] := Norm[p - {1, 0}] > 1 &&
Norm[p + {1, 0}] > 1 && Norm[p - {0, Sqrt[3]}] > 1;
rectPoints = N[Flatten[Table[{x, y},
{x, -1/2, 1/2, 0.02}, {y, 0.05, Sqrt[3]/2, 0.02}], 1]];
regionPoints = Select[rectPoints, inRegionQ];
現在我們生成邊界。參數n確定我們在邊界上放置多少個點。
n = 120;
boundary = N[Join[
Table[{1 - Cos[t], Sin[t]}, {t, Pi/n, Pi/3, Pi/n}],
Table[{Cos[t], Sqrt[3] - Sin[t]}, {t, Pi/3 + Pi/n, 2 Pi/3, Pi/n}],
Table[{Cos[t] - 1, Sin[t]}, {t, Pi/3 - Pi/n, 0, -Pi/n}]]];
points = Join[boundary, regionPoints];
讓我們來看看。
Show[circPic, Graphics[Point[points]],
PlotRange -> {{-3/4, 3/4}, {-0.3, 1.3}}]
![Mathematica graphics](https://i.stack.imgur.com/SnkqU.png)
現在,我們定義一個函數,並使用ListPlot3D
嘗試繪製。
f[x_, y_] := -(1 - Norm[{x - 1, y}]) (1 - Norm[{x + 1, y}])*
(1 - Norm[{x, y - Sqrt[3]}]);
points3D = {#[[1]], #[[2]], f[#[[1]], #[[2]]]} & /@ points;
pic = ListPlot3D[points3D, Mesh -> All]
![Mathematica graphics](https://i.stack.imgur.com/K1mE5.png)
不知怎的,我們必須刪除的東西,處於區域之外。在這個特定的例子中,我們可以使用邊界上的函數爲零的事實。
DeleteCases[Normal[pic], Polygon[{
{x1_, y1_, z1_?(Abs[#] < 1/10.0^6 &)},
{x2_, y2_, z2_?(Abs[#] < 1/10.0^6 &)},
{x3_, y3_, z3_?(Abs[#] < 1/10.0^6 &)}}, ___],
Infinity]
![Mathematica graphics](https://i.stack.imgur.com/aKqJ5.png)
還不錯,但也有一對夫婦的尖點附近的問題,它絕對不是非常普遍的,因爲它使用的功能的特定屬性。如果您檢查圖片的結構,您會發現它包含GraphicsComplex
,並且該GraphicsComplex
的第一個參數中的前n個點恰好是邊界。這裏是證明:
Most /@ pic[[1, 1, 1 ;; n]] == boundary
現在的邊界有三種成分,我們要刪除由從這些組件的只是一個選擇點形成的任何三角形。以下代碼執行此操作。請注意,boundaryComponents包含那些形成邊界的點的索引,如果A是任何一個Bs的子集,則someSubsetQ [A,Bs]返回true。我們想要刪除多邊形中作爲boundaryComponents之一的子集的三角形索引。這是通過DeleteCases
命令在以下代碼中完成的。
哦,我們來添加一些裝飾吧。
subsetQ[A_, B_] := Complement[A, B] == {};
someSubsetQ[A_, Bs_] := Or @@ Map[subsetQ[A, #] &, Bs];
boundaryComponents = Partition[Prepend[Range[n], n], 1 + n/3, n/3];
Show[pic /. Polygon[triangles_] :> {EdgeForm[Opacity[0.3]],
Polygon[DeleteCases[triangles, _?(someSubsetQ[#, boundaryComponents] &)]]},
Graphics3D[{Thick, Line[Table[Append[pt, 0],
{pt, Prepend[boundary, Last[boundary]]}]]}]]
你可以只將U以外的值設置爲0嗎? IE,類似於g [x_,y _] = If [Chop [Im [f [x,y]]] == 0,f [x,y],0]並且繪製g [x,y]而不是f –
這是可以做到的,但它並沒有真正的幫助,因爲Mathematica加入了z = 0平面與圖的其餘部分(以及我想繪製的部分)。也許有一種方法可以告訴Mathematica不要連接這兩部分? – cefstat
「RegionFunction - >函數[{x,y,z},Chop [Im [f [x,y]]] == 0]」?順便說一句,我有更好的經驗,當我發佈Mathematica代碼,人們可以運行自己 –