From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/3490 Path: main.gmane.org!not-for-mail From: David Arnold Newsgroups: gmane.comp.tex.context Subject: Re: scaling Metapost graphics Date: Tue, 28 Nov 2000 13:18:53 -0800 Sender: owner-ntg-context@let.uu.nl Message-ID: <3.0.3.32.20001128131853.00b9ff84@mail.northcoast.com> NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_975475133==_" X-Trace: main.gmane.org 1035394225 17578 80.91.224.250 (23 Oct 2002 17:30:25 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 23 Oct 2002 17:30:25 +0000 (UTC) Cc: ntg-context@ntg.nl Original-To: johannes.huesing@ruhrau.de Xref: main.gmane.org gmane.comp.tex.context:3490 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:3490 --=====================_975475133==_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Johannes, Hans will help you with the Context way, if there is one. What I like to do is get the graphics the right size before I use them. I always use a scaling factor in my MP code. For example, let's say I want a figure that is 3 inches wide. %initialize scale numeric u; 5u=3D3in; %initialize points pair A, B, C, D, E; A:=3Dorigin; B:=3D(3u,0); C:=3D(5u,0); D:=3D(5u,3u); E:=3D(0,5u); %draw frame draw A--B--C--D--B--E--cycle; Note that this is exactly 3inches wide. Now, suppose I change my mind and I want it to be 4inches wide. This is all I have to do: %initialize scale numeric u; 5u=3D4in; %initialize points pair A, B, C, D, E; A:=3Dorigin; B:=3D(3u,0); C:=3D(5u,0); D:=3D(5u,3u); E:=3D(0,5u); %draw frame draw A--B--C--D--B--E--cycle; Notice that nothing changes save my scaling factor. So, good advance planning is a savior. I've attached some more code where you can see this in action. At 10:06 PM 11/28/00 +0100, you wrote: >Hi all, >In the beginner's book it says that \useexternalfigure can go with the >option height=3D, width=3D. Obviously, \useMPgraphics does not provide >such an option (at least it would print out the option as plain >text). So what is the ConTeXt way to include MP graphics and scale >them? > >Groetjes > > >Johannes >--=20 >Johannes H=FCsing /"\ ASCII-Ribbon Campaign > \ / against HTML > X in e-mail and news > / \ > > --=====================_975475133==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="pretest.mp" input mp-tool; %prologues:=0; %pi numeric pi; pi:=3.14159; %cos function for radian input def cos(expr x)= cosd(180/pi*x) enddef; %sin function for radian input def sin(expr x)= sind(180/pi*x) enddef; %xtick marks def xtick(expr p)= draw ((0,-2pt)--(0,2pt)) shifted p; enddef; %ytick marks def ytick(expr p)= draw ((-2pt,0)--(2pt,0)) shifted p; enddef; %opendot vardef open(expr pos)= path p; p:=fullcircle scaled 3pt; p:=p shifted pos; fill p withcolor white; draw p withcolor red; enddef; beginfig(1); %Define function to be drawn def f(expr x)= x*(x+2)*(x-2) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(xmin,f(xmin)); for x=xmin step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %Clip function path draw p; clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic withcolor blue; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); endfig; beginfig(2); %Define function to be drawn def f(expr x)= x*(x+2)*(x-2) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(xmin,f(xmin)); for x=xmin step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %Clip function path draw p withcolor blue; %Highlight parts of the path that are above the axis p:=(-2,f(-2)); for x = -2 step dx until 0: p:=p--(x,f(x)); endfor; p:=p--(0,f(0)); p:=p xscaled ux yscaled uy; draw p withcolor red withpen pencircle scaled 1pt; p:=(2,f(2)); for x = 2 step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); p:=p xscaled ux yscaled uy; draw p withcolor red withpen pencircle scaled 1pt; %Draw open circles open((-2*ux,0)); open((0,0)); open((2*ux,0)); clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); endfig; beginfig(3); %Define function to be drawn def f(expr x)= exp(x) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(xmin,f(xmin)); for x=xmin step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %Clip function path draw p withcolor blue; %reflect p about x-axis draw (p reflectedabout ((0,0),(1,0))) withcolor red; clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); %label first curve label.rt(btex $y=e^x$ etex, (2ux,5uy)); %label second curve label.rt(btex $y=e^{-x}$ etex, (2ux,-5uy)); endfig; beginfig(4); %Define function to be drawn def f(expr x)= exp(x) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(xmin,f(xmin)); for x=xmin step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %Clip function path draw p reflectedabout ((0,0),(1,0)) shifted (0,1uy) withcolor blue; clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); %ytick marks for k=xmin step 1 until xmax: ytick((0,k*uy)) endfor; %label xticks label.lft(btex $-5$ etex, (0,ymin*uy)); label.lft(btex $5$ etex, (0,ymax*uy)); %draw in the asymptote draw (xmin*ux,1uy)--(xmax*ux,1uy) withcolor red dashed evenly; endfig; beginfig(5); %Define function to be drawn def f(expr x)= ln(x-2) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(2.01,f(2.01)); for x=2.01 step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %draw the function draw p withcolor blue; %clip clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); %draw the asymptote draw (2ux,ymin*uy)--(2ux,ymax*uy) dashed evenly withcolor red; %plot key point drawdot (3ux,0) withpen pencircle scaled 2pt; %label key point pic:=thelabel.ulft(btex $(3,0)$ etex, (3ux,0)); unfill bbox pic; draw pic; endfig; beginfig(6); %initialize scale numeric u; 10u=2in; %draw axes path xaxis,yaxis; xaxis:=(-5u,0)--(5u,0); yaxis:=(0,-5u)--(0,5u); drawdblarrow xaxis scaled 1.1; drawdblarrow yaxis scaled 1.1; label.rt(btex $x$ etex, (1.1*u*xmax,0)); label.top(btex $y$ etex, (0,1.1*u*ymax)); %tickmarks for k=-5u step 1u until 5u: xtick((k,0)); ytick((0,k)); endfor; %define and plot ellipse path p; p:=fullcircle xscaled 2u yscaled 6u; draw p shifted (1u,-2u) withcolor blue; %Label the center drawdot (1u,-2u) withpen pencircle scaled 2pt; %direction of motion drawarrow (2u,-2u)--((2u,-2u)+10*down) withpen pencircle scaled 1pt withcolor red; endfig; beginfig(7); %Define function to be drawn def f(expr x)= sqrt(x) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(0,f(0)); for x=0 step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %draw the function draw p withcolor blue; %reflect the function across x-axis draw p reflectedabout ((0,0),(1,0)) withcolor red; %clip clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %label the graphs label.top(btex $y=\sqrt{x}$ etex, (5ux,3uy)); label.bot(btex $y=-\sqrt{x}$ etex, (5ux,-3uy)); %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); %ytick marks for k=xmin step 1 until xmax: ytick((0,k*ux)) endfor; %label xticks label.lft(btex $-5$ etex, (0,ymin*ux)); label.lft(btex $5$ etex, (0,ymax*ux)); endfig; beginfig(8); %Define function to be drawn def f(expr x)= -sqrt(x+2) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(-2,f(-2)); for x=-2 step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %draw the function draw p withcolor blue; %clip clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); %ytick marks for k=xmin step 1 until xmax: ytick((0,k*ux)) endfor; %label xticks label.lft(btex $-5$ etex, (0,ymin*ux)); label.lft(btex $5$ etex, (0,ymax*ux)); endfig; beginfig(9); %Define function to be drawn def f(expr x)= -sqrt(x+2) enddef; %Declare and initialize viewing window numeric xmin, xmax, ymin, ymax; xmin=-5; xmax=5; ymin=-5; ymax=5; %Declare and initialize scaling variables numeric ux, uy; (xmax-xmin)*ux=2in; (ymax-ymin)*uy=2in; %Declare and initialize clipping boundary path q; q:=(xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle; q:=q xscaled ux yscaled uy; %Declare and initialize number of plotted points numeric N; N:=200; %Declare and calculate plotting increment delta x numeric dx; dx:=(xmax-xmin)/N; %Declare and create function path path p; p:=(-2,f(-2)); for x=-2 step dx until xmax: p:=p--(x,f(x)); endfor; p:=p--(xmax,f(xmax)); %Scale function path p:=p xscaled ux yscaled uy; %draw the function draw p withcolor blue; %draw the line y=x draw (-5u,-5u)--(5u,5u) withcolor black; %draw the reflection draw p reflectedabout ((0,0),(1,1)) withcolor red; %clip clip currentpicture to q; %Save and clear the function path picture pic; pic:=currentpicture; clearit; %Draw and label coordinate axes drawdblarrow (1.1xmin*ux,0)--(1.1xmax*ux,0); label.rt(btex $x$ etex,(1.1xmax*ux,0)); drawdblarrow (0,1.1ymin*uy)--(0,1.1ymax*uy); label.top(btex $y$ etex,(0,1.1ymax*uy)); %Superimpose function plot draw pic; %xtick marks for k=xmin step 1 until xmax: xtick((k*ux,0)) endfor; %label xticks label.bot(btex $-5$ etex, (xmin*ux,0)); label.bot(btex $5$ etex, (xmax*ux,0)); %ytick marks for k=xmin step 1 until xmax: ytick((0,k*ux)) endfor; %label xticks label.lft(btex $-5$ etex, (0,ymin*ux)); label.lft(btex $5$ etex, (0,ymax*ux)); %Label f label.bot(btex $f$ etex, (5ux,-3uy)); %label f^-1 label.lft(btex $f^{-1}$ etex, (-3ux,5uy)); %label y=x label.urt(btex $y=x$ etex, (5u,5u)); endfig; beginfig(10); %initialize scale numeric u; 10u=2in; %axes drawdblarrow (-3.1u,0)--(7.1u,0); drawdblarrow (0,-5.1u)--(0,5.1u); endfig; end --=====================_975475133==_ Content-Type: text/plain; charset="us-ascii" - David Arnold College of the Redwoods Mathematics Department 7351 Tompkins Hill Rd Eureka, CA 95501 (707) 476-4222 Office (707) 476-4424 Fax http://online.redwoods.cc.ca.us/instruct/darnold/ Ordinary Differential Equations Using MATLAB, 2/e http://www.prenhall.com/books/esm_0130113816.html --=====================_975475133==_--