Re: Extract a contour from a 3-D plot.
- To: mathgroup@smc.vnet.net
- Subject: [mg11390] Re: Extract a contour from a 3-D plot.
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Sun, 8 Mar 1998 20:13:13 -0500
- References: <6dj1at$a0m@smc.vnet.net>
Chris Farr wrote: > > I would like to extract a contour from a 3-D plot. > > I am particularly interested in the contour associated with a value of = > zero. That is, the curve generated when I set the option in > ContourPlot = to Contours->{0}. > > How can I extract this contour ( I guess the contour would be a = > collection of XY coordinates) ? What if there are two contours with a > = value of zero? How can I extract both of them? Thanks in advance. > If you intend to use ContourPlot then the first problem is that it generates a ContourGraphics object which store a matrix of heights, from which the contour lines are constructed for display - not the lines themselves. However, we can convert the ContourGraphics object to a Graphics object which does contain the lines and them use Cases to extract the lines - all of them: In[180]:= ContourPlot[x^2-y^2-1 ,{x,-3,3},{y,-3,3}, Contours ->{0}, ContourShading-> False] Out[180]= -ContourGraphics- In[181]:= Cases[Graphics[%],Line[_], Infinity] Out[181]= {Line[{{-3., 2.82655}, ..., {-3., -2.82655}}], Line[{{3., 2.82655}, ..., {3., -2.82655}}]} Now you can do what you want with the lists of points on the lines. Allan Hayes Training and Consulting Leicester, UK hay@haystack.demon.co.uk http://www.haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44 (0)116 271 8642