From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/109667 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 17:12:44 +0000 Organization: The PotHole Press Message-ID: 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 Content-Type: multipart/mixed; boundary="===============1557490412466599503==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24078"; 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 To: Fabrice L , mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Nov 26 18:16:33 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 1kiKsi-00067D-TX for gctc-ntg-context-518@m.gmane-mx.org; Thu, 26 Nov 2020 18:16:32 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 102501AA6C2; Thu, 26 Nov 2020 18:12:50 +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 kAnVUtFjsanf; Thu, 26 Nov 2020 18:12:49 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 021BC1AA6BE; Thu, 26 Nov 2020 18:12:49 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id BE3ED1AA6B2 for ; Thu, 26 Nov 2020 18:12:47 +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 DgjoGYTWNGbz for ; Thu, 26 Nov 2020 18:12:46 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.221.43; helo=mail-wr1-f43.google.com; envelope-from=mckaymeister@gmail.com; receiver= Original-Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 D3F851AA6A7 for ; Thu, 26 Nov 2020 18:12:46 +0100 (CET) Original-Received: by mail-wr1-f43.google.com with SMTP id l1so2898744wrb.9 for ; Thu, 26 Nov 2020 09:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:organization:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=XVrtFN9M2cTs3VSU7qBIb3j+TezGt9pF0zsc5zE4L50=; b=o7tJFJEzlxfSCGSJhYmfF3wV55THuA2Qi3Wu7kuWai3Sfy/Tzi0fanxiyY2uyOdT7T AL7Vaf8F5m/Qdj55DwDCHpeZdRFLM648xzuVm6qWWL5VBpaM6Al8etnbf33H0HlFyu6n fKwSSBMsgPe16RsgIfevEUBTc26Ffc5npEz/UVF6fX1fuql5XaFHPugw4/qx40DlkMKR L6G/7OOh4pfIbUqjMnLCur7oLvZKRA6wLpu/+A2MdNNjQuhpAL/FkikVAWBFyqjHbDlz xVnjstYIGlYJf0vpme1hV3PYVDsoC+qJLcjkvUL0qlqth2+oPc1LkuMlDFhG5X3TFNl1 Q3JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=XVrtFN9M2cTs3VSU7qBIb3j+TezGt9pF0zsc5zE4L50=; b=ClLv5RSwFq8ZIcRWGBjLF5cgbEGRaFaczWdg/jrPuKuK+Caaut1naVMOe42jfMWXJE QFU27g5VuEzQjfwGPs4yEJWp3u3uRwJcnW4Wyx8TjHp1vIo7s5PRvpbA2G2VPbHcwIsr nXsS+2DpNqPM7Fm+4Q8Ro7v6e8Sp1zZqnu60mIhYJB6osQkD6Iy+GA+2UgF5bsp03NWM RMUkHT2U5z3bALQ/D4hinPaIehhJuUJ3/LVuw8QKOn5Zp199WShHKkYgJ5EUv9Y+ECzV q52CRtCH6OCNk8kczkyxh3U8xvuYO2Qljo5UGQptxeQ5Y9rBW3CMYnXPJil57+K+Z5VF aFFA== X-Gm-Message-State: AOAM532WJoeO0v6qdE9dqyPWNwg6vktxNm6COz5XeVOGWkuEDDVHUOTq Uc5egqg8NQy3hSu66frr3OmApPR9QKA= X-Google-Smtp-Source: ABdhPJyzxNsc4Es7QnvX5rH2APFHYiAPm2EeW9xWtMTpzBAw7xjAPGAue8EAQJztOPg/p3U1Co5NoA== X-Received: by 2002:a5d:4388:: with SMTP id i8mr5197933wrq.262.1606410766029; Thu, 26 Nov 2020 09:12:46 -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 q81sm9702254wme.34.2020.11.26.09.12.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Nov 2020 09:12:45 -0800 (PST) In-Reply-To: <380BF9A6-1F98-44AB-BB27-5ACB3F8061A3@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:109667 Archived-At: This is a multi-part message in MIME format. --===============1557490412466599503== Content-Type: multipart/alternative; boundary="------------0104E41112C9296D6512849C" Content-Language: en-US This is a multi-part message in MIME format. --------------0104E41112C9296D6512849C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 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 >> ___________________________________________________________________________________ >> > --------------0104E41112C9296D6512849C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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

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 ___________________________________________________________________________________


--------------0104E41112C9296D6512849C-- --===============1557490412466599503== 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== --===============1557490412466599503==--