MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: 3D plot of discontinuous function

  • To: mathgroup at
  • Subject: [mg24800] RE: [mg24779] 3D plot of discontinuous function
  • From: "David Park" <djmp at>
  • Date: Sun, 13 Aug 2000 03:16:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


I designed the DrawingCube package, available at my web site below, to
facilitate this type of graphics. There are two problems that need to be

1) It is necessary to assemble a number of 3D surfaces into one piece of
graphics. The surfaces will generally be plotted over different ranges, and
may even be drawn by different routines (Plot3D or ParametricPlot3D for
example.) DrawingCube allows you to specify each of the surfaces, and mix
them with graphics directives, one after another, in a natural manner
without any of the complications of turning the display on and off.

2) Mathematica plot commands demand a rectangular grid for plotting. You
can't directly write Plot3D[f[x,y], {x,0,1},{y,x,1}] (as you can with
integration routines.) Yet it is often necessary to use just this type of
construction to piece surfaces together. DrawingCube has two routines which
allow you to do this. IteratorSubstution will generate a variable
substitution and new expression to give a fixed range plot.
DrawingTransform3D will transform a plot back to the original desired
coordinates. One advantage of this technique, over others that may be
suggested, is that the boundaries of the regions are smooth and not jagged.

Here is how your example would be done with these DrawingCube routines.

f[x_, y] := If[x >= y, 1, 0]



"IteratorSubstitution[expr, {var, lim1, lim2}, newvar:w] is used to
transform \
a plot range iterator, which may contain variable limits, to one which \
contains constant limits. The plotting expr is transformed to the new \
variable and returned along with the new iterator."


"DrawingTransform3D[f1, f2, f3], where f1, f2 and f3 are function names, is
a \
rule which applies the following transformation to all points in the
graphics \
object: {x_?NumberQ, y_?NumberQ, z_?NumberQ} -> {f1[x, y, z], f2[x, y, z], \
f3[x, y, z]}."

We have to assemble the surface in two regions. For the first region:

IteratorSubstitution[f[x, y], {y, 0, x}]
{If[x >= w*x, 1, 0], {w, 0, 1}}

And y in terms of the x and w is:

IteratorSubstitution[y, {y, 0, x}]
{w x, {w, 0, 1}}

For the second region:

IteratorSubstitution[f[x, y], {y, x, 1}]
{If[w*(-1 + x) >= 0, 1, 0], {w, 0, 1}}

And y in terms of x and w variable is:

IteratorSubstitution[y, {y, x, 1}]
{w + x - w x, {w, 0, 1}}

Now we can make our plot. We can use Plot3D here and the equivalent
DrawingCube routine is Draw3D. (DrawingCube automatically converts the
output to graphical primitives which can be used in Graphics3D). We draw the
surfaces in the xw-coordinates and then use DrawingTransform3D to transform
back to the xy-coordinates.

{Draw3D[If[x >= w*x, 1, 0], {x, 0, 1}, {w, 0, 1}] /.
      DrawingTransform3D[#1 & , #1*#2 & , #3 & ],

 Draw3D[If[w*(-1 + x) >= 0, 1, 0], {x, 0, 1}, {w, 0, 1}] /.
      DrawingTransform3D[#1 & , #2 + #1 - #1*#2 & , #3 & ]}],

   AspectRatio -> Automatic, PlotRange -> All,
   {Axes -> True, AxesLabel -> {x, y, f}, ImageSize -> 500,
    ViewPoint -> {-2.749, 0.332, 1.945}}];

It is very easy to piece together many types of curved surfaces this way.
There are examples in the DrawingCube tutorial.

David Park
djmp at

> -----Original Message-----
> From: Ulrich Bodenhofer [mailto:ulrich.bodenhofer at]
To: mathgroup at
> Hi,
> I am currently struggling with a problem that seems more and more
> non-trivial:
> How can I make a 3D plot of a discontinuous function, where the
> manifolds of
> discontinuities are not necessarily parallel to the axes (*). If
> they were,
> I could
> split the plot into rectangles where the function is continuous and
> reassemble
> them with Show[]. In the more general case, however, I do not have an
> idea how to solve this.
> 1. Plot3D does not support plotting over non-rectangular areas.
> 2. Splitting the plot into regions that can be drawn with ParametricPlot3D
>     is (1) difficult and tedious, and (2) does not support meshes with
>     varying numbers of points either.
> Does anybody have a clue? Any help is gratefully appreciated!
> Regards,
> Ulrich
> (*) Simple example with discontinuities along the diagonal: characteristic
>       function of the linear ordering of real numbers, i.e.
>       f[x_,y_]:=If[x<=y,1,0];

  • Prev by Date: Re: Re: ArcCos[]
  • Next by Date: A simple problem
  • Previous by thread: Re: 3D plot of discontinuous function
  • Next by thread: Re: 3D plot of discontinuous function