Tag Info

New answers tagged

1

The problem lies with using Sphere (or Circumsphere), which are actually surfaces rather than solids. Instead use Ball: a = 1; p0 = {0, 0, 0}; p1 = a {0, 0, Sqrt[2/3] - 1/(2 Sqrt[6])}; p2 = a {-(1/(2 Sqrt[3])), -(1/2), -(1/(2 Sqrt[6]))}; p3 = a {-(1/(2 Sqrt[3])), 1/2, -(1/(2 Sqrt[6]))}; p4 = a {1/Sqrt[3], 0, -(1/(2 Sqrt[6]))}; cs = Circumsphere[{p1, p2, p3, ...


3

You can't make worms with a cylinder ... but a Tube: Graphics3D[ Tube[BSplineCurve[{{1, 1, -1}, {2, 2, 1}, {3, 3, -1}, {3, 4, 1}}], .5]] Tube takes a Line or curve to build itself around, or two endpoints. It also generates caps in a different way.


7

There are lots of places where you can indeed replace Cylinder by Tube, but Tube allows more styling options and flexibility. Most of this information can be collected from the documentation, so I'll just list some aspects that I think are especially noteworthy: In terms of regions, it seems to me that you already answered the question: you can't use Tube ...


-1

My code is: RegionPlot3D[ 0 <= x^2 + y^2 <= 4 && 0 <= z <= 3, {x, -2, 2}, {y, -2, 2}, {z, 0, 3}]


4

Use RegionPlot3D for 3D inequalities. You should get a cylinder. RegionPlot3D[ 0 <= x^2 + y^2 <= 4 && 0 <= z <= 3, {x, -3, 3}, {y, -3, 3}, {z, -1, 4}, PlotPoints -> 40] Increase the PlotPoints for a better quality mesh.


14

Update Silvia proposed a much faster algorithm that I believe produces I uniform distribution. Here is my implementation of it. pointsInMask2[mask_Image, n_Integer, range : {_, _} : {0, 1/2}] := Reverse @ ImageData @ Binarize[mask, range]\[Transpose] // SparseArray[#]["NonzeroPositions"] & // RandomChoice[#, n] + RandomReal[{-1, 0}, {n, 2}] ...


10

Following up on my comment and borrowing a method from Vectorizing an image like "Trace Bitmap" in Inkscape: mask = Binarize @ Import["http://i.stack.imgur.com/yoPNX.png"]; {row, col} = ImageDimensions[mask]; intf = ListInterpolation @ Reverse @ ImageData @ mask; region = DiscretizeGraphics @ RegionPlot[intf[c, r] < 1/2, {r, 1, row}, {c, ...


7

Graphics`Mesh`MeshInit[]; eps = 1/100000000; Manipulate[Labeled[plt = ParametricPlot[{Sin[n t], Sin[(n - 1) t]}, {t, eps, 2 Pi}, Axes -> False, PlotStyle -> Thick]; plt /. Line -> Polygon, Grid[{{"n", "p"}, {n, 2 + Length@Graphics`Mesh`FindIntersections[plt]}}, ItemStyle -> Directive[16, "Panel"]], Top], {n, 2, 10, 1}]


11

I don't like to think too much :P Manipulate[ {#, Composition[ # - 1 &, Length, Union, Flatten, MorphologicalComponents, Binarize, Rasterize ]@#} &@ ParametricPlot[{Sin[ n t], Sin[m t]}, {t, 0, 2 Pi}, Axes -> False, PlotStyle -> Thick] , {n, 2, 10, 1}, {m, 1, 9, 1}]


1

You can also use the function Graphics`Mesh`GenerateUniformPointsInTriangle gupiTriF = Graphics`Mesh`GenerateUniformPointsInTriangle; Graphics[{Polygon[{{0, 0}, {0, 1}, {1, 0}}], White, Point[gupiTriF@500]}] For an arbitrary triangle tri you can use FindGeometricTransform to map the random points in the unit right triangle to points in tri: fgt2DF = ...


2

The general 2D case was discussed in this question, but a more robust version can be written randomFromRegion2D[ region_ /; RegionDimension[region] == 2, trials_Integer /: trials > 0] := Module[{bounds, randPts}, bounds = RegionBounds @ region; randPts = Transpose @ {RandomReal[bounds[[1]], trials], ...


4

In version 10.1 the undocumented function Random`RandomPointVector is useful: region = DiscretizeRegion@RegionUnion@ Table[Disk[RandomReal[4, {2}], RandomReal[1]], {10}]; Graphics@Point@ Random`RandomPointVector[region, 1000, Automatic, Automatic] The two Automatic arguments appear to be working precision and a method option - other allowed values ...


5

Following the advice of @Guess who it is. to use http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle randPt[tri_Triangle] := Module[{a, b, c, r1 = Sqrt[RandomReal[]], r2 = RandomReal[]}, {a, b, c} = Identity @@ tri; (1 - r1)*a + r1*(1 - r2)*b + r1*r2*c]; triangle = Triangle[RandomReal[{0, 5}, {3, 2}]] ...


4

Defining just one of the points of the region with a decimal point helps, suggesting that the method chosen by FindMaximum for integer coordinates is a perhaps a linear programming method, and gets stuck at the observed {5, 5}. Instead one can do: region = Polygon[{{0., 0}, {10, 0}, {10, 5}, {5, 5}, {5, 10}, {0, 10}}]; result = Last@FindMaximum[{x + ...


3

Thanks to a comment from @ilian, I came back to the question: Since the objective function is linear, probably the solution for all these regions except Disk[] comes from a linear programming method, so there are no iterations to monitor And indeed, that's we see. Change the function to e.g. $x^{2}+y^{2}$ and EvaluationMonitor/StepMonitor works a ...


1

As a cone (with a square base), the volume is one-third the base times the height: 1/3 * (4 Sqrt[2])^2 * 8. Another plot, based on the OP's coordinates: ConvexHullMesh@Join[4 IdentityMatrix[3], -4 IdentityMatrix[3]]


1

An alternate approach to calculating the volume Integrate[ Boole[Abs[x] + Abs[y] + Abs[z] < 4], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity}] 256/3


2

A small addition from Mathematica v. 10 In his answer @Ivan has already nailed the most important part of the question, i.e. the formal representation of your region as an ImplicitRegion object: region = ImplicitRegion[Abs[x] + Abs[y] + Abs[z] < 4, {x, y, z}] I just wanted to add that, if you are on Mathematica 10 or newer, you can also use the ...


5

volume = Integrate[1, Element[{x, y, z}, ImplicitRegion[Abs[x] + Abs[y] + Abs[z] < 4, {x, y, z}]]] (*256/3*) ContourPlot3D[Abs[x] + Abs[y] + Abs[z] == 4, {x, -5, 5}, {y, -5, 5}, {z, -5, 5}]



Top 50 recent answers are included