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

*To*: mathgroup at smc.vnet.net*Subject*: [mg50215] Re: [mg50195] Re: Plotting a contour plot with cylindrical co-ordinates*From*: "David Park" <djmp at earthlink.net>*Date*: Sat, 21 Aug 2004 03:04:15 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

With DrawGraphics these examples would be done as follows. Needs["DrawGraphics`DrawingMaster`"] oldpoints = {{0, 1}, {2, 2}, {1, 3}}; newpoints = oldpoints // FineGrainPoints[0.2, 4]; Draw2D[ {Point /@ newpoints, PointSize[0.02], Point /@ oldpoints}, AspectRatio -> Automatic, Frame -> True]; Draw2D[ {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]; Draw2D[ {{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 earthlink.net http://home.earthlink.net/~djmp/ From: Peltio [mailto:peltio at twilight.zone] To: mathgroup at smc.vnet.net 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 >co-ordinates. 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 mapping. This is M. Trott's function: refine[coords_, d_] := Module[ {n, l}, Join[Join @@ ( If[(l = (Sqrt[#1.#1] &)[Subtract @@ #1]) < d, #1, 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]; Show[Graphics[ {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 refine: endpoints = toCircle /@ oldpoints; midpoints = toCircle /@ refine[oldpoints, .2]; Show[Graphics[{ 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]; cheers, Peltio hoping that the OP can adapt these procedures to his needs.

**Follow-Ups**:**Re: Re: Re: Plotting a contour plot with cylindrical co-ordinates***From:*DrBob <drbob@bigfoot.com>