New answers tagged

9

It still feels a little bit wasteful for me to use a trigonometric function so there's room for improvement, but it's not as wasteful as bringing to bear region functionality on this problem: sameLine[InfiniteLine[{u1_, u2_}], InfiniteLine[{v1_, v2_}]] := With[{u = u1 - u2, v = v1 - v2}, PossibleZeroQ[VectorAngle[u, v]] || PossibleZeroQ[VectorAngle[u, v] ...


10

Here's another approach: DeleteDuplicates[lines, And @@ RegionMember[#, #2[[1]]] &] (* {InfiniteLine[{{0, 0}, {1, 0}}], InfiniteLine[{{0, 1}, {1, 0}}]} *)


12

DeleteDuplicates[lines, MemberQ[{##},RegionIntersection @ ##]&] {InfiniteLine[{{0, 0}, {1, 0}}], InfiniteLine[{{0, 1}, {1, 0}}]}


3

Here are two additional approaches, one uses RegionIntersection, the other uses DiscretizeGraphics: f[x_, y_, z_] = x^4 + y^4 + z^4 - 1; g[x_, y_, z_] = x - 2 y + z - 2; regF = ImplicitRegion[f[x, y, z] == 0, {x, y, z}]; regG = ImplicitRegion[g[x, y, z] == 0, {x, y, z}]; reg = DiscretizeRegion @ RegionIntersection[regF, regG] MeshCoordinates @ reg // ...


4

For version 9: f[x_, y_, z_] := x^3 + y^2 - z^2 g[x_, y_, z_] := x^2 + y^2 + z^2 - 1 cp3d = ContourPlot3D[{f[x, y, z]==0, g[x, y, z]==0}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, BoundaryStyle -> {1 -> None, 2 -> None, {1, 2} -> {Thick, Red}}, ContourStyle -> Opacity[.7], Mesh -> None, ImageSize -> 400]; points = Cases[Normal@cp3d, ...


2

Finding the convex hull of points in $\Re^d$ and expressing it as a set of (in)equalities is hard. However, I would suggest you transform the problem by writing feasible points as convex combinations of the given points, i.e. $$x=\sum_{i=1}^{d} w(i)\, x(i)$$ and then optimize over the simplex $$\{ 0\leq w(i) \leq 1, \sum_{i=1}^{d} w(i) = 1\}$$ ...


6

For 2D, just find the Polygon representing the convex hull and use RegionMember: (* fake data *) rand = Round[RandomReal[{0, 1}, {10, 2}], 1/100]; prims = MeshPrimitives[ConvexHullMesh[rand], 2][[1, 1]]; Refine[RegionMember[Polygon[Round[prims, 1/100]], {x, y}], {x, y} ∈ Reals] 1/25 (1/20 - x) + 18/25 (-1/50 + y) >= 0 && -23/25 (-77/100 + ...


1

One way to treat this in some very special, low dimensional and friendly cases is to use ParametricRegion (*Dimension and number of points*) d = 5; np = 4; (*Generate data*) data = RandomInteger[{-10, 10}, {np, d}]; (*Convex hull*) ws = Array[w, Length[data]]; reg3 = ParametricRegion[ {Sum[ws[[i]]*data[[i]], {i, Length@data}], Total[ws] == 1} , ...


6

I'm not sure what kinds of calculations you'll want to do on the intersection line; but to get a sample of points on the intersection line, you could use DiscretizeRegion and MeshCoordinates: f[x_, y_, z_] = x^4 + y^4 + z^4 - 1; g[x_, y_, z_] = x - 2 y + z - 2; ContourPlot3D[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, ...


2

As others mentioned, Qhull can do this. There are multiple ways to access Qhull from Mathematica. One way is through the mPower package, now part of xCellerator. An answer discussing how to install the package is here: http://mathematica.stackexchange.com/a/18909/12 Another way is the qh-math package, described in this answer: ...


3

Thanks @physicien for the comment on Quickull and Qhull, see his comment on the question. Sadly, I did not understand the paper and so I wanted to give this a shot in Mathematica with some very rude implementation (sorry, I am extremly bad at programming). There is a lot of room for improvement (my solution is extremly slow in high dimensions and for large ...


4

pts = RandomReal[1, {20, 2}]; mesh = ConvexHullMesh[pts] You can simple use MeshPrimitives. MeshPrimitives[mesh, 2] (* {Polygon[{{0.135494, 0.556868}, {0.147549, 0.121726}, {0.423421, 0.0565637}, {0.894244, 0.172512}, {0.917483, 0.413526}, {0.911708, 0.8986}, {0.708881, 0.866828}, {0.272797, 0.654125}}]} *) A 2D ...


6

Today, I discovered an example from Wolfram Documentation Center about plotting a parametric region: ParametricPlot[ r^2 { Sqrt[t] Cos[t], Sin[t]}, {t, 0, 3 Pi/2}, {r, 1, 2}] Namely, ParametricPlot[] could generate the region of family: $f(\theta,t)$ For my question, it is a family of ellipses with respect to time variable $t$. {δxp, δyp, δzp} = ...


5

d = RandomReal[{0, 1}, {20, 2}]; hull = ConvexHullMesh[d]; The ordering can be obtained directly using MeshCells: MeshCells[hull, 2] (* {Polygon[{2, 6, 5, 4, 3, 1}]} *) So: points = MeshCoordinates[hull]; order = MeshCells[hull, 2][[1, 1]]; Graphics[{Yellow, Polygon[points[[order]]], Black, Point[d]}]


7

For graphing, my preferred approach is posted already by user21. To get the ordered coordinates you can reorder MeshCoordinates[ConvexHullMesh[d] using FindCurvePath: With[{d = RandomReal[{0, 1}, {20, 2}]}, mc=MeshCoordinates[ConvexHullMesh[d]]; ListPlot[ d, AspectRatio -> 1, Prolog -> {Yellow,Polygon[mc[[FindCurvePath[mc][[1]]]]]}]] An ...


8

Assuming the goal is to create the graphics: With[{d = RandomReal[{0, 1}, {20, 2}]}, Show[ListPlot[d, AspectRatio -> 1], ConvexHullMesh[d]]] And here is a more efficient version than FindPath: With[{d = RandomReal[{0, 1}, {20, 2}]}, ListPlot[d, AspectRatio -> 1, Epilog -> GraphicsComplex[ MeshCoordinates[#], {Opacity[0.2], ...


3

Looks like you've uncovered a bug. I can confirm this behavior in 10.3.1 and 10.4. You can still discretize your region using DiscretizeGraphics though: r = DiscretizeGraphics@ RegionPlot[0 < Sin[u]/Cos[v] < 1 && 0 < Sin[v]/Cos[u] < 1, {u, 0, 2}, {v, 0, 2}] And if you want finer areas, use DiscretizeRegion: DiscretizeRegion[r, ...


6

Since this question has a FEM tag, I assume that the mesh is for applying boundary conditions to a PDE. If that is the case, then the solution suggested by @RunnyKine can be improved. What you are looking for are the "PointMarkerFunction" and the "BoundaryMarkerFunction". Now, it is important to understand that markers can be applied to points for ...


10

DiscretizeRegion[] and ToElementMesh[] at their core use TriangleLink and TetGenLink to make the mesh. Have a look at the documentation for specifics about these packages. Both ship with source code. As far as literature goes. Have a look at "Delaunay Mesh Generation" by Jonathan Shewchuk (Author) et al. Package homepage Triangle : A Two-Dimensional ...


2

I think what you are using is an undocumented feature in these region objects, so I wouldn't expect it to work properly. You can see some of the properties by using: region["Properties"] The list is quite long so I won't be including it here. Now, both of your regions will show "EdgeLengths" as one of the properties, so you clearly see that this ...


1

I post this for fun but perhaps it may be useful. vm = VoronoiMesh[RandomReal[10, {20, 2}], MeshCellStyle -> {{1, All} -> Black, {2, All} -> LightYellow}]; pg = DiscretizeRegion /@ MeshPrimitives[vm, 2]; f[p_, r_] := With[{v = RandomVariate[PoissonDistribution[r Area[p]]]}, If[v == 0, {}, {Blue, Point[RandomPoint[p, v]], Red, ...


8

I don't know what algorithms the built-in functions implement, but here are a few books that implement some of the algorithms you seek: Computational Geometry: Algorithms and Applications Computational Geometry in C Discrete and Computational Geometry Computational Geometry: An Introduction Finally, there is this one that deals with shape analysis: ...


11

Here is an approach using built-in functions: reg = DiscretizeRegion[Disk[{0, 0}, 0.5], MeshCellHighlight -> {{2, All} -> White}] Now, we obtain the outer points: int = MeshCellIndex[reg, {0, "Interior"}][[All,2]] (* interior points *) ext = Complement[MeshCellIndex[reg, 0][[All,2]], int] (* exterior points *) Finally, we set the properties of ...


10

If you don't mind using undocumented stuff, you can access lots of useful properties by converting the BoundaryMeshRegion to a MeshObject. In this case "VertexVertexConnectivityRules" is useful. Here I start at vertex 1 and go up to 4 steps out along the mesh edges: r = BoundaryDiscretizeRegion[Ball[]]; vvcr = ...


4

Here is an approach that seems to work for the cases presented, I think it may be general if you're only dealing with two curves. For more than two curves, you'll just need to extend the approach a little. getSurf[pt1_, pt2_] := Module[{gr1 = Graphics[Line[pt1 ~ Join ~ {pt1[[1]]}]], gr2 = Graphics[Line[pt2 ~ Join ~ {pt2[[1]]}]], reg}, reg = ...


7

Below you'll find the method I wrote myself, but it is terribly slow compared to this one, adapted from halmir's code here, so I will give the fast version first and post my own code below. See halmir's post for an explanation, ClearAll@graphToMesh graphToMesh[graph_?PlanarGraphQ] := Module[{nextCandidate, m, orderings, pAdj, rightF, s, t, initial, ...


9

This is an artifact in Graphics3D rendering (Z-fighting) which is generally difficult to avoid when using a depth buffer. While ArrayMesh is new in 10.4, you would see similar behavior if you did copy and paste the result into an older version. As a possible workaround, try SetOptions[$FrontEnd, RenderingOptions -> {"Graphics3DRenderingEngine" ...


2

Let's look at a simpler example to show the problem. We'll create a Delaunay mesh from some random points, and generate a RegionBoundary from that. In version 10.4: SeedRandom[4]; mr1 = DelaunayMesh[RandomReal[1, {15, 2}]]; mr2 = RegionBoundary[mr1]; Show[mr1, HighlightMesh[mr2, 1], ListLinePlot[MeshCoordinates@mr2, PlotStyle -> Directive[Thick, ...


2

I will show an approach that makes use of this α shapes code. The caveat here is that one needs to tune a parameter to achieve the "best" shape. But this could be achieved programmatically, if desired, by seeing how some property (e.g. area or volume) of the object changes as the α parameter is changed slightly. A region where that property doesn't change ...



Top 50 recent answers are included