ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Metapost samples
@ 2000-11-17 18:22 David Arnold
  2000-11-19 21:55 ` Hans Hagen
  2000-11-20 11:34 ` Marc van Dongen
  0 siblings, 2 replies; 6+ messages in thread
From: David Arnold @ 2000-11-17 18:22 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 128 bytes --]

All,

Here's a nice round of simple graphics in Metapost that I used on my calc
review sheet for an upcoming exam.

I like #15.

[-- Attachment #2: pretest.mp --]
[-- Type: text/plain, Size: 9666 bytes --]

input mp-tool;

%prologues:=0;

%xtick marks
def xtick(expr p)=
 draw ((0,-2pt)--(0,2pt)) shifted p;
enddef;

beginfig(1);

%initialize scale
numeric u; 4u=2in;

%draw axes
drawarrow (0,0)--(4u,0);
drawarrow (0,0)--(0,4u);

%draw the ladder
pickup pencircle scaled 2pt;
draw (2u,0)--(0,3u) withcolor blue;
pickup defaultpen;

%labels
label.urt(btex $13$ etex, 0.5[(2u,0),(0,3u)]);
label.bot(btex $x$ etex, 0.5[origin,(2u,0)]);
label.lft(btex $y$ etex, 0.5[origin,(0,3u)]);

%mark right angle
anglemethod:=2;anglelength:=10pt;
draw anglebetween((0,0)--(3u,0),(0,0)--(0,4u),"");

endfig;

beginfig(2);

%initialize scale
numeric u; 12u=2in;

%initialize vertices
pair A, B, C;
A:=origin;
B=(12u,0);
C=(0,5u);

%draw triangle, label sides
draw A--B--C--cycle;
label.bot(btex $x$ etex, 0.5[A,B]);
label.urt(btex $13$ etex, 0.5[B,C]);
label.lft(btex $5$ etex, 0.5[C,A]);

%mark right angle
anglemethod:=2;anglelength:=10pt;
draw anglebetween(A--B,A--C,"");

endfig;

beginfig(3);

%initialize scale
numeric u; 2u=2in;

%initialize circular base of cone
path p; p:=fullcircle xscaled 2u yscaled 0.5u;
draw p;

%initialize points
z0=origin;
z1=point 0 of p;
z2=point 4 of p;
z3=(0,2u);

%draw cone
draw z1--z3--z2;
draw z3--z0--z1;

%label 
label.lft(btex $h$ etex, 0.5[z0,z3]);
label.bot(btex $r$ etex, 0.5[z0,z1]);

endfig;

beginfig(4);

%initialize scale
numeric u; 125u=2in;

%initialize points
z0=origin;
z1=(sqrt(15525)*u,0);
z2=z1 shifted (0,10u);

%draw triangle
draw z0--z1--z2--cycle;

%label edges
label.ulft(btex $z$ etex, 0.5[z0,z2]);
label.bot(btex $x$ etex, 0.5[z0,z1]);
label.rt(btex $10$ etex, 0.5[z1,z2]);

endfig;

beginfig(5);

%initialize scale
numeric u; 3u=2in;

%initialize points
pair A, B, C, D, E;
A:=origin;
B:=(3u,0);
C:=(3u,2u);
D:=(1u,0);
E:=A+1/3*(C-A);

%draw triangle
draw A--B--C--cycle;
draw D--E;

%label vertices
label.llft(btex $A$ etex, A);
label.lrt(btex $B$ etex, B);
label.urt(btex $C$ etex, C);
label.bot(btex $D$ etex, D);
label.ulft(btex $E$ etex, E);

%label edges
label.bot(btex $z$ etex, 0.5[A,D]);
label.bot(btex $x$ etex, 0.5[D,B]);
label.rt(btex $6$ etex, 0.5[D,E]);
label.rt(btex $18$ etex, 0.5[B,C]);

endfig;

beginfig(6);

%initialize scale
numeric u; 3u=2in;

%initialize points
pair A, B, C;
A:=origin;
B:=(3u,0);
C:=(3u,2u);

%draw triangle
draw A--B--C--cycle;

%label edges
label.bot(btex $w$ etex, 0.5[A,B]);
label.rt(btex $18$ etex, 0.5[B,C]);

endfig;

beginfig(7);

%initialize scale
numeric u; 3u=2in;

%initialize points
pair A, B, C;
A:=origin;
B:=(3u,0);
C:=(3u,2u);

%draw triangle
draw A--B--C--cycle;

%label edges
label.bot(btex $z$ etex, 0.5[A,B]);
label.rt(btex $4\,\hbox{km}$ etex, 0.5[B,C]);

%label angle
anglelength:=10pt; anglemethod:=0;
draw anglebetween(C--A, C--B, btex $\theta$ etex);

endfig;

beginfig(8);

%initialize scale
numeric u; 2u=2in;

%draw axes
drawarrow (0,0)--(2u,0);
drawarrow (0,0)--(0,2u);

%draw the line
draw (1u,0)--(0,1u) withcolor blue;

%label intercepts
label.bot(btex $(1,0)$ etex, (1u,0));
label.lft(btex $(0,1)$ etex, (0,1u));

endfig;

beginfig(9);

%initialize scale
numeric u; 2u=2in;

%draw semicircle
path p;
p:=fullcircle scaled 2u;
z0=point 0 of p;
z1=point 4 of p;
p:=p cutafter z1;
draw p;

%draw diameter
draw z0--z1;

%draw center of circle
pickup pencircle scaled 2pt;
drawdot(origin);
pickup defaultpen;

%initialize point on semicircle
z2=(1u,0) rotated 30;

%draw triangle
draw z0--z2--z1--cycle withcolor blue;

%mark right angle
anglelength:=5pt; anglemethod:=2;
draw anglebetween(z2--z0,z2--z1,"");

%label sides
label.bot(btex $R$ etex, 0.5[z1,origin]);
label.bot(btex $R$ etex, 0.5[origin,z0]);
label.ulft(btex $y$ etex, 0.5[z1,z2]);
label.llft(btex $x$ etex, 0.5[z2,z0]);
endfig;

beginfig(10);

%initialize scale
numeric u; 2u=2in;

%draw semicircle
path p;
p:=fullcircle scaled 2u;
z0=point 0 of p;
z1=point 4 of p;
p:=p cutafter z1;
draw p;

%draw diameter
draw z0--z1;

%draw center of circle
pickup pencircle scaled 2pt;
drawdot(origin);
pickup defaultpen;

%initialize point on semicircle
z2=(1u,0) rotated 45;

%draw triangle
draw z0--z2--z1--cycle withcolor blue;

%mark right angle
anglelength:=5pt; anglemethod:=2;
draw anglebetween(z2--z0,z2--z1,"");

%label sides
label.bot(btex $R$ etex, 0.5[z1,origin]);
label.bot(btex $R$ etex, 0.5[origin,z0]);
label.ulft(btex $\sqrt2 R$ etex, 0.5[z1,z2]);
label.llft(btex $\sqrt2 R$ etex, 0.5[z2,z0]);
endfig;

beginfig(11);

%initialize scale
numeric u; 2u=2in;

%draw semicircle
path p;
p:=fullcircle scaled 2u;
z0=point 0 of p;
z1=point 4 of p;
p:=p cutafter z1;
draw p;

%draw diameter
draw z0--z1;

%draw center of circle
pickup pencircle scaled 2pt;
drawdot(origin);
pickup defaultpen;

%initialize points
z2=(1u,0) rotated 35;
z3=(1u,0) rotated 145;
z4=(xpart z2,0);
z5=(xpart z3,0);
z6=origin;

%draw rectangle
draw z4--z2--z3--z5--cycle withcolor blue;
draw z6--z2;

%label sides
label.bot(btex $x$ etex, 0.5[z6,z4]);
label.bot(btex $x$ etex, 0.5[z6,z5]);
label.lft(btex $y$ etex, 0.5[z4,z2]);
label.rt(btex $y$ etex, 0.5[z5,z3]);
label.ulft(btex $R$ etex, 0.5[z6,z2]);
label.top(btex $2x$ etex, 0.5[z2,z3]);

endfig;

beginfig(12);

%initialize scale
numeric u; 1u=2in;

%initialize points
pair A, B, P, C; 
A:=origin;
B=(0,1u);
P:=(1/2*u,1u);
C:=(1u,1u);

%draw the river
path p;
p:=(-1,0)--(2,0)--(2,1)--(-1,1)--cycle;
p:=p scaled u;
fill p withcolor cyan;

%draw river borders
pickup pencircle scaled 1pt;
draw (-1u,0)--(2u,0);
draw (-1u,1u)--(2u,1u);

%label points
dotlabel.bot(btex $A$ etex, A);
dotlabel.top(btex $B$ etex, B);
dotlabel.top(btex $P$ etex, P);
dotlabel.top(btex $C$ etex, C);

%draw paths
draw A--B dashed evenly;
draw A--P--C withcolor red;

%label lengths
label.lft(btex $1$ etex, 0.5[A,B]);
label.lrt(btex $\sqrt{1+x^2}$ etex, 0.5[A,P]);
label.top(btex $x$ etex, 0.5[B,P]);
label.top(btex $1-x$ etex, 0.5[P,C]);

endfig;

beginfig(13);

%initialize scale
numeric u; 4u=3in;

%initialize points
z0=origin;
z1=(1u,0);
z2=(2u,0);
z3=(3u,0);
z4=(4u,0);

%draw the number line
draw z0--z4;

%draw tick marks
for k=0 step 1u until 4u:
 xtick((k,0));
endfor;

%label critical points
label.bot(btex $1$ etex, z1);
label.bot(btex $3$ etex, z3);

%offset
oldlabeloffset:=labeloffset;
labeloffset:=10pt;
label.bot(btex $f'$ etex, z0);
label.bot(btex $+$ etex, 0.5[z0,z1]);
label.bot(btex $-$ etex, 0.5[z1,z3]);
label.bot(btex $+$ etex, 0.5[z3,z4]);
label.top(btex $f$ etex, z0);
label.top(btex inc etex, 0.5[z0,z1]);
label.top(btex dec etex, 0.5[z1,z3]);
label.top(btex inc etex, 0.5[z3,z4]);
labeloffset:=oldlabeloffset;

endfig;

beginfig(14);

%initialize scale
numeric u; 4u=3in;

%initialize points
z0=origin;
z1=(1u,0);
z2=(2u,0);
z3=(3u,0);
z4=(4u,0);

%draw the number line
draw z0--z4;

%draw tick marks
for k=0 step 1u until 4u:
 xtick((k,0));
endfor;

%label critical points
label.bot(btex $2$ etex, z2);

%offset
oldlabeloffset:=labeloffset;
labeloffset:=10pt;
label.bot(btex $f''$ etex, z0);
label.bot(btex $-$ etex, 0.5[z0,z2]);
label.bot(btex $+$ etex, 0.5[z2,z4]);
label.top(btex $f$ etex, z0);
label.top(btex dn etex, 0.5[z0,z2]);
label.top(btex up etex, 0.5[z2,z4]);
labeloffset:=oldlabeloffset;

endfig;

beginfig(15);

%initialize picture variable
picture pic[];

%initialize scale
numeric u; 4u=3in;

%initialize points
z0=origin;
z1=(1u,0);
z2=(2u,0);
z3=(3u,0);
z4=(4u,0);

%draw the number line
draw z0--z4;

%draw tick marks
for k=0 step 1u until 4u:
 xtick((k,0));
endfor;

%label critical points
label.bot(btex $1$ etex, z1);
label.bot(btex $2$ etex, z2);
label.bot(btex $3$ etex, z3);

%offset
oldlabeloffset:=labeloffset;
labeloffset:=10pt;
label.bot(btex $f'$ etex, z0);
label.bot(btex $+$ etex, 0.5[z0,z1]);
label.bot(btex $-$ etex, 0.5[z1,z2]);
label.bot(btex $-$ etex, 0.5[z2,z3]);
label.bot(btex $+$ etex, 0.5[z3,z4]);
label.top(btex $f$ etex, z0);
label.top(btex inc etex, 0.5[z0,z1]);
label.top(btex dec etex, 0.5[z1,z2]);
label.top(btex dec etex, 0.5[z2,z3]);
label.top(btex inc etex, 0.5[z3,z4]);
labeloffset:=20pt;
label.bot(btex $f''$ etex, z0);
label.bot(btex $-$ etex, 0.5[z0,z1]);
label.bot(btex $-$ etex, 0.5[z1,z2]);
label.bot(btex $+$ etex, 0.5[z2,z3]);
label.bot(btex $+$ etex, 0.5[z3,z4]);
label.top(btex $f$ etex, z0);
label.top(btex dn etex, 0.5[z0,z1]);
label.top(btex dn etex, 0.5[z1,z2]);
label.top(btex up etex, 0.5[z2,z3]);
label.top(btex up etex, 0.5[z3,z4]);
labeloffset:=oldlabeloffset;

pic1:=currentpicture;
currentpicture:=nullpicture;

%define function
def f(expr x)=
 x*x*x-6*x*x+9*x+1
enddef;

%Declare and initialize viewing window
numeric xmin, xmax, ymin, ymax;
xmin=0;
xmax=4;
ymin=0;
ymax=10;

%Declare and initialize scaling variables
numeric ux, uy;
(xmax-xmin)*ux=3in;
(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;
clip currentpicture to q;

%draw axes
drawarrow (xmin*ux,ymin*uy)--(xmax*ux,ymin*uy);
drawarrow (xmin*ux,ymin*uy)--(xmin*ux,ymax*uy);

%draw tick marks
for k=0 step 1u until 4u:
 xtick((k,0));
endfor;

%label extrema
dotlabel.top(btex $(1,5)$ etex, (1ux,5uy));
dotlabel.urt(btex $(2,3)$ etex, (2ux,3uy));
dotlabel.bot(btex $(3,1)$ etex, (3ux,1uy));

%save current picture
pic2:=currentpicture;
currentpicture:=nullpicture;

draw pic2 shifted (0,50pt);
draw pic1;

endfig;

end.

[-- Attachment #3: Type: text/plain, Size: 292 bytes --]

-
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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost samples
  2000-11-17 18:22 Metapost samples David Arnold
@ 2000-11-19 21:55 ` Hans Hagen
  2000-11-20 11:34 ` Marc van Dongen
  1 sibling, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2000-11-19 21:55 UTC (permalink / raw)
  Cc: ntg-context

At 10:22 AM 11/17/00 -0800, David Arnold wrote:
>All,
>
>Here's a nice round of simple graphics in Metapost that I used on my calc
>review sheet for an upcoming exam.
>
>I like #15.

right, but maybe changing btex ... into btex \strut ... improves the
spacing, at least it helps to align labels

Hans
-------------------------------------------------------------------------
                                                  Hans Hagen | PRAGMA ADE
                      Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost samples
  2000-11-17 18:22 Metapost samples David Arnold
  2000-11-19 21:55 ` Hans Hagen
@ 2000-11-20 11:34 ` Marc van Dongen
  2000-11-20 12:30   ` Hans Hagen
  2000-11-20 22:43   ` Pierre Goossens
  1 sibling, 2 replies; 6+ messages in thread
From: Marc van Dongen @ 2000-11-20 11:34 UTC (permalink / raw)
  Cc: ntg-context

David Arnold (darnold@northcoast.com) wrote:

: Here's a nice round of simple graphics in Metapost that I used on my calc
: review sheet for an upcoming exam.

[snip]

I tried to run it through mpost on my machine but
that didn't work. Am I right to assume that it
requires some ConTeXt built-ins? If so, can they
be isolated from the ConTeXt distribution?

Regards,

Marc


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost samples
  2000-11-20 11:34 ` Marc van Dongen
@ 2000-11-20 12:30   ` Hans Hagen
  2000-11-20 22:43   ` Pierre Goossens
  1 sibling, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2000-11-20 12:30 UTC (permalink / raw)
  Cc: David Arnold, ntg-context

At 11:34 AM 11/20/00 +0000, Marc van Dongen wrote:
>David Arnold (darnold@northcoast.com) wrote:
>
>: Here's a nice round of simple graphics in Metapost that I used on my calc
>: review sheet for an upcoming exam.
>
>[snip]
>
>I tried to run it through mpost on my machine but
>that didn't work. Am I right to assume that it
>requires some ConTeXt built-ins? If so, can they
>be isolated from the ConTeXt distribution?

I don't think that context code is used, or maybe some metafun ones, and
these are isolated. 

Hans
-------------------------------------------------------------------------
                                                  Hans Hagen | PRAGMA ADE
                      Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost samples
  2000-11-20 11:34 ` Marc van Dongen
  2000-11-20 12:30   ` Hans Hagen
@ 2000-11-20 22:43   ` Pierre Goossens
  2000-11-21  8:44     ` Hans Hagen
  1 sibling, 1 reply; 6+ messages in thread
From: Pierre Goossens @ 2000-11-20 22:43 UTC (permalink / raw)
  Cc: ntg-context

At 11:34 20-11-00 +0000, you wrote:
>David Arnold (darnold@northcoast.com) wrote:
>
>: Here's a nice round of simple graphics in Metapost that I used on my calc
>: review sheet for an upcoming exam.
>
>[snip]
>
>I tried to run it through mpost on my machine but
>that didn't work. Am I right to assume that it
>requires some ConTeXt built-ins? If so, can they
>be isolated from the ConTeXt distribution?
>
>Regards,
>
>
>Marc
>
Hello Marc,

Because that was also the case with me (the not-working part) I made
separate files for every figure in the original pretest.mp file.
It turns out that the figures 1, 2, 7, 9 and 10 suffer the same symptoms.
This is what my MikTeX logging has to say about it:

-----------------
This is MetaPost, Version 0.641 (MiKTeX 1.20e) (preloaded mem=plain
2000.9.9)  20 NOV 2000 23:15
**mp1
(mp1.mp (C:\texmf\metapost\context\mp-tool.mp)
>> anglebetween
! Improper `addto'.
<to be read again> 
                   withpen
draw->...PR0)else:doublepath(EXPR0)withpen
                                          .currentpen.fi._op_
<to be read again> 
                   (
l.31 draw anglebetween(
                       (0,0)--(3u,0),(0,0)--(0,4u),"");
? h
This expression should have specified a known path.
So I'll not change anything just now.

? x
----------------- 

The 'known path' part returns in all said figures. I haven't looked into
this further as I am still ploughing through the metafun-p.pdf . A very
readable manual by the way.

Succes,

Pierre


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Metapost samples
  2000-11-20 22:43   ` Pierre Goossens
@ 2000-11-21  8:44     ` Hans Hagen
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2000-11-21  8:44 UTC (permalink / raw)
  Cc: Marc van Dongen, ntg-context

At 11:43 PM 11/20/00 +0100, Pierre Goossens wrote:

>l.31 draw anglebetween(
>                       (0,0)--(3u,0),(0,0)--(0,4u),"");
>? h
>This expression should have specified a known path.
>So I'll not change anything just now.
>
>? x
>----------------- 
>
>The 'known path' part returns in all said figures. I haven't looked into
>this further as I am still ploughing through the metafun-p.pdf . A very
>readable manual by the way.

You need a recent version of mp-tool.mp, since anglebetween is rather new.
The latest version of this file can be found in beta distribution. 

Hans
-------------------------------------------------------------------------
                                                  Hans Hagen | PRAGMA ADE
                      Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-11-21  8:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-17 18:22 Metapost samples David Arnold
2000-11-19 21:55 ` Hans Hagen
2000-11-20 11:34 ` Marc van Dongen
2000-11-20 12:30   ` Hans Hagen
2000-11-20 22:43   ` Pierre Goossens
2000-11-21  8:44     ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).