Tag Info

Hot answers tagged

16

You can use Show to combine graphics of the same type: g1 = Plot3D[x^2 - y^2, {x, -3, 3}, {y, -3, 3}, RegionFunction -> Function[{x, y, z}, 2 < x^2 + y^2 < 9]]; g2 = SphericalPlot3D[ 1 + Sin[5 θ] Sin[5 φ]/5, {θ, 0, π}, {φ, 0, 2 π}, Mesh -> None, RegionFunction -> (#6 > 0.95 &), PlotStyle -> FaceForm[Orange, Yellow]]; ...


14

Βαγγέλη, you can use an appropriate RegionFunction: V = 1/2*(x^2 + y^2 + z^2) + (x^2*y^2 + x^2*z^2 + y^2*z^2 - x^2*y^2*z^2); E0 = 7; S0 = ContourPlot3D[V == E0, {x, -4, 4}, {y, -4, 4}, {z, -4, 4}, PlotPoints -> 70, PerformanceGoal -> "Speed", Mesh -> None, ContourStyle -> Directive[Green, Opacity[0.3], Specularity[White, 30]], ...


14

You can always hide away the coordinate transformations inside a function that calls RegionPlot3D. Here's a quick & dirty sphericalRegionPlot3D: sphericalRegionPlot3D[ ineq_, {r_, rmin_: 0, rmax_: 1}, {th_, thmin_: 0, thmax_}, {ph_, phmin_, phmax_}, opts___] := RegionPlot3D[With[{ r = Sqrt[x^2 + y^2 + z^2], th = ArcCos[z/Sqrt[x^2 + y^2 + ...


13

While not positive, I believe the answer is that RegionPlot does not support spherical (or other non-Cartesian) coordinates natively. If correct, I guess the question becomes "What's the easiest way to plot a region defined in terms of spherical coordinates, without resorting to converting the equations by hand?" V9 has commands to ease this process. ...


13

Update Compare two pictures. First is able to make mistake like you made the code. You need to do like this code using Mod[ArcTan[x, y], 2π]. h[r_,θ_] := 2 < r <= 5 && 3/4 π < θ < 3/2 π RegionPlot[ h[Sqrt[x^2 + y^2], Mod[ArcTan[x, y], 2π]], {x, -6, 6}, {y, -6, 6}] So I suggest to use ParametricPlot like this. rg = 6; mg = ...


12

In principal you should be able to do r = RegionDifference[Ball[{0, 0, 0}], Ball[{0, 0, 1}]]; rp = RegionPlot3D[r, PlotPoints -> 50]; DiscretizeGraphics[rp] Unfortunately, this does not work and is hopefully improved in a future version. One thing you can do, however, is use the finite element mesh generator for this: Needs["NDSolve`FEM`"] m = ...


12

Here is what I think the issue is: Let's look at what NDSolve parses. Needs["NDSolve`FEM`"] {state} = NDSolve`ProcessEquations[{op == 0, bc}, u, {x, y} \[Element] reg, Method -> {"FiniteElement", "MeshOptions" -> {MaxCellMeasure -> 0.005}}]; femData = state["FiniteElementData"]; femData["PDECoefficientData"]["All"] {{{{0}}, {{{{0}, ...


12

Update: Using MeshFunctions and Mesh in RegionPlot: RegionPlot[Evaluate[Region`RegionProperty[Rationalize /@ blob, {x, y}, "FastDescription"][[1, 2]]], {x, -3, 3}, {y, -3, 3}, Mesh -> 50, MeshFunctions -> {#1 + #2 &, #1 - #2 &}, MeshStyle -> White, PlotStyle -> Directive[{Thick, Blue}]] With settings MeshStyle -> ...


10

The inertia tensor is defined as an integral of the following tensor over the body region vars = {x, y, z}; r2 = IdentityMatrix[3] Tr[#] - # &@Outer[Times, vars, vars]; r2 // MatrixForm It is very simple to do with integration over a region Integrate[r2, vars ∈ region] It can be wrapped in the following function inertiaTensor[reg_, assum_: {}] ...


10

It sounds like you might like to use a stereographic projection. xy[ϕ_, λ_] := 2 Tan[(π - ϕ)/2] {Cos[λ], Sin[λ]}; Here is a cubic with a free parameter (for fun): cubic[{x_, y_}, b_] := y^3 - b x y + 4 x^3; For the sphere, use SphericalPlot3D of course. Although you could resort to ParametricPlot3D for the cubic curve, it's automatic and much simpler ...


10

Perhaps something like this? p = Plot[x^3/9, {x, -3, 3}, PlotStyle -> Thickness[0.01], Filling -> Axis, AspectRatio -> 1, ImageSize -> 500, BaseStyle -> {FontFamily -> "Calibri", 30}, AxesStyle -> Thick]; With[{k = 3}, SphericalPlot3D[1, {theta, 0, Pi}, {phi, 0, 2 Pi}, Mesh -> None, Boxed -> False, Axes -> False, ...


9

It would be nice if UniformDistribution worked on arbitrary regions, then we could simply do RandomVariate[UniformDistribution[region]]. Someone at Wolfram should get on that. In the meantime, it seems we have to write our own sampling routines. @m_goldberg's answer is very nice (vote it up!) and uses rejection sampling, which works for arbitrary regions. ...


9

There are already good answers, but I'm going to improve the performance, generalize to any region in any dimensions and make the function more convenient. The main idea is to use DirichletDistribution (the uniform distribution on a simplex, e.g. triangle or tetrahedron). This idea was implemented by PlatoManiac and me in the related question obtaining ...


8

Use the inequality to sow all integer coordinates that are inside the boundary of the region when iterating through all integer pairs of the full range: pts = First@Last@Reap@Do[If[x >= 4 y && x <= 4 y + 3, Sow@{x, y}], {x, 0, 63}, {y, 0, 15}] RegionPlot[x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}, Epilog -> {Red, ...


7

This is a bug, I think, and I filed it as such: The second region should not evaluate to a RegionQ BoundaryMeshRegion. A BoundaryMeshRegion is valid if it contains a closed surface. The subtle point about BoundaryMeshRegion is that this closed surface is a (sparse) representation of the entire region the surface encloses. Why the first one does not work, I ...


7

ClearAll[mpbmdcg,ljr]; mpbmdcg[k_]:= Composition[MeshPrimitives[#,k]&, BoundaryMesh, DiscretizeGraphics, Graphics]; ljr = Composition[Line, Join[#, {#[[1]]}]&, Replace[#,Line[{a_,b_}]:>a, {0, Infinity}]&]; poly = First@mpbmdcg[2]@(Rectangle/@(-1+Normal[october2014[Values]])); fastdesc= FullSimplify[ Reduce[ ...


6

One option would be to restrict the function from funky regions with a Condition liks this f[x_, y_] /; Abs[x - y] > 5 := (Sin[x] - Sin[y])/(x - y); Plot3D[f[x, y], {x, -10, 10}, {y, -10, 10}] Out: One can easily see that Plot3D will also sample points in the region which is "forbidden", the points are just not drawn due to the RegionFunction. ...


6

All you're missing is the option for BoundaryStyle RegionPlot[1 <= x^2 + y^2 < 9, {x, -3.5, 3.5}, {y, -3.5, 3.5}, Frame -> False, AxesOrigin -> {0, 0}, Axes -> True, BoundaryStyle -> {Dotted, Thickness[0.005]}] If you want the unit circle filled, you can RegionPlot that separately: Show[RegionPlot[1 <= x^2 + y^2 < 9, {x, ...


6

This appears to be equivalent to your previous question. ybeltukov's beautiful answer can be adapted. His answer provides volume above x-y plane. volume[p_, abc_] := π Times @@ abc (2/3 + # - #^3/3) & @@ Normalize[abc p] an[a_] := {Cos[Pi/2 - a], Sin[Pi/2 - a], 0} vol[a_, abc_] := 4 Pi Times @@ abc/3 - volume[an[a], abc] a in the above is the angle ...


6

u = {x, x^3, 0}; v = {0, 0, z2}; l = (u - v) t + v; w = l /. Solve[xs xs + ys ys + (zs - 1)^2 == 1 /. Thread[{xs, ys, zs} -> l], t][[2]]; Manipulate[Show[ ParametricPlot3D[{Cos[u] Sin[v], Sin[u] Sin[v], 1 - Cos[v]}, {v, ArcCos[1 - z1], 0}, {u, 0, 2 Pi}, PlotStyle -> {Opacity[.3], FaceForm[Red, Yellow]}, Mesh -> False, ...


6

Another way to generate all the points is by using Reduce: points = {x, y} /. List@ToRules@ Reduce[x >= 4 y && x <= 4 y + 3 && 0 < x < 63 && 0 < y < 15, {x, y}, Integers] If you give bounds (and thus constrain the possible solutions to a finite set), Reduce will typically list all solutions. Then just plot ...


6

Here is a workaround: r1 = RegionDifference[Rectangle[{0, 0}, {10, 10}], Rectangle[{4, 4}, {8, 8}]]; r2 = TransformedRegion[r1, RotationTransform[45 \[Degree], {5, 5}]]; mr = DiscretizeRegion[r2] And then: RegionPlot[mr]


6

SeedRandom[0]; region = RegionUnion @ Table[Disk[RandomReal[4, {2}], RandomReal[1]], {10}]; DiscretizeRegion @ region points = RandomReal[{-1, 5}, {10000, 2}]; circles = List @@ (region /. Disk -> Circle); Graphics[{AbsolutePointSize[2], Transpose[{RegionMember[region, points] /. {False -> White, True -> Gray}, Point /@ points}], ...


6

---EDIT--- @MichaelE2 is right in that it isn't the overlap (or at least not just the overlap) that is to blame. However, it's not just the scaling of the fast dimension either. You can see that if you resample the data by adding another point. Then Area calculates this just fine! data2[n_] := Transpose[ArrayResample[#, n] & /@ Transpose[data]]; so ...


6

The polygon is very thin. If we scale the points so that the polygon is of good proportions Area works. GraphicsRow[{ Graphics[{Red, Polygon[pts]}], Graphics[{Red, Polygon[pts.DiagonalMatrix[{1, 1000}]]}]}, Frame -> All] Area[Polygon[pts.DiagonalMatrix[{1, 1000}]]]/1000 (* 2018.48 *) One might suppose that round-off error causes the failure ...


5

Solution using Show needs to rearrange the order of ranges in ContourPlot3D, e.g. : Show[RegionPlot3D[(s - 3 q*s + q > 0 && p == 0) || (s - 3 q*s + q <= 0 && p == 1), {q, 0, 1}, {s, 0, 1}, {p, 0, 1}, AxesLabel -> Automatic], ContourPlot3D[s - 3 q*s + q == 0, {q, 0, 1}, {s, 0, 1}, {p, 0, ...


5

Clear["Global`*"] expr = y^2 - 2 x^2 y + 6 x^3 - 3*x*y + 2 y - 6; Integrate[ expr Boole[y >= 2*x^2 - 2 && y <= 3*x], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}] -(36625/2688) Reduce[y >= 2*x^2 - 2 && y <= 3*x, y] (x == -(1/2) && y == -(3/2)) || (-(1/2) < x < 2 && -2 + 2 x^2 ...


5

Try to define your matrix as a function of $(x,q,r,t)$ variables S[x_, q_, r_, t_] := {{1/r^2, 1, 1, t Sqrt[x]}, {1, 1/t^2, 1, Sqrt[x]/t}, {1, 1, 1, Sqrt[q]}, {t Sqrt[x], Sqrt[x]/t, Sqrt[q], 1}}; Then Manipulate does what you want Manipulate[ RegionPlot[ PositiveDefiniteMatrixQ@S[x, q, r, t], {x, 0, 1}, {q, 0, 1}], {{r, 1/2}, 0, 1}, {{t, 1/2}, 0, ...


5

By looking at the hyperbolic behavior of the branches, you may try a simple RegionFunction[]: ContourPlot3D[V == E0, {x, -4, 4}, {y, -4, 4}, {z, -4, 4}, PlotPoints -> 70, PerformanceGoal -> "Speed", Mesh -> None, ContourStyle -> Directive[Green, Opacity[0.3], Specularity[White, 30]], ImageSize -> 550, RegionFunction -> (Abs[#1 #2 ...


5

Here is a clean way to do it. The idea is to specify all circular boundary regions and then to explicitly set those that are region holes, such that those are not meshed. Needs["NDSolve`FEM`"] \[CapitalOmega] = ImplicitRegion[(9/10)^2 <= x^2 + y^2 <= 1^2, {x, y}]; ToElementMesh[\[CapitalOmega]]["Wireframe"] ToElementMesh[\[CapitalOmega], ...



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