Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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)
share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer

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}}
*)
share|improve this answer
    
@micheal thanks a lot, this can fit the answer of the first question pretty good. Thanks again. –  Panichi Pattumeros PapaCastoro Jun 10 at 13:49
    
@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. –  Michael E2 Jun 10 at 15:03
    
@PanichiPattumerosPapaCastoro Please, take a tour. –  Kuba Jun 10 at 15:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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