From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/109668 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Fabrice L Newsgroups: gmane.comp.tex.context Subject: Re: Units of xpart and ypart of a pair in MetaFun Date: Thu, 26 Nov 2020 12:20:20 -0500 Message-ID: <2E8A4110-3FA8-4D5B-869E-97F562BFE0A4@gmail.com> References: <68dba0aa-8cc8-0a93-29bf-81afc7bf9079@gmail.com> <380BF9A6-1F98-44AB-BB27-5ACB3F8061A3@gmail.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.21\)) Content-Type: multipart/mixed; boundary="===============0469540435357062232==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4677"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mailing list for ConTeXt users To: Keith McKay Original-X-From: ntg-context-bounces@ntg.nl Thu Nov 26 18:21:13 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiKxE-00015q-N4 for gctc-ntg-context-518@m.gmane-mx.org; Thu, 26 Nov 2020 18:21:12 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 19B241AA6BD; Thu, 26 Nov 2020 18:20:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hFfavCrkeABH; Thu, 26 Nov 2020 18:20:27 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D587E1AA6C0; Thu, 26 Nov 2020 18:20:25 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B32091AA6BF for ; Thu, 26 Nov 2020 18:20:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GX2AwTb3izsz for ; Thu, 26 Nov 2020 18:20:23 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.160.174; helo=mail-qt1-f174.google.com; envelope-from=fabrice.alpha@gmail.com; receiver= Original-Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 95BE51AA6B4 for ; Thu, 26 Nov 2020 18:20:23 +0100 (CET) Original-Received: by mail-qt1-f174.google.com with SMTP id d5so1584817qtn.0 for ; Thu, 26 Nov 2020 09:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=smkM6JgtyVlgpjKByLmvkHr2tDcKNhtO/yWk+vl/mNs=; b=amsy3XodeVXNO8LZ4ixIlw2sMBJWXkX9yGvHon1wy4e1LefdXhPWpocasg9aj8SIja MoUCKiItQA8z/5tDNzvlQdcjtJxlud16rL74mcnshw2aKj3tmnkWM+HRjmvqmxM8pdZj jlqn5t3GXPYwIq8aFR8RnXCUP54DFcxr5UpEnVxby9LptOeeg8vxJkZJubdIliiZI3Ql gQNzRZu4O1YoGQrtOk1o/syMGLT+/3vWUqVoy6eM02HV8RaZ8HpZ7qSEm5CuE6j5GJip BME0wFBbNlxgI8vlrV5oG2ww1QfJsR9+Hs57QP756bIJAt6uDduFqk71uCiZOHHdmb+n RBkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=smkM6JgtyVlgpjKByLmvkHr2tDcKNhtO/yWk+vl/mNs=; b=unBAnZv4CNYCNfDDYDtshMwBBhewX1eOvOErMrDKToHIvhl1RiLAMqeMn+M4NGRt/8 1m+fJybOdLEo2lBG9daGyNbYoeccs5OaGFWKvZzdcN/noF8b+YD9OIVkgjvyQQS25no4 ONLTt+eBUoVmwNR9pZjSnh4Btk9KY9i+NLgm7HDcYK0CLAu8vFlKWmozMm7t6kI10NpO 6Cwo3eBDhI7KQQ6sYzyYZTyKNafin0YB0w5aDc/mikpmQsIaTY5q7qlnrl/L+M7YGKB7 Nq5mreoEVNshLLpT21Btktqr8HnxQRM8KkLbomYOKBPue8AWhPMxC3DIshTwEGbkKpwC PW0w== X-Gm-Message-State: AOAM533qH2nZthv50wSbJhVqMy2YiKqMNpFcq8R51AFInSXlVnfhwr6S 5XtT3HXlV4tfowXjpR+IpgT4PoA3KvQ= X-Google-Smtp-Source: ABdhPJz2dUB9zN8G7pZ7h3U8BVNy4kkL/5QWpZdXZG5Ko1y7cJllDkQSRFMS2dRuGX5lut9EajDoXg== X-Received: by 2002:ac8:6b59:: with SMTP id x25mr4060166qts.144.1606411222533; Thu, 26 Nov 2020 09:20:22 -0800 (PST) Original-Received: from icovid.lan ([38.74.28.141]) by smtp.gmail.com with ESMTPSA id b17sm2986898qkl.123.2020.11.26.09.20.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2020 09:20:21 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3654.20.0.2.21) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:109668 Archived-At: --===============0469540435357062232== Content-Type: multipart/alternative; boundary="Apple-Mail=_15FD1ADF-79F5-4EB1-AEA1-F07676A90F64" --Apple-Mail=_15FD1ADF-79F5-4EB1-AEA1-F07676A90F64 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Keith, > Le 26 nov. 2020 =C3=A0 12:12, Keith McKay a = =C3=A9crit : > Thanks Fabrice and Hans. >=20 > I now see I can simplify some lines of the code: >=20 > pp :=3D ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:=3D = a[i]; >=20 > and >=20 > pp :=3D pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now = becomes pp :=3D pp --- a[i +1] ; >=20 > However I still have the problem in the calculation of xcoord and = ycoord which are used in the creation of path pp: > =09 > for squig =3D 1 step 1 until 15: >=20 > xcoord :=3D uniformdeviate(1) - 0.5 + (xpart a[i]/cf); >=20 > ycoord :=3D uniformdeviate(1) - 0.5+ (ypart a[i]/cf); >=20 > pp :=3D pp .. {curl 100}(xcoord*cm, ycoord*cm); >=20 > endfor; >=20 > I'm adding a small random amount to the x and ypart of the pair a[i] = to produce a path that is like a squiggle (gribouiller in French, = according to Google). I have to use cf to convert to the x and yparts to = centimeters since they seem to loose the centimeter units on separation. = I can't see anyway round this, or am I missing something? >=20 > Thanks > Keith McKay First =C2=AB uniformdeviate(1) - 0.5 =C2=BB could be modified to =C2=AB = uniformdeviate(0.5)=C2=BB. To add noise, you can use the randomized function of Metafun. For = exemple, you can write: draw pp randomized 1cm ; Fabrice. >=20 > On 26/11/2020 15:19, Fabrice L wrote: >> Hi keith, >>=20 >>> Le 26 nov. 2020 =C3=A0 10:09, Keith McKay > a =C3=A9crit : >>>=20 >>> Hi, >>>=20 >>> I have been using xpart and ypart to extract these values from pairs = of points in a path but I wasn't getting the correct result. I was = expecting: >>>=20 >>> pair (2cm, 11cm) to give xpart 2 and ypart 11 >>>=20 >>> However I was getting: >>>=20 >>> pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 >>>=20 >>> After much head scratching and reading the MetaPost and MetaFun = manuals, I realised that the units of xpart or ypart are in Postcript = points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get = the values of xpart or ypart in cm I would have to use a correction = factor. I had made the assumption that since the x and ypart in the pair = was in cm that the result would be in cm, but I see now that this is not = the case. Will I have to continue doing this or is there some magic = within MetaFun which takes account of the units in a pair and outputs = the result of x and ypart in the same units? >>>=20 >>> The MWE belows shows what I have been doing. >>>=20 >>> Thanks >>>=20 >>> Keith McKay >>>=20 >>> %%% MWE %%% >>> \setuppapersize [A5, landscape][A4, portrait] >>> \usecolors[crayola] >>> \starttext >>> \startMPpage >>> StartPage; >>> width :=3D PaperWidth ; height :=3D PaperHeight ; unit :=3D cm ; >>> numeric squig; >>> pair a[]; a0 =3D (2cm,11cm); a1 =3D (4cm,10cm); a2 =3D (6cm,9cm); = a3 =3D (8cm,8cm); >>> show xpart a[0], ypart a[0]; %Example of result from x and ypart = before applying correction factor (cf) % >>> cf :=3D 72/2.54; %Converts points/in to points/cm% >>> path pp; >>> for i =3D 0 step 1 until 3: >>> pp :=3D ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); >>> for squig =3D 1 step 1 until 15: >>> xcoord :=3D uniformdeviate(1) - 0.5 + (xpart a[i]/cf); >>> ycoord :=3D uniformdeviate(1) - 0.5+ (ypart a[i]/cf); >>> pp :=3D pp .. {curl 100}(xcoord*cm, ycoord*cm); >>> endfor; >>> pp :=3D pp --- cycle; >>> if i < 3 : >>> pp :=3D pp --- ((xpart a[i+1]/cf)*cm, (ypart = a[i+1])/cf*cm); >>> fi;=09 >>> f :=3D((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to = lighten/darken colour % >>> draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 = withcolor (f[white,\MPcolor{BurntSienna}]); >>> endfor; >>> StopPage; >>> \stopMPpage >>> \stoptext >>> %%%%%%%%%%%%%% >>>=20 >>=20 >> MetaPost (MetaFun) is taking care of everything regarding units. As = you ave discovered, everything is translated to a unique internal = dimension. So you can write: >>=20 >> a :=3D (1cm,2in) ; >>=20 >> with no problem. The =C2=AB cm =C2=BB and =C2=AB in =C2=BB parts of = the expression will become numbers to translate this number on the right = unit.=20 >> Fabrice. >>> = __________________________________________________________________________= _________ >>> If your question is of interest to others as well, please add an = entry to the Wiki! >>>=20 >>> maillist : ntg-context@ntg.nl / = http://www.ntg.nl/mailman/listinfo/ntg-context = >>> webpage : http://www.pragma-ade.nl / = http://context.aanhet.net >>> archive : https://bitbucket.org/phg/context-mirror/commits/ = >>> wiki : http://contextgarden.net >>> = __________________________________________________________________________= _________ >>>=20 --Apple-Mail=_15FD1ADF-79F5-4EB1-AEA1-F07676A90F64 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Keith,

Le 26 nov. 2020 =C3=A0 12:12, = Keith McKay <mckaymeister@gmail.com> a =C3=A9crit :

Thanks Fabrice = and Hans.

I now see I = can simplify some lines of the code:

pp :=3D ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); = now becomes pp:=3D a[i];

and

pp :=3D pp --- ((xpart a[i+1]/cf)*cm, = (ypart a[i+1])/cf*cm); now becomes pp :=3D pp --- a[i +1] ;

However I still have the problem in the calculation of xcoord = and ycoord which are used in the creation of path pp:
for = squig =3D 1 step 1 until 15:
xcoord :=3D = uniformdeviate(1) - 0.5 + (xpart a[i]/cf);
ycoord :=3D = uniformdeviate(1) - 0.5+ (ypart a[i]/cf);
pp :=3D pp .. {curl = 100}(xcoord*cm, ycoord*cm);
endfor;
I'm adding a small random amount = to the x and ypart of the pair a[i] to produce a path that is like a = squiggle (gribouiller in French, according to Google). I have to use cf = to convert to the x and yparts to centimeters since they seem to loose = the centimeter units on separation. I can't see anyway round this, or am = I missing something?
Thanks
Keith McKay

First = =C2=AB uniformdeviate(1) - 0.5 =C2=BB could be modified = to =C2=AB uniformdeviate(0.5)=C2=BB.

To add noise, you can use the randomized function = of Metafun. For exemple, you can write:

draw pp randomized 1cm ;

Fabrice.




On= 26/11/2020 15:19, Fabrice L wrote:
Hi keith,

Le 26 = nov. 2020 =C3=A0 10:09, Keith McKay <mckaymeister@gmail.com> a =C3=A9crit = :

Hi,

I have been using xpart and ypart to = extract these values from pairs of points in a path but I wasn't getting = the correct result. I was expecting:

pair (2cm, 11cm) to give xpart 2 and = ypart 11

However I was = getting:

pair (2cm, = 11cm) -> xpart 56.6929 and ypart 311.8096

After much head scratching and reading = the MetaPost and MetaFun manuals, I realised that the units of xpart or = ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an = inch, and thus to get the values of xpart or ypart in cm I would have to = use a correction factor. I had made the assumption that since the x and = ypart in the pair was in cm that the result would be in cm, but I see = now that this is not the case. Will I have to continue doing this or is = there some magic within MetaFun which takes account of the units in a = pair and outputs the result of x and ypart in the same units?

The MWE belows shows what I = have been doing.

Thanks

Keith McKay

%%% MWE %%%
\setuppapersize [A5, landscape][A4, = portrait]
\usecolors[crayola]
\starttext
\startMPpage
StartPage;
width :=3D = PaperWidth ; height :=3D PaperHeight ; unit :=3D cm ;
numeric squig;
pair a[]; a0 =3D (2cm,11cm); a1 =3D (4cm,10cm); a2 = =3D (6cm,9cm); a3 =3D (8cm,8cm);
show xpart a[0], ypart a[0]; %Example of result from = x and ypart before applying correction factor (cf) %
cf :=3D 72/2.54; %Converts points/in to = points/cm%
path pp;
for i =3D 0 step 1 until 3:
pp :=3D ((xpart a[i])/cf*cm, (ypart = a[i])/cf*cm);
for squig =3D 1 = step 1 until 15:
xcoord = :=3D uniformdeviate(1) - 0.5 + (xpart a[i]/cf);
ycoord :=3D uniformdeviate(1) - 0.5+ = (ypart a[i]/cf);
pp :=3D = pp .. {curl 100}(xcoord*cm, ycoord*cm);
endfor;
pp :=3D = pp --- cycle;
if i < 3 = :
pp :=3D pp --- ((xpart = a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm);
fi;
f :=3D((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % = Factor to lighten/darken colour %
draw pp withpen pencircle xscaled 0.5mm yscaled = .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]);
endfor;
StopPage;
\stopMPpage
\stoptext
%%%%%%%%%%%%%%


MetaPost = (MetaFun) is taking care of everything regarding units. As you ave = discovered, everything is translated to a unique internal dimension. So = you can write:

 a :=3D (1cm,2in) ;

with no problem. The =C2=AB cm = =C2=BB and =C2=AB in =C2=BB parts of the expression will become = numbers to translate this number on the right unit. 
Fabrice.

_______________________________________________________________= ____________________ 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://context.aanhet.net archive  : https://bitbucket.org/phg/context-mirror/commits/= wiki     : http://contextgarden.net = __________________________________________________________________________= _________


= --Apple-Mail=_15FD1ADF-79F5-4EB1-AEA1-F07676A90F64-- --===============0469540435357062232== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============0469540435357062232==--