0
$\begingroup$

I have the follow simple condition between integers: k - 2 h - l == 0, which describe a plane that I plot with:

ContourPlot3D[x - 2*y - z == 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

Now the problem I have is: How can I plot the same plane under these restrictions:

  • plot only discrete numbers (x = 1, 2, 3, ...; y = 1, 2, 3, ...; z = 1, 2, 3, ...);
  • Mathematica should observe rules on the integers (e.g.: plot only the positive integers for which k ≠ h)
$\endgroup$
2
$\begingroup$

If you want to separately see the plane, the grid of integer point positions, and those points that meet your criteria, you might want to try something like this:

With[{max=2,plane={x,y,z}\[Function]x-2y-z==0},
  Module[{zz,grid,filter},
    zz=z/.Solve[plane[x,y,z],z];
    grid=Select[Tuples[Range[-max,max],3],p\[Function]plane@@p];
    filter[{k_,h_,l_}]:=(k>=0)&&(h>=0)&&(l>=0)&&(k!=h);
    Show[{
      ParametricPlot3D[{x,y,zz},{x,-max,max},{y,-max,max},Mesh->None,PlotStyle->Directive[Opacity[0.5],Gray]],
      Graphics3D[{
        {Gray,Opacity[0.5],Sphere[#,0.19]&/@grid},
        {Red,Sphere[#,0.2]&/@Select[grid,filter]}
      }]
    },BoxRatios->{1,1,1},PlotRange->max+0.5,Lighting->"Neutral"]
  ]
]

enter image description here

You might want to set max to a larger value to see how the set of selected points looks.

$\endgroup$
1
$\begingroup$

Is this the sort of thing you mean?

rgnFn[{x_, y_, z_}] := x - 2*y - z == 0;
Graphics3D[
 Translate[Cuboid[], Select[Tuples[Range[-2, 2], 3], rgnFn] - 1/2], 
 Axes -> True, AxesLabel -> {x, y, z}]

Mathematica graphics

Select here is used to pick the coordinates to be plotted. Subtracting 1/2 above centers the cube on the coordinate.

Select[Tuples[Range[-2, 2], 3], rgnFn]
(*
  {{-2, -2,  2}, {-2, -1,  0}, {-2,  0, -2}, {-1, -1,  1}, {-1,  0, -1},
   { 0, -1,  2}, { 0,  0,  0}, { 0,  1, -2}, { 1,  0,  1}, { 1,  1, -1},
   { 2,  0,  2}, { 2,  1,  0}, { 2,  2, -2}}
*)
$\endgroup$
  • $\begingroup$ @micheal thanks a lot, this can fit the answer of the first question pretty good. Thanks again. $\endgroup$ – Panichi Pattumeros PapaCastoro Jun 10 '14 at 13:49
  • $\begingroup$ @PanichiPattumerosPapaCastoro If you also want to constrain x != y, then change the region function to rgnFn[{x_, y_, z_}] := x - 2*y - z == 0 && x != y. $\endgroup$ – Michael E2 Jun 10 '14 at 15:03
  • $\begingroup$ @PanichiPattumerosPapaCastoro Please, take a tour. $\endgroup$ – Kuba Jun 10 '14 at 15:04

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.