MathGroup Archive 2004

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

Search the Archive

Re: Plotting a contour plot with cylindrical co-ordinates

  • To: mathgroup at
  • Subject: [mg50195] Re: Plotting a contour plot with cylindrical co-ordinates
  • From: "Peltio" <peltio at>
  • Date: Fri, 20 Aug 2004 04:57:31 -0400 (EDT)
  • References: <rrncfuxz67c5@legacy> <cg20b9$nti$>
  • Reply-to: "Peltio" <peltioNOSP at>
  • Sender: owner-wri-mathgroup at

Jake wrote:

>I have a set of data which corresponds to points on a circle. I have
>these values as a function of r and theta. Is there a way of plotting
>this in Mathematica? The ContourPlot function requires x and y

I'm not sure I've understood clearly your problem.
If you want to plot a ContourPlot in polar coordinates, I would suggest to
use a trick I've learnt from Micheal Trott's "The Vibrating Ellipse-shaped
Drum", in The Mathematica Journal volume 6, issue 4. He plots the contour
plot in the rectangular coordinate system and then transforms the lines and
polyogons produced in order to adapt it to the new coordinate system.

A function 'refine' is defined in order to make curves smoother. In fact a
straight line in the x-y system is generally curve in the r-theta system,
and it is necessary to add several intermediate points to give a smoother
This is M. Trott's function:

    refine[coords_, d_] := Module[
        {n, l},
        Join[Join @@ (
            If[(l = (Sqrt[#1.#1] &)[Subtract @@ #1]) < d,
                n = Floor[l/d] + 1;
                (Table[#1 + (i/n)*(#2 - #1), {i, 0, n - 1}] &) @@ #1] &) /@
          Partition[coords, 2, 1], {Last[coords]}]

The parameter d sets the maximum distance between points. The following
picture shows the points it adds to a three point line:

oldpoints = {{0, 1}, {2, 2}, {1, 3}};
newpoints = refine[oldpoints, .2];
    {Point /@ newpoints,PointSize[.02], Point /@ oldpoints}],
     Frame -> True];

So, if we define a coordinate transformation like this:

    toCircle[{r_, theta_}] = {r Cos[theta], r Sin[theta]};

We can see the difference between the curve connecting the two transformed
endpoints and the one connecting all the intermediate points generated by

endpoints = toCircle /@ oldpoints;
midpoints = toCircle /@ refine[oldpoints, .2];
        Point /@ midpoints,
        {PointSize[.02], Point /@ endpoints},
        {Dashing[{.01, .02}], Line[endpoints], Hue[.84], Line[midpoints]}
      ], Frame -> True];

Now all we have to do, following M. Trott's solution, is to convert our
graphics. We can use the following rule (accepting the name of the
conversion routine):

    convert[toSystem_, d_] :=
        f : _Line | _Polygon :> (Head[f])[toSystem /@ (refine[#, d] & @@ f)]

Here's an example (that can be streamlined into a procedure):

gr = ContourPlot[r + theta, {r, 0, 1}, {theta, 0, Pi}];
Show[Graphics[gr] /. convert[toCircle, 0.1],AspectRatio -> Automatic];

hoping that the OP can adapt these procedures to his needs.

  • Prev by Date: Re: Hypergeometric function
  • Next by Date: Re: Re: FindMinimum and the minimum-radius circle
  • Previous by thread: Re: Plotting a contour plot with cylindrical co-ordinates
  • Next by thread: Re: Re: Plotting a contour plot with cylindrical co-ordinates