Re: Pick up coordinates along different contours.
- To: mathgroup at smc.vnet.net
- Subject: [mg43418] Re: Pick up coordinates along different contours.
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 16 Sep 2003 04:36:39 -0400 (EDT)
- References: <bihpbq$b5t$1@smc.vnet.net>
- Reply-to: "Allan Hayes" <hay at haystack.demon.co.uk>
- Sender: owner-wri-mathgroup at wolfram.com
"Jun Lin" <jl_03824 at yahoo.com> wrote in message news:bihpbq$b5t$1 at smc.vnet.net... > I plot a couple of 2D contours by using ContourPlot. Now, I want to > pick up the coordinate of each point along each contour for next step > calculation purposes. I appreciate with your any suggestion of how to > get the coordinates of each point along a specific contour (suppose > two contours have been created). > > Jun > Jun, Here are some ideas cp = ContourPlot[x*y, {x, -1, 1}, {y, -1, 1}] -ContourGraphics- -ContourGraphics- is a name for the actual output, cp, which we do not normally want to see (the picture is a side effect). We can, however, look at it: InputForm[cp] We see that it is simply an array of values of the x*y at sample points together with instructions to create a picture when operated on with Show - no lines - these are constructed each time the picture is created. To get explicit lines we convert cp into a Graphics object: gr = Graphics[cp] -Graphics- Again, we can look at the actual output: InputForm[gr] We see lines (the contour lines) and polygons (for constructing the shading). Now extract the lines lns = Cases[gr, _Line, Infinity] We may need to label the lines with their heights, especially if there are several contour segments at the same height. lns /. ln:Line[{___, {x_, y_}}] :> {x*y, ln}. Note: we can avoid the polygons in gr by begining with ContourPlot[x*y, {x, -1, 1}, {y, -1, 1}, ContourShading->False] -- Allan --------------- Allan Hayes hay at haystack.demon.co.uk Voice: +44 (0)116 241 8747 Fax: +44 (0)870 164 0565