From: Giuseppe Bilotta <gip.bilotta@iol.it>
Subject: Re[4]: MetaPost/Fun question
Date: Sun, 23 Mar 2003 14:34:34 +0100 [thread overview]
Message-ID: <14611799596.20030323143434@iol.it> (raw)
In-Reply-To: <vg065qbm0u7.fsf@localhost.localdomain>
Sunday, March 23, 2003 Emil Hedevang Lohse wrote:
EHL> I implemented it by finding some intersectiontime and the recursively
EHL> finding the intersectionstimes of the two subpaths (each with some
EHL> neighbourhood of the first intersection point cut off). For the time
EHL> being I cannot find my code, but here it is in pseude code.
EHL> let p and q be paths;
EHL> let (s,t) be a pair of intersection times of p and q;
EHL> recursively find the intersection times of the
EHL> subpath (0, s - small number) of p and q;
EHL> store (s,t);
EHL> recursively find the intersection times of the
EHL> subpath (s + small number, infinity) of p and q;
EHL> feel happy;
EHL> When done this way, the intersection times will be sorted according to
EHL> the first path.
Ok, I came up with something which might be useful; Hans, you may
consider adding it to the MetaFun core:
newinternal intersectiontolerance ; intersectiontolerance := 4*eps ;
def findallintersections (expr p, q) =
pair intersections[], intersectionpoints[] ; intersectionsfound := 0 ; % reset intersections
if (path p and path q):
begingroup ;
save j, tp ; path tp; tp := p ;
j:= 0 ;
intersections[j] = tp intersectiontimes q ;
forever:
exitif (xpart intersections[j] = -1) or (ypart intersections[j] = -1) or
(xpart intersections[j] + intersectiontolerance > length p) ;
intersectionpoints[j] = point ypart intersections[j] of q ;
j:=j+1 ;
tp := subpath (xpart intersections[j-1] + intersectiontolerance, length p) of p ;
% watch the trick to ensure that the times are
% relative to the original paths
intersections[j] := tp intersectiontimes q ;
intersections[j] := (xpart (p intersectiontimes ((point xpart intersections[j] of tp)--cycle)),
ypart intersections[j]);
endfor ;
intersectionsfound := j ;
endgroup ;
fi ;
enddef ;
Some notes:
* this is my first MetaPost macro, so I expect it to be slow,
inefficient, and buggy; feel free to comment
* USAGE: findallintersections(path, path) reinitializes the
following global expressions:
+ intersectionsfound, a numeric containing the number of
intersections
+ intersections[0] .. intersections[intersectionsfound-1], pairs
containing the time of the intersections on the two paths
+ intersectionpoints[0] ..
intersectionpoints[intersectionsfound-1], points of intersection
of the two paths
* PARAMETER: there is a global parameter intersectiontolerance:
setting it too low will send the macro in a neverending loop in case of
tangent curves (example:
beginfig(1)
path c[] ;
c1:= fullcircle scaled 10cm ;
c2:= fullsquare scaled 10cm ;
draw c1 withcolor blue; draw c2 withcolor blue;
loggingall ;
findallintersections (c1, c2) ;
show intersectionsfound ;
for i= 0 upto intersectionsfound-1 : drawpoint intersectionpoints[i] ; endfor ;
endfig
will fail for intersectiontolerance:=eps ;
Comments? Ideas? Suggestions?
--
Giuseppe "Oblomov" Bilotta
next prev parent reply other threads:[~2003-03-23 13:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-22 20:59 Giuseppe Bilotta
2003-03-22 21:23 ` Hans Hagen
2003-03-22 21:32 ` Re[2]: " Giuseppe Bilotta
2003-03-22 23:35 ` Emil Hedevang Lohse
2003-03-23 13:34 ` Giuseppe Bilotta [this message]
2003-03-24 12:53 ` Re[4]: " Guy Worthington
2003-03-24 13:49 ` Giuseppe Bilotta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14611799596.20030323143434@iol.it \
--to=gip.bilotta@iol.it \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).