* Tangent vector
@ 2001-09-26 21:47 David Arnold
2001-09-29 17:37 ` Hans Hagen
2001-09-29 21:24 ` Patrick Gundlach
0 siblings, 2 replies; 4+ messages in thread
From: David Arnold @ 2001-09-26 21:47 UTC (permalink / raw)
All,
In the second image in this file, I am disappointed to find that the vector
doesn't look tangent to the path at the tip of the position vector.
input mp-tool;
beginfig(1);
%initialize scale
numeric u; 6u=3in;
%draw coordinate axes
drawdblarrow (-1u,0)--(5u,0);
label.rt(btex $x$ etex, (5u,0));
drawdblarrow (0,-1u)--(0,3u);
label.top(btex $y$ etex, (0,3u));
%path
path p;
p:=(-1,1)..(1,2)..(5,2.5);
p:=p scaled u;
draw p withcolor blue;
%position vector
drawarrow (0,0)--(1u,2u) withcolor red;
label.lrt(btex ${\bf r}(t)$ etex, 0.5[(0,0),(1u,2u)]);
dotlabel.ulft(btex $(x(t),y(t))$ etex, (1u,2u));
endfig;
beginfig(2);
%initialize scale
numeric u; 6u=3in;
%draw coordinate axes
drawdblarrow (-1u,0)--(5u,0);
label.rt(btex $x$ etex, (5u,0));
drawdblarrow (0,-1u)--(0,3u);
label.top(btex $y$ etex, (0,3u));
%path
path p;
p:=(-1,1)...(1,2)...(5,2.5);
%position vector
drawarrow (0,0)--(1u,2u) withcolor red;
label.lrt(btex ${\bf r}(t)$ etex, 0.5[(0,0),(1u,2u)]);
dotlabel.ulft(btex $(x(t),y(t))$ etex, (1u,2u));
%calculate the velocity vector
numeric t;
t:=directiontime (1u,2u) of p;
pair d;
d:=direction t of p;
drawarrow ((0,0)--d) scaled u shifted (1u,2u);
p:=p scaled u;
draw p withcolor blue;
endfig;
end.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tangent vector
2001-09-26 21:47 Tangent vector David Arnold
@ 2001-09-29 17:37 ` Hans Hagen
2001-09-29 21:24 ` Patrick Gundlach
1 sibling, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2001-09-29 17:37 UTC (permalink / raw)
Cc: ntg-context
At 02:47 PM 9/26/2001 -0700, David Arnold wrote:
>In the second image in this file, I am disappointed to find that the vector
>doesn't look tangent to the path at the tip of the position vector.
now, are your disappointed in me, metapost, or yourself -)
how about: d:=direction 1 of p; since you *know* that 1,2 (not 1u,2u !) is
point 1 there is no need for time calculations
also, keep in mind that this times/point stuff is sensitive to rounding
errors (in that respect you can indeed be disappointed in mp)
now, your error result from calculating a time for a scaled point (watch
the 1u,2u) while you have no scaled path but scale it afterwards.
i think that your code snippet will become more clean if you say p := p
scaled u after setting p and then work on the scaled path, or alternatively
use no u's and only scale the whole to u, but this is a matter of taste.
i've fallen in this trap some times too [at first i thought that your
sample was a rounding error; suggestion: in such case draw d withpen
pencircle scaled 5 helps; add this to your code and you will see that you
got the point + 1,2 near point zero which indeed has the tangent you got.
Hans
-------------------------------------------------------------------------
Hans Hagen | PRAGMA ADE | pragma@wxs.nl
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] 4+ messages in thread
* Tangent vector
2001-09-26 21:47 Tangent vector David Arnold
2001-09-29 17:37 ` Hans Hagen
@ 2001-09-29 21:24 ` Patrick Gundlach
2001-09-30 20:00 ` Hans Hagen
1 sibling, 1 reply; 4+ messages in thread
From: Patrick Gundlach @ 2001-09-29 21:24 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 1907 bytes --]
Hallo David,
> In the second image in this file, I am disappointed to find that the
> vector doesn't look tangent to the path at the tip of the position
> vector.
[...]
OK, there are several issues here, that might be confusing.
> %initialize scale
> numeric u; 6u=3in;
>
> %draw coordinate axes
[...]
> %calculate the velocity vector
> numeric t;
> t:=directiontime (1u,2u) of p;
wrong: directiontime looks at the path p and tries to find a slope of
(1u,2u). Since it cannot find one, t gets -1 (check with show t).
> pair d;
> d:=direction t of p;
since t = -1 it looks at the first point and finds the direction there.
> drawarrow ((0,0)--d) scaled u shifted (1u,2u);
This is messy, since d has the correct correct direction but a "somewhat
arbitrary" magnitude. See the Metapost manual p. 28.
> p:=p scaled u;
If you do some calculations with path p, you have to scale it before doing
these calculations!
So here is my solution (tested with context/metafun)
----------------------------------
%initialize scale
numeric u; 6u=3in;
%draw coordinate axes
drawdblarrow (-1u,0)--(5u,0);
label.rt(btex $x$ etex, (5u,0));
drawdblarrow (0,-1u)--(0,3u);
label.top(btex $y$ etex, (0,3u));
%path
path p;
p:=(-1,1)...(1,2)...(5,2.5);
p:=p scaled u;
%position vector
drawarrow (0,0)--(1u,2u) withcolor red;
label.lrt(btex ${\bf r}(t)$ etex, 0.5[(0,0),(1u,2u)]);
dotlabel.ulft(btex $(x(t),y(t))$ etex, (1u,2u));
%calculate the velocity vector
numeric t;
% at what time does my point intersect w/ the path?
(t,whatever) = p intersectiontimes ((1u,-infinity)--(1u,infinity));
pair d;
d:=direction t of p;
%warning! d now has the correct direction but not!! magnitude
drawarrow (origin -- ((2u,0) rotated angle d))
shifted (1u,2u)
withcolor green;
draw p withcolor blue;
---------------------------------------
--
Viele Grüße,
Patrick Gundlach
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Tangent vector
2001-09-29 21:24 ` Patrick Gundlach
@ 2001-09-30 20:00 ` Hans Hagen
0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2001-09-30 20:00 UTC (permalink / raw)
Cc: ntg-context
At 11:24 PM 9/29/2001 +0200, Patrick Gundlach wrote:
> % at what time does my point intersect w/ the path?
> (t,whatever) = p intersectiontimes ((1u,-infinity)--(1u,infinity));
ah, that's real metapost. i still have to learn to think in whatevers.
maybe this also is less sensitive to rounding problems
Hans
-------------------------------------------------------------------------
Hans Hagen | PRAGMA ADE | pragma@wxs.nl
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] 4+ messages in thread
end of thread, other threads:[~2001-09-30 20:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-26 21:47 Tangent vector David Arnold
2001-09-29 17:37 ` Hans Hagen
2001-09-29 21:24 ` Patrick Gundlach
2001-09-30 20:00 ` 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).