# Tag Info

15

Mathematica makes this fairly simple. We can define a region region = RegionDifference[Disk[{a, 0}, a], Disk[{0, 0}, b]] (* BooleanRegion[#1 && ! #2 &, {Disk[{a, 0}, a], Disk[{0, 0}, b]}] *) You can visualise this quite simply, for specific values of a and b with the following line Block[{a = 3, b = 1}, Region[region]] and an integrand ...

12

f1h = HoldForm[10 - Sqrt[10^2 - x^2]]; f1 = f1h // ReleaseHold; f2h = HoldForm[5 - Sqrt[5^2 - (x - 5)^2]]; f2 = f2h // ReleaseHold; f3h = HoldForm[5 + Sqrt[5^2 - (x - 5)^2]]; f3 = f3h // ReleaseHold; The x values for the curve intersections are {x1, x2} = x /. Solve[f1 == #, x][] & /@ {f2, f3}; The point coordinates for the curve intersections ...

11

In addtion to Carl's answer, you can also force to rasterize the image with customized resolution. Takes longer but creates higher resolution bitmap images. g = Show[Graphics[{Red, rDisk}], Graphics[{Blue, bDisk}], Graphics[{Green, gDisk}], Graphics[{Blend[{Red, Blue}, 0.5], BoundaryDiscretizeRegion[rbDisk]}], Graphics[{Blend[{Red, Green}, 0.5], ...

11

Update: Carl gave the best solution in a comment: Could use {y} ∈ Interval[{-1, 1}] instead. – Carl Woll If you use the region notation, the variable is considered to be a vector. 1D region implies a 1D vector, but still a vector, not a scalar. The following all work: Explicitly take the first component of the vector. Since this is symbolic ...

10

One simple way to visualize complicated regions in mathematica disk1 = Region[Disk[{5, 5}, 5]] disk2 = Region[Disk[{0, 10}, 10]] disk3 = Region[Disk[{10, 0}, 10]] result = Region[ RegionUnion[RegionDifference[disk1, disk3], RegionDifference[disk1, disk2]]]

9

You mixed up the ordering of bRegion and aRegion. Moreover, Region is only suitable for a quick preview; it usually does not discretize very accurately. Try DiscretizeRegion with variable MaxCellMeasure instead. \[CapitalOmega] = DiscretizeRegion[RegionDifference[bRegion, aRegion], MaxCellMeasure -> 0.001] You may also try to specify a suitable ...

9

You can use BoundaryDiscretizeRegion instead of DiscretizeRegion to avoid the mesh lines when using Antialiasing->True: Graphics[{ {Red, rDisk}, {Blue, bDisk}, {Green, gDisk}, Antialiasing->True, BoundaryDiscretizeRegion[rbDisk, MeshCellStyle->{2->Blend[{Red, Blue}]}], BoundaryDiscretizeRegion[rgDisk, MeshCellStyle->{2-...

8

Like this? ContourPlot3D[x^2 + y^2 + z^2, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, ContourStyle -> Directive[Opacity[.5], ColorData], Axes -> False, Contours -> {0.25, .5, .75}, Mesh -> None ]

8

As Henrik has pointed out, the holes are there when the parameterization of RegionDifference is correct. Sometimes having Infix notation in mind will help to avoid mistakes. Another advice is to start using contructor functions with parameters defined only once (e.g. using scoping constructs like With) right from the start. So mind the advice: Don't repeat ...

8

Here's an approach you could try, making use of ListContourPlot to build a RegionMemberFunction: First I'll make some sample data. This should just be replaced by your actual stuff: cutout = Region@Disk[{-2, 3}, 3]; concaveShape = RegionDifference[Disk[{0, 0}, 3], cutout]; distFunc = RegionDistance[cutout]; data = Flatten[ Table[r*{Cos[q], Sin[q]}, {q, ...

8

You can force Mathematica to use a finer mesh by using BoundaryDiscretizeRegion and giving the option MaxCellMeasure. Like so: r = ImplicitRegion[ -0.5 <= x <= 0.5 && -0.5 <= y <= 0.5 && -0.5 <= z <= 0.5 && (x^2 + z^2 <= 0.04 || y^2 + (0.3 + z)^2 <= 0.04), {x, y, z}]; BoundaryDiscretizeRegion[...

8

I have created a GmshLink package as a workaround exactly for such questions. Please also see this answer for another nice example of use. First we load the package and show path to directory containing GMSH executable. Get["GmshLink"] $GmshDirectory = "path_to_directory\\gmsh-4.5.0-Windows64"; Define symbolic region and calculate its bounds (optionally).... 8 I think RegionMeasure factorizes through Region which is meant only as preview and is also very buggy. RegionMeasure@BoundaryDiscretizeRegion@reg seems to return a more plausible result. So this rule of thumb: Do not rely on Region; always discretize. 7 nF = RegionNearest[Cases[simplexPlot, _Line, All][]]; pnt = {2, 2, 2}; npnt = nF @ pnt {4.56162,6.16536,10.9321} EuclideanDistance[pnt, nF@pnt] 10.1831 Show[simplexPlot, Graphics3D[{Red, Sphere[pnt, .2], Green, Sphere[npnt, .2], Gray, Dashed, Arrow[{pnt, npnt}]}]] 7 Update: Putting together pieces from several sources (links below) to identify the largest contiguous rectangle in a binary matrix: ClearAll[poP, stutteringAccumulate, largestRectangleInHistogram, maxRectangle] SetAttributes[poP, HoldAllComplete]; poP[a_] := Module[{b}, If[EmptyQ[a], False, b = Last[a]; Set[a, Most[a]]; b]] stutteringAccumulate = FoldList[... 7 Given a set of random 3D points, you can create a mesh that represents the minimum bounding region using BoundingRegion[] or ConvexHullMesh[] as MarcoB suggested. ConvexHullMesh[] is probably the simplest, though BoundingRegion[] has some nice options for other sorts of regions like the smallest sphere or cuboid. BlockRandom[SeedRandom; pts = ... 7 One option could be to use FindClusters and MinMax or Quantile sample = Import["https://pastebin.com/raw/yFJa87Hn", "RawJSON"]; clusterEdges = MinMax /@ FindClusters[sample, 3] (* {{1.00194, 1.0076}, {0.988321, 0.994815}, {0.995332, 1.00138}} *) clusterEdges2 = Quantile[#, {0.1, 0.9}] & /@ FindClusters[sample, 3] (* {{1.00319, 1.00651}, {0.989299, 0.... 7 Using @Michael's suggestion brings the timing down about an order of magnitude. There are 120 components after using LogicalExpand: components = List @@ LogicalExpand[ Reduce[1 > y > 0 && First @ reg1, {r, r, r, r}] /. _Equal -> False ]; //AbsoluteTiming Length[components] {6.53425, Null} 120 Computing integral over ... 7 Working with mesh regions (i.e., using DiscretizeRegion) instead of region primitives (e.g., Cuboid) will produce objects that can be rendered more easily. body = RegionUnion[ DiscretizeRegion @ Cylinder[{{2.55,0,0},{4.45,0,0}},0.55], RegionDifference[ DiscretizeRegion @ Cylinder[{{2.5,0,0},{4.5,0,0}},0.6], DiscretizeRegion @ ... 7 Using Rationalize and arbitrary-precision produces consistent results poly[x_, y_] = 4.3 x + 2.1 y // Rationalize // Simplify; triangle = Triangle[{{-1., 0.}, {0., 1.}, {1., 0.}} // Rationalize]; reg = ImplicitRegion[poly[x, y] < 0 && {x, y} ∈ triangle, {x, y}]; area = RegionMeasure[reg] (* 43/128 *) area // N // InputForm (* 0.3359375 *) ... 6 You could define a ParametricRegion , examplary between curves #10 and #11 reg10 = ParametricRegion[{{Cos[t], Sin[t]} Exp[(t + 2*Pi*ii/120)/2], (Sqrt[#.#] < radius) &[{Cos[t],Sin[t]} Exp[(t + 2*Pi*ii/120)/2] - ctr]} , {{t, -Pi, Pi}, {ii, 10, 11}}] DiscretizeRegion[reg10] Area[DiscretizeRegion[reg10]] (*0.0592725*) addendum Knowing the plot pp a ... 6 Update: Post-process RegionPlot outputs to remove the walls: colors = ColorData /@ Range; radii = {1, 3/4, 1/2, 1/4}; regionplots = RegionPlot3D[x^2 + y^2 + z^2 <= #^2, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, Mesh -> None, BoundaryStyle -> None, Axes -> False] & /@ radii; Graphics3D[{EdgeForm[], FaceForm[{Opacity[.5], #[]}], ... 6 I'll use the spherical-coordinates approach, and I'll assume for now that by "surface measure" you mean the Haar measure of$4\pi\$ total area covering the unit sphere uniformly. If instead you are looking for an average, see further below. The full integral would be Integrate[Abs[Det[{{Sin[θ1] Cos[φ1], Sin[θ1] Sin[φ1], Cos[θ1]}, {Sin[θ2] ...

6

For the 2D case, you can use the shape of the joint to give rounded corners to your shape. For instance: pts = RandomReal[{-5, 5}, {20, 2}]; ConvexHullMesh[pts] Retrieve the mesh expressed as a Polygon object and style to your liking: Graphics[{ Darker@Blue, EdgeForm[{Darker@Blue, Thickness[0.09], JoinForm["Round"]}], Cases[Normal[chm["Graphics"]], ...

6

Please note the RegionBounds: reg1 = Cylinder[{{0, 0, 0}, {10, 0, 0}}, 0.5]; reg2 = Cuboid[{5, 0, 0}, {10, 1, 1}]; reg = RegionDifference[reg1, reg2]; bounds = RegionBounds@reg; Region[reg, Axes -> True, PlotRange -> bounds]

6

One approach is to see where each face in the union came from and assign the colors from there. rmfs = RegionMember /@ {reg3, reg6, reg9}; color[{__, True}] = Darker[Yellow]; color[{_, True, _}] = Darker[Green]; color[_] = Darker[Orange]; centroids = PropertyValue[{reg, 2}, MeshCellCentroid]; facecolors = color /@ Transpose[Through[rmfs[centroids]]]; ...

6

When ElementMarker are attributed automatically there is no way that they would fit all possible orderings one could think of. The work flow is that one would generate the boundary mesh and the use, for example, a Manipulate to scroll through the boundaries. Something like this: Needs["NDSolveFEM`"] radius = 0.1; Louter = 2; OuterRegion = Rectangle[{-L/2, ...

6

Here's one workaround. Since your clip-plane is axes aligned, we can use the 2 argument form of DiscretizeRegion to clip the solid in one direction, then manually pick the faces on the plane. (If your clip-plane is not axes aligned, you could rotate your whole scene, clip, then rotate back.) x = 6.; clip = BoundaryDiscretizeRegion[myConeMesh, {{-1, x}, {-...

6

You can specify the quarter disks using the three-argument form of Disk. For the first picture: a = 1; d1 = Disk[{0, 0}, a, {0, Pi/2}]; d2 = Disk[{a, 0}, a, {Pi/2, Pi}]; d3 = Disk[{0, a}, a, {-Pi/2, 0}]; ri = RegionIntersection[d1, d2, d3]; Through[{Perimeter, N @* Area} @ ri] {2.61799, 0.442972} Graphics[{EdgeForm[Gray], Opacity[.25], Orange, d1, ...

6

RegionPlot[ x^2 + y^2 < 25 \[And] ((x - 5)^2 + (y + 5)^2 > 100 \[Or] (x + 5)^2 + (y - 5)^2 > 100), {x, -5, 5}, {y, -5, 5}] Or... z[w_] := EuclideanDistance[{x, y}, w {5, -5}]; RegionPlot[ z < 5 \[And] (z > 10 \[Or] z[-1] > 10), {x, -5, 5}, {y, -5, 5}] Or... z[w_] := (a = ({x, y} - 5 {w, -w})).a; RegionPlot[ z < 25 \[...

Only top voted, non community-wiki answers of a minimum length are eligible