Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To generate a really nice picture, without using zillions of points, you might want to use a non-uniform distribution of points that includes the boundary of the region you want. Here's an example somewhat like what you describe. We start with three mutually tangent circles.</p> <pre><code>circPic = Graphics[{Circle[{0, Sqrt[3]}, 1], Circle[{-1, 0}, 1], Circle[{1, 0}, 1]}] </code></pre> <p><img src="https://i.stack.imgur.com/z3BzT.png" alt="Mathematica graphics"></p> <p>We write a Boolean function that determines whether a point in the rectangle {-1/2,1/2} by {0,Sqrt[3]/2} lies outside of all the circles and use this to generate some points in the region of interest.</p> <pre><code>inRegionQ[p:{x_, y_}] := Norm[p - {1, 0}] &gt; 1 &amp;&amp; Norm[p + {1, 0}] &gt; 1 &amp;&amp; Norm[p - {0, Sqrt[3]}] &gt; 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]; </code></pre> <p>Now we generate the boundary. The parameter n determines how many points we place on the boundary.</p> <pre><code>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]; </code></pre> <p>Let's take a look.</p> <pre><code>Show[circPic, Graphics[Point[points]], PlotRange -&gt; {{-3/4, 3/4}, {-0.3, 1.3}}] </code></pre> <p><img src="https://i.stack.imgur.com/SnkqU.png" alt="Mathematica graphics"></p> <p>Now, we define a function and use <code>ListPlot3D</code> to try to plot it.</p> <pre><code>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]]]} &amp; /@ points; pic = ListPlot3D[points3D, Mesh -&gt; All] </code></pre> <p><img src="https://i.stack.imgur.com/K1mE5.png" alt="Mathematica graphics"></p> <p>Somehow, we've got to delete that stuff that lies outside the region. In this particular example, we can use the fact that the function is zero on the boundary.</p> <pre><code>DeleteCases[Normal[pic], Polygon[{ {x1_, y1_, z1_?(Abs[#] &lt; 1/10.0^6 &amp;)}, {x2_, y2_, z2_?(Abs[#] &lt; 1/10.0^6 &amp;)}, {x3_, y3_, z3_?(Abs[#] &lt; 1/10.0^6 &amp;)}}, ___], Infinity] </code></pre> <p><img src="https://i.stack.imgur.com/aKqJ5.png" alt="Mathematica graphics"></p> <p>Pretty good, but there are a couple of problems near the cusps and it's definitely not very general since it used a specific property of the function. If you examine the structure of pic, you'll find that it contains a <code>GraphicsComplex</code> and the first n points in the first argument of that <code>GraphicsComplex</code> is exactly the boundary. Here's proof:</p> <pre><code>Most /@ pic[[1, 1, 1 ;; n]] == boundary </code></pre> <p>Now the boundary comes in three components and we want to delete any triangle that is formed by points chosen from just one of those components. The following code does this. Note that boundaryComponents contains the indices of those points that form the boundary and someSubsetQ[A,Bs] returns true if A is a subset of any one of the Bs. We want to delete those triangle indices in the multi-Polygon that are subsets of one of the boundaryComponents. That's accomplished in the following code by the <code>DeleteCases</code> command.</p> <p>Oh, and let's add some decoration, too.</p> <pre><code>subsetQ[A_, B_] := Complement[A, B] == {}; someSubsetQ[A_, Bs_] := Or @@ Map[subsetQ[A, #] &amp;, Bs]; boundaryComponents = Partition[Prepend[Range[n], n], 1 + n/3, n/3]; Show[pic /. Polygon[triangles_] :&gt; {EdgeForm[Opacity[0.3]], Polygon[DeleteCases[triangles, _?(someSubsetQ[#, boundaryComponents] &amp;)]]}, Graphics3D[{Thick, Line[Table[Append[pt, 0], {pt, Prepend[boundary, Last[boundary]]}]]}]] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload