From: Taco Hoekwater <taco@elvenkind.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Marco <netuse@lavabit.com>
Subject: Re: Metapost: union test of two paths
Date: Sat, 03 Jul 2010 12:19:30 +0200 [thread overview]
Message-ID: <4C2F0EB2.1020508@elvenkind.com> (raw)
In-Reply-To: <4C2EEED4.1010300@elvenkind.com>
[-- Attachment #1: Type: text/plain, Size: 678 bytes --]
On 07/03/2010 10:03 AM, Taco Hoekwater wrote:
>
>> If this is too complicated, it might help if I can find out if a given
>> point lies inside a given cycled path.
>
> Even this is fairly tricky. Some important questions are:
I thought this was a neat thing to try to write a macro for. Attached
is a test file that defines a macro inside() that takes two arguments:
a point and a cyclic path. It returns true if the point lies inside
that path, in most cases. There are lots of problems with it;
what happens to a point actually on the curve is basically undefined,
and self-intersects sometimes make it fail in interesting ways.
Anyway, perhaps it helps.
Best wishes,
Taco
[-- Attachment #2: inside.mp --]
[-- Type: text/plain, Size: 1783 bytes --]
def inside(expr j, p) =
begingroup
save n;
hide(
save done, L, P, t, bottom, top;
boolean done;
path L,P;
numeric t[];
pair bottom, top;
bottom = llcorner p;
top = urcorner p;
P := p;
n := 0;
if (xpart j <= xpart bottom) or (xpart j >= xpart top)
or (ypart j <= ypart bottom) or (ypart j >= ypart top):
else:
L := j--(xpart j, ((ypart bottom)-100));
done := false;
forever:
(t[n],whatever) = L intersectiontimes P;
if (t[n]<0) and (n>0) : % find upward match
P := reverse P;
numeric t[];
L := j--(xpart j, ((ypart bottom)-100));
forever:
(t[n],whatever) = L intersectiontimes P;
exitif t[n]<0;
L := subpath (t[n]+epsilon, length L) of L;
n := n + 1;
endfor;
done := true;
fi
exitif done;
L := subpath (t[n]+epsilon,length L) of L;
n := n + 1;
endfor;
fi )
if (n>1) and (not odd n): true else: false fi
endgroup
enddef;
beginfig(1);
path P;
% P:= (fullcircle scaled 20) shifted (20,20);
% P:= (0,10){down}..(10,10){up} .. (30,10){down} .. (20,10){up}..cycle;
% P := unitsquare scaled 10 rotated 30 shifted (20,10);
% P := (10,10){down}..(30,10){up} .. (0,10){down} .. (20,10){up}..cycle;
P := (0,10){down}..(10,0){right}..(30,5){up}..
(20,10){up}..(30,15){up}..(20,20){left}..cycle;
draw P withcolor red;
nx := 100;
ny := 100;
pair endgrid;
endgrid := (30,30);
pickup pencircle xscaled (xpart endgrid/nx) yscaled (ypart endgrid/ny);
pair J;
for k = 1 upto nx:
for l = 1 upto ny:
J := (k/nx*xpart endgrid,l/ny*ypart endgrid);
if inside(J,P):
drawdot J withcolor green;
else:
drawdot J withcolor blue;
fi
endfor;
endfor;
currentpicture := currentpicture scaled 10;
endfig;
end.
[-- Attachment #3: Type: text/plain, Size: 486 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2010-07-03 10:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-02 17:01 Marco
2010-07-03 8:03 ` Taco Hoekwater
2010-07-03 10:19 ` Taco Hoekwater [this message]
2010-07-03 13:34 ` Taco Hoekwater
2010-07-03 14:54 ` Marco
2010-07-03 23:11 ` Marco
2010-07-04 6:47 ` Taco Hoekwater
2010-07-04 8:09 ` Marco
2010-07-04 8:21 ` Taco Hoekwater
2010-07-03 10:33 ` Alan BRASLAU
2010-07-03 13:36 ` Taco Hoekwater
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=4C2F0EB2.1020508@elvenkind.com \
--to=taco@elvenkind.com \
--cc=netuse@lavabit.com \
--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).