Tag Info

Hot answers tagged

22

You are combining the images in the form Show[Graphics[simplePrimitives], complicatedRegionPlot] The options in the resulting figure are inherited from the first term, namely Graphics[simplePrimitives]. This does not include the "TransparentPolygonMesh" -> True generated by RegionPlot. You see the mesh as a result. If you combine things as follows: ...


15

Here's my go at it. This tells you if two line segments intersect (unless they lie on the same line, in which case it fails horribly): ClearAll[segmentsIntersect]; segmentsIntersect[{a_, b_}, {p_, q_}] := Module[{s, t, soln}, soln = NSolve[a + t (b - a) == p + s (q - p), {s, t}]; If[Length@soln == 0, False, (0 <= s <= 1 && 0 <= t ...


15

It might be easier to use TriangularSurfacePlot3D to find the Delaunay triangulation of the points. For example, Needs["ComputationalGeometry`"]; triangles[points_] := Module[{pl}, pl = TriangularSurfacePlot[ArrayPad[points, {{0, 0}, {0, 1}}]]; Cases[pl, Polygon[a_] :> Flatten[(Position[points, #[[{1, 2}]]] & /@ a)], Infinity]] ...


14

Here's a possible approach. First use TetGen to tetrahedralize the data: Needs["TetGenLink`"] {pts, tetrahedra} = TetGenDelaunay[data3D]; Next define a function to compute the radius of the circumsphere of a tetrahedron (formula from Wikipedia) csr[{aa_, bb_, cc_, dd_}] := With[{a = aa - dd, b = bb - dd, c = cc - dd}, Norm[a.a Cross[b, c] + b.b ...


13

You could use the (undocumented) option Method -> {"TransparentPolygonMesh" -> True} for this, e.g. Show[Graphics[Point[{p1, p2}]], RegionPlot[{d[{x, y}, p1, M1] < d[{x, y}, p2, M2], d[{x, y}, p1, M1] > d[{x, y}, p2, M2]}, {x, -4, 4}, {y, -4, 4}], Method -> {"TransparentPolygonMesh" -> True}] which produce


13

RegionPlot[{d[{x, y}, p1, M1] < d[{x, y}, p2, M2], d[{x, y}, p1, M1] > d[{x, y}, p2, M2]}, {x, -4, 4}, {y, -4, 4}, Epilog -> Point[{p1, p2}]] seems to do what you want:


13

Table[drawtriangulation[mesh @@ example, First@example, AspectRatio -> Automatic], {example, {circle, circle34, ellipseeye}}] // GraphicsRow Calculating specifications for these examples: (* distance function, bounding box, fixed points, number of initial points, max iterations, min triangle quality *) circle = {Sqrt[#1^2 + #2^2] - 1. &, ...


13

First, you can generate your random points like so: SeedRandom[1]; pts = RandomReal[{0, 12}, {100, 2}]; The DelaunayTriangulation command returns an adjacency list representation of the triangulation. Needs["ComputationalGeometry`"]; dt = DelaunayTriangulation[pts]; dt // Column This says that the first point should be connected to the 2nd, the 24th, ...


13

The mesh seems to be fine and you can see that it is by doing: region = ImplicitRegion[! (Norm[{x, y, z}] < 1), {{x, -5, 5}, {y, -5, 5}, {z, 0, 5}}]; m = DiscretizeRegion[region, {{-2, 2}, {-2, 2}, {0, 1}}] To view as wireframe you can do: Needs["NDSolve`FEM`"] mesh = ToElementMesh[m] // Quiet; Then: Show[mesh["Wireframe"]] If you want to ...


12

This is my implementation using Graphics primitives and rules. Here's the final result; the implementation details and edge cases follow. 1. General approach First, we start with a single square and build up a test grid: square = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]; grid = Graphics[{EdgeForm[Black], FaceForm[None], Table[Transpose@First@square ...


12

You have to create your own mesh and you have to convert your u and v to mesh interpolations. (In the example in the documentation, NDSolveValue does this itself in constructing uif, vif.) Example: Needs["NDSolve`FEM`"] mesh = ToElementMesh[FullRegion[2], {{0, 5}, {0, 1}}]; u = Function[{x, y}, x (y - 0.5)/25]; v = Function[{x, y}, -x^2/50]; uif = ...


11

Not sure about the creation of a "smooth" surface. But from Mma help, you may create a convex hull in 3D by using TetGenConvexHull Needs["TetGenLink`"] data3D = RandomReal[{0, 1}, {100, 3}]; Graphics3D[Point[data3D]]; surface = TetGenConvexHull[data3D]; (* TetGenConvexHull was changed sometime between 8.0.0 and 8.0.4. Uncomment the following line only if ...


11

I just followed examples in TetGenLink documentation: Needs["TetGenLink`"] data3D = N@Flatten[Table[{r Cos[phi], r Sin[phi], z}, {phi, 0, 2 Pi, .5}, {z, -4, 4, .5}, {r, .2, 1, .4}], 2]; in = TetGenCreate[]; TetGenSetPoints[in, data3D]; out = TetGenTetrahedralize[in, ""]; coords = TetGenGetPoints[out]; meshElements = TetGenGetElements[out]; ...


11

Here are a few additions to @RunnyKine suggestions. If you are ever in doubt about the quality of a mesh (an ElementMesh to be exact) you can query the mesh. Needs["NDSolve`FEM`"] region = ImplicitRegion[! (Norm[{x, y, z}] < 1), {{x, -5, 5}, {y, -5, 5}, {z, 0, 5}}]; mesh = ToElementMesh[region]; Min[mesh["Quality"]] 0.004439742441262357` So the ...


10

As pointed out in the comments, there's really no mathematical definition of a concave hull. Of course, just because there's no mathematical definition does not preclude coming up with something that sort of works. I can think of two ways to do this: Easy Way, Not General Your data roughly has axial symmetry parallel to the x-axis. Moreover, all of your ...


10

first part..i had lying around.. poly = Random[Real, {1, 2}] {Cos[#], Sin[#]} & /@ Sort[Table[Random[Real, {0, 2 Pi}], {5}]] isLeft[P2_, {P0_, P1_}] := -Sign@Det@{P2 - P0, P1 - P0}; pinpoly[p_, poly_] := Module[{ed},(*winding rule*) ed = Partition[Append[poly, poly[[1]]], {2}, 1]; Count[ed,pr_ /; (pr[[1, 2]] <= p[[2]] < pr[[2, 2]] ...


10

In Version 10, this can be done elegantly in one line: SeedRandom[400] pts = RandomReal[5, {400, 3}]; Then: surftri = RegionBoundary @ TriangulateMesh @ DelaunayMesh @ pts We can look inside to see that only the surface triangulation remains: HighlightMesh[surftri, {Style[0, Directive[PointSize[0.015], Blue]], Style[1, Thin, Black], Style[2, ...


9

You can add the mesh specific to the x and y coordinates of your data with Mesh -> {First /@ bData, #[[2]] & /@ bData}: p1 = ListPointPlot3D[bData, PlotStyle -> PointSize[Large]] p2 = ListPlot3D[bData, MeshStyle -> Red, PlotStyle -> None, Mesh -> {First /@ bData, #[[2]] & /@ bData}, InterpolationOrder -> ...


9

This will do densPlot = DensityPlot[ 4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1}, MeshStyle -> Thick, Mesh -> All]; vertexCoordinates = densPlot[[1, 1]]; length = Length[vertexCoordinates]; graphReadyConnections = DeleteDuplicates@ Flatten[ Cases[#, List[x_, y_, z_] :> {Sort[x ...


9

It seems you are asking for the Delaunay triangulation. There's a function for this in the Computational Geometry package, which Mark described. Another, usually much faster option is using ListDensityPlot: ldp = ListDensityPlot[ArrayPad[p0, {0, {0, 1}}], Mesh -> All, ColorFunction -> (White &)] You can extract the polygons from this ...


9

Well, you have to first convert it to a MeshRegion. Let's take the space shuttle for example: shuttle = ExampleData[{"Geometry3D", "SpaceShuttle"}] Now, we discretize it, since it's a Graphics3D object, we use DiscretizeGraphics: ds = DiscretizeGraphics[shuttle] Now, we can find the Area easily: Area[ds] 177.301907 Similarly for the horse: ...


9

There are some new functions in Mathematica 10 that make this very easy: r = {{-6, 6}, {-6, 6}}; pts = RandomSample[Permutations[Range[-5, 5], {2}], 10]; Grid[{ {"The sites", "Delaunay trianguation", "Voronoi diagram"}, { Graphics[{Red, Point[pts]}, PlotRange -> r], Show[dm = DelaunayMesh[ pts], Graphics[{Red, Point[pts]}], PlotRange -> ...


8

Using Simon's answer (all credit to him): Needs["TetGenLink`"] file = "https://dl.dropboxusercontent.com/u/68983831/curved_pipe02.txt"; dat = Import[file, "Table"]; {pts, tetrahedra} = TetGenDelaunay[dat]; csr[{aa_, bb_, cc_, dd_}] := With[{a = aa - dd, b = bb - dd, c = cc - dd}, Norm[a.a Cross[b, c] + b.b Cross[c, a] + c.c Cross[a, b]]/(2 ...


7

If you don't mind using undocumented functions, you can do it like this: Graphics`Mesh`MeshInit[]; mesh = DensityPlot[4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1}, Method -> {"ReturnMeshObject" -> True}]; Graph[mesh["Edges"], VertexCoordinates -> mesh["Coordinates"], VertexShapeFunction -> (Point[#] &)]


7

Here is an (imperfect) starting point for how to use ListSurfacePlot3D with this example. It needs manual refinement, but I only have time for this quick test: pts = Import["http://dl.dropbox.com/u/68983831/tube01.vtk", "VertexData"]; Show[Map[ListSurfacePlot3D[#] &, Partition[pts, 300]]] The idea is to break the over 6000 points in your shape ...


6

The procedure I suggested for your other "concave hull" question seems to work reasonably well here, simultaneously isolating the clusters and creating the surfaces. Needs["TetGenLink`"]; {pts,tetrahedra}=TetGenDelaunay[data3D]; csr[{aa_,bb_,cc_,dd_}]:=With[{a=aa-dd,b=bb-dd,c=cc-dd}, Norm[a.a Cross[b,c]+b.b Cross[c,a]+c.c Cross[a,b]]/(2Norm[a.Cross[b,c]])]; ...


6

As I said before, there really isn't such a thing as a concave hull. What you want to do is plot your clusters here. The first problem involves a machine vision problem known as 3D segmentation. Mathematica doesn't have any tools out of the box to do this, as far as I know. One way is to guess how many "clusters" are in your data, although that's hard to ...



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