From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/11597 Path: main.gmane.org!not-for-mail From: Giuseppe Bilotta Newsgroups: gmane.comp.tex.context Subject: Re[4]: MetaPost/Fun question Date: Sun, 23 Mar 2003 14:34:34 +0100 Sender: ntg-context-admin@ntg.nl Message-ID: <14611799596.20030323143434@iol.it> References: <5.1.0.14.1.20030322222005.026b1b68@server-1> <12815828760.20030322223256@iol.it> Reply-To: ntg-context@ntg.nl NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1048426820 21619 80.91.224.249 (23 Mar 2003 13:40:20 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 23 Mar 2003 13:40:20 +0000 (UTC) Original-X-From: ntg-context-admin@ntg.nl Sun Mar 23 14:40:15 2003 Return-path: Original-Received: from ref.vet.uu.nl ([131.211.172.13] helo=ref.ntg.nl) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18x5hv-0005cV-00 for ; Sun, 23 Mar 2003 14:40:15 +0100 Original-Received: from ref.ntg.nl (localhost.localdomain [127.0.0.1]) by ref.ntg.nl (Postfix) with ESMTP id 89F5B10AE8; Sun, 23 Mar 2003 14:40:12 +0100 (MET) Original-Received: from smtp1.libero.it (smtp1.libero.it [193.70.192.51]) by ref.ntg.nl (Postfix) with ESMTP id 88D4D10AE8 for ; Sun, 23 Mar 2003 14:37:00 +0100 (MET) Original-Received: from [151.29.140.124] (151.29.140.124) by smtp1.libero.it (6.7.015) id 3E44E7FA01079342 for ntg-context@ntg.nl; Sun, 23 Mar 2003 14:37:01 +0100 X-Mailer: The Bat! (v1.63 Beta/7) X-Priority: 3 (Normal) Original-To: ntg-context@ntg.nl In-Reply-To: Errors-To: ntg-context-admin@ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.0.13 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.comp.tex.context:11597 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:11597 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