# Tag Info

32

Well, you can use the undocumented RegionDistance which does exactly this as follows: (This answer, as written, only works for V9 as noted by Oska, for V10 see update below) here is a triangle in 3D region = Polygon[{{0, 0, 0}, {1, 0, 0}, {0, 1, 1}}]; Graphics3D[region] Now suppose you want to find the shortest distance from the point {1, 1, 1} in 3D to ...

17

I discarded my previous approach to generate cubes, then fuse them together, since it seems to do a lot of wasted work. Instead, I propose here my version of a cartesian mesher. The approach is conceptually the same as the one delineated by Zviovich, but I wasn't entirely satisfied with his results, as it seems to me that his process still leads to ...

14

I'd say that if the problem is to style the result of DiscretizeRegion, then you don't have a problem :-) You can use MeshCellStyle to indicate the styles to apply to each category of mesh component, in this format: MeshCellStyle -> {{dimensionality, index} -> style, ...}. Dimensionality is $0$ for mesh vertices, $1$ for mesh cell boundary lines, $2$ ...

13

Having Area generate conditions is informative: Area[ RegionIntersection[ Polygon[{{1, 2}, {-1, 1}, {2, 5}}], Polygon[{{2, 4}, {1, -3}, {1, a}}] ], GenerateConditions -> True ] (* Out: ConditionalExpression[0, a < 2] *) Indeed, for $a<2$ there is no intersection, so the area of the intersection is correctly $0$. On the one hand, we ...

11

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 = GraphicsRegionToMeshObject[r]["...

11

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: horse = ...

11

plt = ParametricPlot[ u {9 Sin[2 t] + 5 Sin[3 t], 9 Cos[2 t] - 5 Cos[3 t]}, {t, 0, 2 Pi}, {u, 0, 1}, MeshFunctions -> {Sqrt@(#1^2 + #2^2) &}, Mesh -> {{1}}, PlotPoints -> 30, MeshStyle -> Cyan, MeshShading -> {Cyan}] Post-process plt to remove Lines plt /. Line[_] :> Sequence[] or to paint them Cyan: plt /. Line[x_] :> {...

11

I don't think there's any way to give RegionNearest a user defined DistanceFunction. I don't see an Option for this. However, you can define your own RegionNearest with custom distance function as follows: dist[{u_, v_}, {x_, y_}] := Norm[{u, v} - {x, y}] Then: Clear[q1, q2]; regN[region_, point_] := NArgMin[{dist[point, {q1, q2}], {q1, q2} ∈ region}, {...

10

My take on the problem. We start with the largest cuboids and break down the border cuboids into four smaller cuboids. The function can be nested as many time as needed. rMin = 6; rMax = 10; (*--define sphere volume--*) sphereVolume[{x_, y_, z_}] := rMin <= Sqrt[x^2 + y^2 + z^2] <= rMax; (*Our Data Structure will look as follows element={{x0,y0,z0},...

9

This is at least one bug, possibly more. Let me explain: If we go one step further and use Needs["TetGenLink"] tethull = TetGenConvexHull[pts]; bmr = BoundaryMeshRegion[tethull[[1]], {Polygon[tethull[[2]]]}] BoundaryMeshRegion::binsect: "The boundary curves self-intersect or cross each other in BoundaryMeshRegion[{{1.,-0.999551,-0.000449248},{0.900969,-...

9

Here is an approach based on WatershedComponents and MorphologicalGraph. Some of the steps feel a bit over-complicated, so feel free to point out any improvements. The end result is a Graph expression describing the cell walls: Here is the code with some intermediate results: Get the original image: img = Import["https://i.stack.imgur.com/elbTN.png&...

8

There are a number of ways to do this. Sometimes use of Reduce simplifies the constraints but as Dr Hintze's comment shows Mathematica handles boolean statements well. To illustrate: reg = Reduce[ 0 <= x^2 + y^2 <= 4 && x - y + 2 z <= 4 && z >= 0 && y >= 0 && x >= 0, {x, y, z}] Visualizing region ...

6

ClipPlanes does exactly what you need: You can use ClipPlanes in two different ways: (1) As an option to clip all the 3D primitives: Graphics3D[{Green, Sphere[{0, 0, 0}, 1/4], Blue, Sphere[{0, 0, 0}, 2/3], Red, Sphere[]}, ClipPlanes -> {{0, 1, -1, 0}}, ClipPlanesStyle -> Opacity[.25, Gray]] (2) As a directive that applies to individual 3D ...

6

Note that RegionIntersection[rr, ip] should give you what you want here but doesn't. Since we have an axes aligned plane, we can workaround this by exploiting the second argument of DiscretizeRegion: cut = DiscretizeRegion[RegionBoundary[rr], {{-0.2, 4.1}, {-0.5, 0}, {-0.3, 3.1}}]; holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"]; ...

6

You can use FrenetSerretSystem: FrenetSerretSystem[{x[s], y[s], z[s]}, s][[-1, -1]] //TeXForm \$\left\{\frac{y'(s) z''(s)-y''(s) z'(s)}{\sqrt{\left(x'(s) y''(s)-x''(s) y'(s)\right)^2+\left(x''(s) z'(s)-x'(s) z''(s)\right)^2+\left(y'(s) z''(s)-y''(s) z'(s)\right)^2}},\frac{x''(s) z'(s)-x'(s) z''(s)}{\sqrt{\left(x'(s) y''(s)-x''(s) y'(s)\right)^2+\...

6

Here is another approach where you convert a region to a RegionImage. Then you can use ImageRotate to rotate about a vector and Image3DProjection to project the image on a plane. (* Convert Region To RegionImage *) ri = RegionImage@ExampleData[{"Geometry3D", "SpaceShuttle"}, "Region"]; (* Rotate Image Pi/2 around X *) rirot = ImageRotate[ri, {π/2, {1, 0, 0}}...

5

Edit: Wolfram Technical Support has confirmed this as a bug The only workaround I know is to turn the MeshRegion into a BoundaryMeshRegion and triangulate the resulting mesh object: dr = DiscretizeRegion[reg, MaxCellMeasure -> {"Area" -> 0.05}]; Then: TriangulateMesh[BoundaryMeshRegion[MeshCoordinates[dr], MeshCells[dr, 2]], ...

5

g0 = Graphics[{BezierCurve[pts], Point[pts], Red, Point[pt]}, Frame -> True]; lines = MeshPrimitives[DiscretizeGraphics[g0], 1]; npt = RegionNearest[RegionUnion @@ lines][pt] {0.0805512, 0.671604} Graphics[{Blue,lines, Red, Point[pt], Black, Point@pts, Green, PointSize[Large], Point@npt}, Frame -> True]

5

Simply using BezierFunction is not enough. The BezierFunction will not match the BezierCurve because that curve is actually a composite of multiple splines - see here: BezierCurve is different from BezierFunction. This below is adapted from the above and @J. M.'s technical difficulties solution: You need to first chop your spline into its components and ...

4

This is a tangential answer to your question, but perhaps it may be of interest nonetheless, in the spirit of providing an alternative approach. In the case of a cubic region you may be interested in using the bounding box option to DiscretizeRegion, rather than trying to coax it to include all the edges (which I was not yet able to do either). For ...

4

Element treats Intervals as geometric regions, and members of those geometric regions are vectors, even when they are of single dimension. (I don't think this is really properly documented anywhere - I tried to look at documentation of both.) The fact that there are two different interpretations of an Interval - the old, and the new bought by geometric ...

4

The most powerful tensor package suit for MMA (and arguably for any CAS) is xAct. It uses the full machinery of diff geometry (fiber bundles, connections, forms, ect) and a powerful canonicalization algorithm, both symbolically and numerically. Obviouly you can use just a fraction of this power. I am the developer of xPrint, the GUI interface to xAct. With ...

4

The main idea is to find the gap position dimension by dimension. Take the first dimension for example, to accomplish that, we first project the hold points set to x axis, and do some very basic but fast statistics to locate the "gap", then we shift the coordinates according to the it. Here is an example: (* Size of the periodic cell: *) ℒ = 10; (* ...

4

I have described integrating Mathematica and the open source 3D modeling tool, Blender 2.79b, in previous answers here and here. Your geometry does have some small features and concavity that can cause many meshers problems. Blender appears to be able to handle it. You will need to learn some python scripting to facilitate the integration but there are ...

4

Note that this is only an issue with the display -- the region itself is still correct. We can see this by sampling a bunch of random points: Graphics3D[{PointSize[Tiny], Point[RandomPoint[r3, 100000, {{0, 30}, {-5, 5}, {-5, 5}}]]}, Boxed -> False] As a workaround, you can discretize then perform boolean operations: r1 = Fold[RegionDifference, ...

4

LatticeData makes use of the abstract Mathematica Entity Lattice. This reflects the physical interpretation of lattices in solids. So it is in general translational. Translational is in general not periodic. It depends on the task to be periodic. Visualization can not be periodic. To represent translational infinity usually the finite lattice graphic is cut ...

4

Your question is fundamentally not about a 3D object, incidentally. Binarize the image (called image), then find the number of black pixels, and divide by the total number of pixels: N[1 - ((1 /. ComponentMeasurements[a = Binarize[image], "Count"])/(Times @@ ImageDimensions[a]))] (* 0.246316 *)

4

Given 3 point, search the center of the circle through these points. The center of the circle must lay in the same plane as p1,p2,p3, therefore we can write: SeedRandom[12]; {p1, p2, p3} = RandomReal[{-1, 1}, {3, 3}]; c = p3 + l1 (p1 - p3) + l2 (p2 - p3); with the center c and unknowns l1 and l2. These are determined by the condition that the distance to ...

3

Since N is a built-in symbol, we will use n instead of N. The required formulas are r = {x[s], y[s], z[s]}; T = D[r, s] \[Kappa] = Norm[D[T, s]] n = D[T, s]/\[Kappa] \[Tau] = Norm[(\[Kappa]*T + D[n, s])] B = (\[Kappa]*T + D[n, s])/\[Tau]

3

{x, y, z} = {Sin[θ] Cos[φ], Sin[θ] Sin[φ], Cos[θ]}; Reduce[0 <= θ <= π && 0 <= φ < 2π && z > 0, {θ, φ}] 0 <= θ < π/2 && 0 <= φ < 2π Reduce[0 <= θ <= π && 0 <= φ < 2π && z > 0 && x > 0, {θ, φ}] 0 < θ < π/2 && (0 <= φ < π/2 || 3π/2 < φ &...

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