From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/109690 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Keith McKay Newsgroups: gmane.comp.tex.context Subject: Re: Units of xpart and ypart of a pair in MetaFun Date: Thu, 26 Nov 2020 20:29:58 +0000 Organization: The PotHole Press Message-ID: <48755178-4e64-e059-84cf-1852e9735fe5@gmail.com> References: <68dba0aa-8cc8-0a93-29bf-81afc7bf9079@gmail.com> <380BF9A6-1F98-44AB-BB27-5ACB3F8061A3@gmail.com> <2E8A4110-3FA8-4D5B-869E-97F562BFE0A4@gmail.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5415354975189892917==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28269"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.4.2 Cc: mailing list for ConTeXt users To: Fabrice L Original-X-From: ntg-context-bounces@ntg.nl Thu Nov 26 21:30:25 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 1kiNuL-0007Fe-60 for gctc-ntg-context-518@m.gmane-mx.org; Thu, 26 Nov 2020 21:30:25 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id EB54A1AA715; Thu, 26 Nov 2020 21:30:04 +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 Q2FjKc87dwQj; Thu, 26 Nov 2020 21:30:03 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 0A6A81AA719; Thu, 26 Nov 2020 21:30:03 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B83FC1AA710 for ; Thu, 26 Nov 2020 21:30:01 +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 HqMOi3VX8sXf for ; Thu, 26 Nov 2020 21:30:00 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.128.47; helo=mail-wm1-f47.google.com; envelope-from=mckaymeister@gmail.com; receiver= Original-Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 AF0EC1AA709 for ; Thu, 26 Nov 2020 21:30:00 +0100 (CET) Original-Received: by mail-wm1-f47.google.com with SMTP id a3so3580791wmb.5 for ; Thu, 26 Nov 2020 12:30:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=SIe1yfTl9mJk+dTsc92qmAdmIPIMgUU0VlPZiUdq7TE=; b=fHIcz+h2oR1ul4SrXLtEZaBU1L1OluWeeirJdNME0KpZlm8tw+cmdTtA6PPelJn2AK KcGsNbYRFcYCqEkK8zP+FCojgwHnlZFVOr/8ci/1H7tiyDgrB801ZAONEHKHe7GazkMG MnadOx5VSL/OP9Vgltcdu8hA0P/uoOC0nSEiLh0qN0xTD4dI6xwvnJM0PFUxUi8O2Lqi U4bvfiMr3MW2PRXlA8gjzpo2eHr85NXBk3zgpZl3sLIgUlj5IKxhMe0+Iv334xuavISL zU1HNL/uSIGaOeUtDn1wSlWqLaCwNetmcKe2F6K7ERqlgQjMRpw/6IFLEtrr2z6iJXG6 gJlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=SIe1yfTl9mJk+dTsc92qmAdmIPIMgUU0VlPZiUdq7TE=; b=WJla7SLsrUS4ahDyKSEYNqjpQdS+MuoGQrCrKz0lakY/FmYkXCT2x40wg/BIuidM4R WT9feyewKCF9vpQLHwGQnpM02JBQOmqHBbIr4rrWBXSKpeOZ2pQxJItQxZLIjud6BBWh J5FnaEAoHRTEkQhVxQt73VFn2uXqwCaK2vqwgvyjhWyUF87jwKr+LX2X9awwhjb6QE8l PYMAAypSMXRZW8+d1kDwI0vYBVcbnvczXToXf6Lnsc5G12U2XllPQnmlsg6t3m+zJt+O zy59UJuPiEyxOZlZP8ierG52La4HfY/RNL5DsfI7M7GIDtNYnRhO+LX/KFndo6pxNDKr /wNQ== X-Gm-Message-State: AOAM530CQv1b9BgZfHZ/lBbw8Fz7gDd/+WUbVHTiBiH9olkjyzPMPYip ay+zD+3A5NQgykLkSxywJPwhdPsfHFaG+g== X-Google-Smtp-Source: ABdhPJwhcV0YP2IJvIgZfr40I5sWIP+9Ac6Xpi1W3pDObqt1Y2D/LFXBITNHdq3PXo4hDwCPgWX6Cg== X-Received: by 2002:a1c:3c8a:: with SMTP id j132mr5163095wma.75.1606422599971; Thu, 26 Nov 2020 12:29:59 -0800 (PST) Original-Received: from Keiths-Mac-mini.local (cpc100594-uddi29-2-0-cust51.20-3.cable.virginm.net. [82.42.107.52]) by smtp.googlemail.com with ESMTPSA id h83sm9745499wmf.9.2020.11.26.12.29.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Nov 2020 12:29:59 -0800 (PST) In-Reply-To: <2E8A4110-3FA8-4D5B-869E-97F562BFE0A4@gmail.com> Content-Language: en-US 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:109690 Archived-At: This is a multi-part message in MIME format. --===============5415354975189892917== Content-Type: multipart/alternative; boundary="------------C6DC5500710B54FDBBF886A5" Content-Language: en-US This is a multi-part message in MIME format. --------------C6DC5500710B54FDBBF886A5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit /First « //uniformdeviate(1) - 0.5// » could be modified to « //uniformdeviate(0.5)//»./ / / /To add noise, you can use the randomized function of Metafun. For exemple, you can write:/ / / /draw pp randomized 1cm ;/ / / That's true Fabrice but in this use case I wanted a random number between -0.5 and +0.5, and I wasn't sure I would get that with randomized. Thanks again Keith McKay/ / On 26/11/2020 17:20, Fabrice L wrote: > Keith, > >> Le 26 nov. 2020 à 12:12, Keith McKay > > a écrit : >> >> Thanks Fabrice and Hans. >> >> I now see I can simplify some lines of the code: >> >> pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:= a[i]; >> >> and >> >> pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now >> becomes pp := 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 = 1 step 1 until 15: >> xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); >> ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); >> pp := 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 « uniformdeviate(1) - 0.5 » could be modified to « > uniformdeviate(0.5)». > > 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 à 10:09, Keith McKay >>> > a écrit : >>>> >>>> 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 := PaperWidth ; height := PaperHeight ; unit := cm ; >>>> numeric squig; >>>> pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = >>>> (8cm,8cm); >>>> show xpart a[0], ypart a[0]; %Example of result from x and ypart >>>> before applying correction factor (cf) % >>>> cf := 72/2.54; %Converts points/in to points/cm% >>>> path pp; >>>> for i = 0 step 1 until 3: >>>> pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); >>>> for squig = 1 step 1 until 15: >>>> xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); >>>> ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); >>>> pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); >>>> endfor; >>>> pp := pp --- cycle; >>>> if i < 3 : >>>> pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); >>>> fi; >>>> f :=((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 := (1cm,2in) ; >>> >>> with no problem. The « cm » and « in » 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 >>>> ___________________________________________________________________________________ >>>> > --------------C6DC5500710B54FDBBF886A5 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
First « uniformdeviate(1) - 0.5 » could be modified to « uniformdeviate(0.5)».

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

draw pp randomized 1cm ;

That's true Fabrice but in this use case I wanted a random number between -0.5 and +0.5, and I wasn't sure I would get that with randomized.
Thanks again
Keith McKay
On 26/11/2020 17:20, Fabrice L wrote:
Keith,

Le 26 nov. 2020 à 12:12, Keith McKay <mckaymeister@gmail.com> a écrit :

Thanks Fabrice and Hans.

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

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

and

pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now becomes pp := 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 = 1 step 1 until 15:
xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf);
ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf);
pp := 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 « uniformdeviate(1) - 0.5 » could be modified to « uniformdeviate(0.5)».

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 à 10:09, Keith McKay <mckaymeister@gmail.com> a écrit :

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 := PaperWidth ; height := PaperHeight ; unit := cm ;
numeric squig;
pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm);
show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) %
cf := 72/2.54; %Converts points/in to points/cm%
path pp;
for i = 0 step 1 until 3:
pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm);
for squig = 1 step 1 until 15:
xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf);
ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf);
pp := pp .. {curl 100}(xcoord*cm, ycoord*cm);
endfor;
pp := pp --- cycle;
if i < 3 :
pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm);
fi;
f :=((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 := (1cm,2in) ;

with no problem. The « cm » and « in » 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 ___________________________________________________________________________________


--------------C6DC5500710B54FDBBF886A5-- --===============5415354975189892917== 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== --===============5415354975189892917==--