How to extract the data points in tabular form from a 3D region plot

I want to solve an inequality e.g.

RegionPlot3D[x^2 + y^2 + z^2 > 300, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}]

and store x, y, z values for which this inequality gets satisfied in a table with x value y value and z value entries. I would like to use that table to plot any two variables among x, y, z. How can I extract the data values from the plot?

• Do you want integer solutions? Otherwise, there are infinitely many solutions.
– mjw
Mar 17 '19 at 18:02
• Thanks rohit for editting Mar 18 '19 at 8:14
• No , i want all such many solution, which will later cover a region between two variables. I have given a fractional step size for each range. Can you tell me how fast is this method, because my data points could be many many more in the original program. Earlier when i did the region3D plot, for my original program, it takes a time like 20 mints. Mar 18 '19 at 8:28

reg = ImplicitRegion[
x^2 + y^2 + z^2 > 300 &&
2 < x < 9 && 3 < y < 10 && 4 < z < 12, {x, y, z}];

RandomPoint will uniformly distribute points within a region.

data = RandomPoint[reg, 2000];

The data is in {x, y, z} form

data[[1 ;; 10]] // Grid Graphics3D[Point[data],
Axes -> True,
AxesLabel -> (Style[#, 14, Bold] & /@ {x, y, z})] Here is code to generate a list of integer solutions in the ranges you provided:

Do[If[x^2 + y^2 + z^2 > 300, Print[{x, y, z}]], {x, 2, 9}, {y, 3, 10}, {z, 4, 12}]

Here is the output: Better yet, to store the values in Q:

Q = {};
Do[
If[x^2 + y^2 + z^2 > 300, Q = Join[Q, {{x, y, z}}]],
{x, 2, 9}, {y, 3, 10}, {z, 4, 12}
]

Here is Q:

Q // TableForm • Thanks for the code, i tried it as such , and that is all i want. As i have just given an example here. The original problem is a bit more complex, going to apply the same logic there. Mar 18 '19 at 8:24
• Thanks a lot mjw, it works. Mar 18 '19 at 18:06
• You are welcome!
– mjw
Mar 19 '19 at 2:14
• Dear mjw, As I am running this code from 7 days on my i7 machine, because the function i am using a complicated one, is there any way to make this faster, by means of parallelization, or changing it to C. Mar 28 '19 at 12:06
• Which code? Please post your code and perhaps we'll see a way to speed it up ...
– mjw
Mar 28 '19 at 12:45

You can use Part to get the coordinates used by RegionPlot:

rp = RegionPlot3D[x^2 + y^2 + z^2 > 200, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}];

Coordinates:

coords = rp[[1, 1]];

Show coords with the region surface:

Show[RegionPlot3D[x^2 + y^2 + z^2 > 200, {x, 2, 9}, {y, 3, 10}, {z, 4, 12},
PlotStyle -> Opacity[.1], Mesh -> None, BoundaryStyle -> None],
ListPointPlot3D[coords]] To extract the actual values use in the plot:

plot = RegionPlot3D[x^2 + y^2 + z^2 > 300, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}];
Cases[plot, _GraphicsComplex][[1, 1]] // Short

(* {{7.5,9.98755,12.},<<1084>>,{8.77091,9.58138,11.4544}} *)

Update

Not sure exactly what you mean by "in table form". data is a list of lists which is how a table is usually represented in WL.

data = Cases[plot, _GraphicsComplex][[1, 1]];

You can save it to a file

Export["data.dat", data];

data2 = Import["data.dat"];
data2 == data
(* True *)

Plot all of the x, y values

ListPlot[data[[All, {1, 2}]]] • Thanks for the code, But i don't want them to be displayed or saved like this. I want a columns of x , y ,z data values in a table form to save that table for further analysis. Can you please suggest the way out and extended this thread more, i will appreciate your value time and suggestions. Mar 18 '19 at 8:17

mjw This is the code

sv11ss[g_, mx_, m\[Psi]_] =0. + (0.0242711 g^4 m\[Psi]^2)/((26.0127 + 1. g^4) mx^4 -  208.102 mx^2 m\[Psi]^2 + 416.204 m\[Psi]^4) + (0.075676 g^4(-4.50051*10^8-15000.9 m\[Psi]^2 + m\[Psi]^4))/((-15000.9 + m\[Psi]^2) ((26.0127+1. g^4) mx^4 - 208.102 mx^2 m\[Psi]^2 + 416.204 m\[Psi]^4)) + (0.380504 (0. + 0.00043828 g^8 mx^4 m\[Psi]^4 +g^4 (0.0114009 mx^4 m\[Psi]^4 - 0.0912069 mx^2 m\[Psi]^6 + 0.182414 m\[Psi]^8)))/(m\[Psi]^2 ((0.61685 + 0.0237134 g^4) mx^4 - 4.9348 mx^2 m\[Psi]^2 + 9.8696m[Psi]^4)^2) + (676.662 (0. + 0.0000715353 g^8 mx^8 m\[Psi]^4 + g^4 (0.00186083 mx^8 m\[Psi]^4 - 0.0148866 mx^6 m\[Psi]^6 + 0.0297732 mx^4 m\[Psi]^8)))/(mx^4 m\[Psi]^2 ((26.0127 + 1. g^4) mx^4 - 208.102 mx^2 m\[Psi]^2 + 416.204 m\[Psi]^4)^2)

Then Finally i want to solve this for

mQ = {};Do[If[+0.0001257367 mx >= g + 0.15128504 && 1.0456*^-9 <= sv11ss[g, mx, m\Psi] <= 1.06676*^-9,Q = Join[Q, {{g, mx, m\Psi}}]], {g, 0.01, 0.5, 0.001}, {mx, 500.,10000., 0.5},{m\Psi,300,7000}]Export["newdelmxgFit(0.5).txt", Q, "Table"] // AbsoluteTiming\\

Can i ma ke this kind of code faster

• Well, just to see how long this is going to take ..., If we let $g$ vary from 0 to 0.5 in steps of .1, mx vary from 500 to 1000 in steps of 5, $m\psi$ vary from 300 to 7000, this will take 3.165 seconds. Your version should take 18.5 * 10^5 as long. That is about 6 million seconds.
– mjw
Mar 29 '19 at 1:56
• Also, your use of Join may not be efficient, especially for such a large list that is increasing with each iteration.
– mjw
Mar 29 '19 at 1:59
• Perhaps we can calculate how much memory you are using. Is there any way to scale down this problem?
– mjw
Mar 29 '19 at 2:00
• There is no way, I tried a test code for smaller points, with more step size but it misses then some solutions in between. You mean this will run for 69 days, for the step size that I have given. omg. How can i calculate the time for my code, for how long it will run? Mar 29 '19 at 10:08
• I would suggest scaling it down a bit. Either that or set up a few dozen computers in parallel. I believe you need to think more about the results you need, maybe either reduce the step sizes, or focus in on a smaller region, or both. Also, maybe you or somebody else can come up with more efficient code. How important is the result? Is it worth waiting over two months (and will you have enough memory) to store it all?
– mjw
Mar 29 '19 at 14:46