MathGroup Archive 2004

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

Search the Archive

Re: Re: Plotting a contour plot with cylindrical co-ordinates

With DrawGraphics these examples would be done as follows.


oldpoints = {{0, 1}, {2, 2}, {1, 3}};
newpoints = oldpoints // FineGrainPoints[0.2, 4];

    {Point /@ newpoints,
      Point /@ oldpoints},
    AspectRatio -> Automatic,
    Frame -> True];

    {PointSize[0.02], Point /@ newpoints,
        PointSize[0.04], Point /@ oldpoints,
        Red, Dashing[{0.02}], Line[oldpoints]} /.
      DrawingTransform[#1 Cos[#2] &, #1Sin[#2] &],

    AspectRatio -> Automatic,
    Frame -> True,
    Background -> Linen];

    {{ContourDraw[r + theta, {r, 0, 1}, {theta, 0, Pi}] //
            FineGrainPolygons[0.05, 4]} /.
        DrawingTransform[#1 Cos[#2] &, #1Sin[#2] &],
      Circle[{0, 0}, 1, {0, Pi}],
      Line[{{-1, 0}, {1, 0}}]},
    AspectRatio -> Automatic,
    Frame -> True,
    Background -> Linen,
    ImageSize -> 400];

David Park
djmp at

From: Peltio [mailto:peltio at]
To: 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: Do-loop conversion
  • Next by Date: Function Solve from its Property
  • Previous by thread: Re: Plotting a contour plot with cylindrical co-ordinates
  • Next by thread: Re: Re: Re: Plotting a contour plot with cylindrical co-ordinates