[NTG-context] Implicit plots/level curves possible?

Hans Hagen j.hagen at xs4all.nl
Sun Oct 7 20:03:40 CEST 2018


On 10/7/2018 7:14 PM, Alan Braslau wrote:
> On Sun, 7 Oct 2018 17:25:35 +0200
> "Mikael P. Sundqvist" <mickep at gmail.com> wrote:
> 
>> ContourPlot[2 x^5 + x y + y^5 == 0, {x, 0, 2}, {y, -2, 1/2}]
> 
> Brut force:
> 
> \startTEXpage
> \startMPcode {doublefun}
> pen savedpen ; savedpen := currentpen ;
> pickup pencircle scaled .01 ;
> path p ;
> p := for i=0 upto 1000 :
>         for j=0 upto 1000 :
>           hide(x := 2i/1000 ; y := 2.5j/1000 - 2 ;)
>           if abs(2*(x**5)+x*y+y**5) < .002i/1000 : (x,y) .. fi
>         endfor
>       endfor cycle ;
> draw subpath (0,length p - 1) of p ;
> setbounds currentpicture to (0,-2)--(2,-2)--(2,.5)--(0,.5)--cycle ;
> currentpicture := currentpicture xsized 5cm ;
> pickup savedpen ;
> 
> picture pic ; pic := currentpicture ;
> drawarrow llcorner pic--lrcorner pic ;
> drawarrow llcorner pic--ulcorner pic ;
> label.rt ("$x$", lrcorner pic) ;
> label.top("$y$", ulcorner pic) ;
> for x=0 step .5 until 2 :
>      label.bot(decimal x,(x/2)[llcorner pic,lrcorner pic]) ;
> endfor
> for y=0 step .5 until 2.5 :
>      label.lft(decimal (y-2),(y/2.5)[llcorner pic,ulcorner pic]) ;
> endfor
> \stopMPcode
> \stopTEXpage
as this takes some time here's a cheat:

\starttext

\startbuffer[demo]
% when an environment is used, load it here
\startMPcode {doublefun}
     pen savedpen ; savedpen := currentpen ;
     pickup pencircle scaled .01 ;
     numeric stp ; stp := 1 ;
     path p ;
     p := for i=0 step stp until 1000 :
         for j=0 step stp until 1000 :
             hide(x := 2i/1000 ; y := 2.5j/1000 - 2 ;)
             if abs(2*(x**5)+x*y+y**5) < .002i/1000 : (x,y) .. fi
         endfor
     endfor cycle ;
     draw subpath (0,length p - 1) of p ;
     setbounds currentpicture to (0,-2)--(2,-2)--(2,.5)--(0,.5)--cycle ;
     currentpicture := currentpicture xsized 5cm ;
     pickup savedpen ;
     picture pic ; pic := currentpicture ;
     drawarrow llcorner pic--lrcorner pic ;
     drawarrow llcorner pic--ulcorner pic ;
     label.rt ("$x$", lrcorner pic) ;
     label.top("$y$", ulcorner pic) ;
     for x=0 step .5 until 2 :
         label.bot(decimal x,(x/2)[llcorner pic,lrcorner pic]) ;
     endfor ;
     for y=0 step .5 until 2.5 :
         label.lft(decimal (y-2),(y/2.5)[llcorner pic,ulcorner pic]) ;
     endfor ;
\stopMPcode
\stopbuffer

\startTEXpage
     \typesetbuffer[demo]
\stopTEXpage

\stoptext

a next run the already prepared buffer will be taken unles it has been 
changed.

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list