Hot answers tagged

13

You can try this: polygon = Import["https://pastebin.com/raw/d3MRBb8K"]; pts = Union @@ polygon[[1]]; nf = Nearest[pts -> "Index"]; R = BoundaryMeshRegion[pts, Polygon[DeleteDuplicates@*Flatten /@ Map[nf, polygon[[1]], {2}]]]; f = RegionMember[R]


11

Here is an alternative approach using SignedRegionDistance that seems pretty fast, but I have not compared it to @Henrik Schumacher's answer. It took about 5 seconds to test 100,000 points on my machine. Needs["NDSolve`FEM`"] points = Import["https://pastebin.com/raw/190HQui1"]; polygon = Import["https://pastebin.com/raw/d3MRBb8K"]; (* Convert into ...


10

chm = ConvexHullMesh[{P0, P1, P2, P3}]; ClearAll[regFunc] regFunc[{x, y, z}] := FullSimplify @ RegionMember[Rationalize @ MeshPrimitives[DiscretizeRegion[chm, MaxCellMeasure -> ∞], 3][[1]]] @ {x, y, z} regFunc @ {x, y, z} x + y + z <= 1 && z >= 0 && y >= 0 && x >= 0 Also dm = DelaunayMesh[{P0, P1, P2, P3}]; ...


7

We can use Simplex instead: Refine[RegionMember[Simplex[P /@ Range[0,4]], {x,y,z,w}], {x,y,z,w} ∈ Reals] x >= 0 && y >= 0 && z >= 0 && w >= 0 && w+x+y+z <= 1


6

Join each of your collections of lines using a RegionUnion into a single region, then intersect both regions with RegionIntersection like so: redLines = { Line[{{-2.`, 4.`}, {-1.5`, 2.25`}, {-1.`, 1.`}, {-0.5`, 0.25`}, {0.`, 0.`}, {0.5`, 0.25`}, {1.`, 1.`}, {1.5`, 2.25`}, {2.`, 4.`}}] , Line[{{2, -1}, {2.5, 2}}] }; blueLines = { Line[{{22.`, -3.`}, {15....


6

Here is a method that takes around 2-2.5 times longer than the one from @TimLaska. It has the advantage that it can perhaps be made considerably faster using Compile. It is code from here that I adjusted slightly for the problem at hand. The main idea is to find boundary triangles that a ray from the outside to the given point can intersect. We count these; ...


6

This is not ideal, but it gives an approximate resulting region. I first generate random points on the hexagon and add a random vector on the unit sphere. I take the convex hull of the points which is acceptable because the blob must be convex. Finally I discretize the octahedron and intersect with crudehexagonblob: crudehexagonblob = ConvexHullMesh[# + ...


5

Here is an approach based on creating exact regions: a = Rationalize[0.857597, 10^-16]; b = Rationalize[1.653926, 10^-16]; hexagon = Polygon[{{0, (b - a)/2, 1/2}, {(b - a)/2, 0, 1/2}, {1/2, 0, (b - 1)/(2 a)}, {1/2, (b - 1)/2, 0}, {(b - 1)/2, 1/2, 0}, {0, 1/2, (b - 1)/(2 a)}}] // Simplify; octahedron = ImplicitRegion[Abs[x] + Abs[y] + a ...


4

I think I've found a method that could work. The idea is to make a MeshRegion out of your points and then find all of the polygons with similar face normal vectors. The normal vectors can be computed with MeshCellNormals as described in this answer: mesh = ConvexHullMesh[Data3D]; poly = MeshPrimitives[ConvexHullMesh[Data3D], 2]; clusters = ...


3

I've used a more functional approach here: regions = { Disk[{0, 0}, 1], Disk[{5, 6}, 3], Disk[{2, 2}, 4], Disk[{58, 92}, 5], Disk[{-1, 1}, 2] }; intersections = Select[ ParallelMap[ RegionIntersection @@ # &, Subsets[regions, {2}]] , RegionDimension[#] > 0 &]; If you don't want to store the regions themselves but instead ...


3

The easy part of the question: (1) Use regFunc[i][{x_, y_, z_}] (not regFunc[i][{x, y, z}]) when you define regFunc, (2) Use With[{i = i}, ...] to inject the value of i on the right-hand-side expression: Do[With[{i = i}, regFunc[i][{x_, y_, z_}] := FullSimplify@ RegionMember[ Rationalize@ MeshPrimitives[ DiscretizeRegion[R[...


2

In 12.1.1 this is still a problem. For a workaround I've noticed that making the a + b + c == 1 plane 'thicker' using 1 - 10^-6 <= a + b + c <= 1 allows you to generate points, and you can correct the small error by using #/Total[#] & so that a + b + c is exactly 1 without introducing any significant bias into the sampling: #/Total[#] &@ ...


2

Decimation of mesh is not a trivial task if you want to preserve the visual features of the original mesh. If you want to tap into the efforts of people that have been working on the problem for many years, you could use the freely available MeshLab to perform the decimation with a script driven from Mathematica. Here is one possible workflow (Note: ...


2

Using FindMeshDefects shows that the second example produces "tiny faces". You can use RepairMesh as clean up step to remove such errors like so: meshTest = ConvexHullMesh@ptsOrignal FindMeshDefects[meshTest] meshTest = RepairMesh[meshTest]; RegionResize[meshTest, 10]


2

Graphics`Mesh`FindIntersections Graphics`Mesh`MeshInit[]; findIntersections = Complement[Graphics`Mesh`FindIntersections[Join[##]], Join @@ Graphics`Mesh`FindIntersections /@ {##}] &; Using redLines and blueLines from flinty's answer: intersections = findIntersections[redLines, blueLines] {{-1.73595,3.07582}, {-0.648352,0.472527}, {0.385965,0....


2

Given a set of variables vars and a set of planes planes, where each plane is an equation set to zero, vars = {x1, x2, x3, x4}; planes = {x1, x2, x3, x4, x1 + x2 + x3 + x4 - 1}; the question is: on which side of each plane is the desired polytope? For $n$ planes there are $2^n$ possible polytopes: polytopes = Inner[#1 #2 > 0 &, Tuples[{-1, 1}, ...


1

sys = ForAll[z, And @@ { x^2*y*(1 + z^2 + x*z^4) >= 0, z^2*y*x^2 <= 0, z^4 + y^3 + x^8 >= 0 }]; reg = ImplicitRegion[Resolve[sys, Reals], {x, y, z}] (* example minimization *) Minimize[x^4, {x, y, z} ∈ reg] The system can be reduced further: Resolve[sys,Reals] (* y == 0 || (x == 0 && x^8 + y^3 >= 0) *) Reduce[%] (* y == ...


1

Here's what I think might be sort of a minimal fix to make your approach work. I wasn't able to test this on the regions you provided but here's an outline of how I would do it, and it might work. If it doesn't work, you might try to fix it: ParallelTable[ If[ RegionDimension[ RegionIntersection[R[[i]], R[[j]]] ] > 0, j, Nothing ], {i, ...


1

Normally you would run this where ineq is your inequality, however Mathematica v12.1 will give up after 5-10 minutes because your problem is too complex. implr = ImplicitRegion[ ineq, {{A, 1, 100}, {θ, 0.374626, 1}, {δ, 0, 1}, {γ, 0, 1}}]; measure = RegionMeasure[implr,4] Instead, I recommend using NIntegrate to find the 4-volume. It may complain about ...


1

I have been trying to do this calculating a Concave Hull using this approach: obj = Import["Link.STL"]; pts = RandomPoint[obj, 10000]; tetrahedra = Level[MeshPrimitives[DelaunayMesh[pts], 3], {-3}]; radius[p_] := Check[Circumsphere[p][[2]], 10000]; radii = radius /@ tetrahedra; alphashape[rmax_] := Pick[tetrahedra, radii, r_ /; r < rmax] faces[...


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