ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Re: A Metapost need
       [not found] <3.0.5.32.20001129204148.009b7740@mail.northcoast.com>
@ 2000-08-30  9:49 ` Hans Hagen
  0 siblings, 0 replies; only message in thread
From: Hans Hagen @ 2000-08-30  9:49 UTC (permalink / raw)
  Cc: ntg-context

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

At 08:41 PM 11/29/00 -0800, David Arnold wrote:
>Hans,
>
>When mathematicians draw parametric curves, they frequently need to
>indicate the direction of motion. I often have need of a little macro that
>will put an arrow of requested length, anchored at a point on the curve,
>and bending with the curve in the direction of motion. 
>
>I am looking for a nice way to do this. Got any ideas?

Well, you expressed the idea already, so you need the implementation -) 

If there are more of such general wishes, I can consider adding the
solutions to the new metafun macros [bunch of mp and tex]  to be released
soon. Don't expect too much and too clever macros. 

================= code ===================================

% output=pdftex

\setupcolors[state=start]

\setuplayout[width=middle,height=middle]

\starttext 

\startbuffer[macros]
\startMPinclusions
vardef pointarrow (expr pat, loc, len, off) =
  save l, r, s ; path l, r ; numeric s ; 
% draw loc withpen pencircle scaled 10 withcolor .5white ; 
  s := len/2 - off ; if s<=0 : s := 0 elseif s>len : s := len fi ;  
  r := pat cutbefore loc ;
  r := (r cutafter point (arctime s of r) of r) ;
  s := len/2 + off ; if s<=0 : s := 0 elseif s>len : s := len fi ;  
  l := reverse (pat cutafter loc) ;
  l := (reverse (l cutafter point (arctime s of l) of l)) ;
  (l..r) 
enddef ; 

def rightarrow  (expr pat,tim,len) = pointarrow(pat,tim,len,-len) enddef ; 
def leftarrow   (expr pat,tim,len) = pointarrow(pat,tim,len,+len) enddef ; 
def centerarrow (expr pat,tim,len) = pointarrow(pat,tim,len,   0) enddef ;
\stopMPinclusions
\stopbuffer

\getbuffer[macros]

\startbuffer
\startMPcode
  pickup pencircle scaled 2pt; 

  path p ; p := fullcircle scaled 5cm ; draw p ; 

  for i=1,3,5,7 : 
    drawdot point i of p withpen pencircle scaled 10 withcolor .5white ; 
  endfor ; 

  drawarrow leftarrow   (p,point 1 of p,1cm)      withcolor red    ; 
  drawarrow rightarrow  (p,point 3 of p,1cm)      withcolor green  ; 
  drawarrow centerarrow (p,point 5 of p,1cm)      withcolor blue   ;  
  drawarrow pointarrow  (p,point 7 of p,2cm,.5cm) withcolor yellow ;
\stopMPcode
\stopbuffer

The following code will produce small arrows positioned at a
given location with a given length and optional shift. 

\typebuffer

The shift of .5cm in the last example (the yellow arrow) is 
a backward shift. This may be fuzzy, but negative values 
would be even more confusing. By default the arrow is 
centered around the given point. 

\startlinecorrection[blank]
\getbuffer
\stoplinecorrection

The code that produces the arrow is (here) defined as 
inclusion, but may end up it in the \MetaFun\ macro 
collection. 

\typebuffer[macros]

\stoptext 

[-- Attachment #2: a.pdf --]
[-- Type: application/pdf, Size: 25716 bytes --]

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

-------------------------------------------------------------------------
                                                  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] only message in thread

only message in thread, other threads:[~2000-08-30  9:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <3.0.5.32.20001129204148.009b7740@mail.northcoast.com>
2000-08-30  9:49 ` A Metapost need 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).