I need to produce a 3-dimensional equispaced grid over a given function in a way, that I can calculate intersection points of the function with the grids edges. So my first question is how to produce this grid in Mathematica. I don't really get if this is possible by modeling the grid by Polygons? For this I might need some help then, too. Or can it be done by using more simple graphics objects like done here?

  • 2
    $\begingroup$ What do you exactly mean by grid? A grid of points? Gridlines? A grid of planes? Can you elaborate? It's not clear to me what the "intersection of a function with a grid" is. Also, exactly what kind of function do you have? $\endgroup$ – Szabolcs Jul 24 '12 at 8:47
  • $\begingroup$ In general, I have a function giving a surface of an object. Now, I want to get the points at which this surface intersects with edges of some kind of grid. Its like getting the intersection of a plane going through a cube. I hope this makes it more clear... $\endgroup$ – MathM Jul 24 '12 at 14:04

Do I understand it correctly that you are looking for the intersection of an implicitly defined surface with planes (planes that could make up a grid)?

Suppose we have this surface ...

j = 1.25;

 x^4 + y^4 + z^4 - (x^2 + y^2 + z^2) == -2/5, 
  {x, -j, j}, {y, -j, j}, {z, -j, j}, 
 Mesh -> False, Axes -> False, PlotPoints -> 30]

Mathematica graphics

... and we want to visualize the intersection with the plane $x + 2y - z$:

ContourPlot3D[x + 2 y - z == 0, {x, -j, j}, {y, -j, j}, {z, -j, j}, 
 Axes -> False]

Mathematica graphics

The simplest way is to use custom MeshFunctions with ContourPlot3D:

gr =ContourPlot3D[x^4 + y^4 + z^4 - (x^2 + y^2 + z^2) == -2/5, 
   {x, -j, j}, {y, -j, j}, {z, -j, j}, 
   Axes -> False, PlotPoints -> 30,
   MeshFunctions -> {Function[{x, y, z}, x + 2 y - z]}, 
   Mesh -> {{0.}}, MeshStyle -> Thick]

Mathematica graphics

Or take the intersections with planes parallel to $yz$:

Update: You can extract the coordinates for the points making up the lines like this: Cases[Normal[gr], _Line, Infinity].

Mathematica graphics

| improve this answer | |
  • $\begingroup$ Thanks for your answer! But I do not only need to get it as a Meshfunction because I need to calculate some points at which the function is intersected by the plane. Like in the answer below. Maybe you have a idea? $\endgroup$ – MathM Aug 1 '12 at 10:38
  • $\begingroup$ @MathM I realise this is not ideal, but you can extract the mesh lines from the graphics expression. Try Graphics3D@Cases[Normal[gr], _Line, Infinity], where gr contains the intersection line. It'll show you the lines only. Now write Cases[Normal[gr], _Line, Infinity] only and you'll see all coordinates that make up the line. Caveat: since the methods that compute the mesh lines are meant for visualization, they are not going to give very precise results. MaxRecursion and PlotPoints can be used to increase precision a bit (at significant cost to computation time). $\endgroup$ – Szabolcs Nov 12 '12 at 20:08

Here's an answer to my interpretation of the question:

Start with a three dimensional grid of lines:

lines = With[{j = 1.25, h = 0.25}, {
  Table[Line[{{x, y, -j}, {x, y, j}}], {x, -j, j, h}, {y, -j, j, h}],
  Table[Line[{{x, -j, z}, {x, j, z}}], {x, -j, j, h}, {z, -j, j, h}],
  Table[Line[{{-j, y, z}, {j, y, z}}], {y, -j, j, h}, {z, -j, j, h}]

Turn each line into rule which gives a parameterisation of the line:

rules = Flatten[lines] /. Line[{{ax_, ay_, az_}, {bx_, by_, bz_}}] ->
  {x -> ax + t (bx - ax), y -> ay + t (by - ay), z -> az + (bz - az)};

Now solve t in whatever implicit equation you have, and extract the valid solution points:

points = Cases[{x, y, z} /. # /. NSolve[x^4 + y^4 + z^4 - (x^2 + y^2 + z^2) == -2/5 /. #,
 t, Reals] & /@ rules, {_?NumberQ, _?NumberQ, _?NumberQ}, Infinity];

And plot the results:

Graphics3D[{PointSize[0.015], Point[points], Opacity[0.25], lines}, Boxed -> False]


| improve this answer | |

From your description, it seems that you need to find the points of intersection between a set of lines and your function, the lines being part of your "grid."

When you say intersection with the grid's edges, I am assuming that you mean points on the grid lines in the following sense: each grid unit makes cube of regular dimensions. You want to determine the intersection of the function with cube faces.

If this is the case, all you need to do is solve for intersection with sets of plane equations.

| improve this answer | |
  • $\begingroup$ That is exactly what I like to do! So you mean using the Mathematica Solve-Command with plane equations. But I don't really know how do it with my function (which is a implicit defined surface like Szabolcs showed us on the top of this page). $\endgroup$ – MathM Aug 1 '12 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.