MathGroup Archive 2004

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

Search the Archive

Re: Questions about Graph output

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49235] Re: Questions about Graph output
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 9 Jul 2004 02:26:06 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <200407070542.BAA25007@smc.vnet.net> <ccis7v$4c7$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <ccis7v$4c7$1 at smc.vnet.net>,
 Yasvir Tesiram <yat at omrf.ouhsc.edu> wrote:

> Here is a quick modification,
> 
> plt2 = ContourPlot[Sin[x y], {x, -1, 1}, {y, -1, 1}, Contours -> {-.5, 
> .5}]
> plt3 = ListContourPlot[Table[x^2 + y^2 + Random[Real, {-0.2, 0.2}], {x, 
> -2, 2,
>             0.1}, {y, -2, 2, 0.1}]];
> 
> 
> Cases[InputForm[plt2], ContourGraphics[x__] -> x][[1]]
> Cases[InputForm[plt3], ContourGraphics[x__] -> x][[1]]

This does not give the points on the contour. For example

  plt = ContourPlot[x^2 + y^4, {x, -1, 1}, {y, -1, 1}, 
    Contours -> {1/2, 3/4}]

  Cases[InputForm[plt], ContourGraphics[x__] -> x][[1]] == plt[[1]]

so Cases is of no advantage here. 

If you first coerce the ContourGraphics object into a Graphics object, 
you can extract the points on each contour line using Cases:

  contourlinepts = Cases[Graphics[plt], Line[x__] -> x, Infinity]

and, if you like, recover the (set of) contour lines as follows: 

  Show[Graphics[Line /@ contourlinepts], AspectRatio->Automatic]; 

> On Jul 7, 2004, at 12:42 AM, Daohua Song wrote:
> 
> > Dear Friends,
> >       (1)I saw several lines about how to save a graph in the forum 
> > before,
> > but i can not catch the point. how does it work?
> >       plt1 = Plot[Sin[x], {x, 0, 2Pi}];
> >       mydata = Flatten[Cases[plt1, Line[x__] -> x, Infinity], 1];
> >       Export["mydata.txt", mydata, "CSV"];
> >
> >       (2) If i use implicit plot or contour plot, for example
> > draw f[x,y]==Constant. My question is :
> >      how to save the curve to data points i can deal with(just like 
> > (1)),
> > so i can work out the perimeter of this curve, area if it is closed 
> > etc.

Note that, after conversion to polar coordinates (taking the first 
contour),

  polarpts = contourlinepts[[1]] /. 
    {(x_)?NumberQ, y_} :> {ArcTan[x, y], Sqrt[x^2 + y^2]}

you can use Interpolation to compute the perimeter and area. Here is the 
radius as a function of angle:

  r = Interpolation[Rest[polarpts]]

The minimum and maximum angles are

  qmin = r[[1,1,1]]
  qmax = r[[1,1,2]]

(Note that the interpolated curve is not closed -- this can and should 
be fixed to obtain more accurate answers.)

Here is a parametric plot of the contour, to verify that it looks ok:

  ParametricPlot[r[q] {Cos[q], Sin[q]}, {q, qmin, qmax},
    AspectRatio -> Automatic]

We now compute the perimeter,

 NIntegrate[Sqrt[r[q]^2 + r'[q]^2], {q, qmin, qmax}, PrecisionGoal -> 4]

and area

 1/2 NIntegrate[r[q]^2, {q, qmin, qmax}, PrecisionGoal -> 4]

using the standard formulae.

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: RE: Re: Changing the Natural Sort Order
  • Next by Date: what kind of a programming language is Mathematica?
  • Previous by thread: Re: Questions about Graph output
  • Next by thread: No More Memory Available??