ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Units of xpart and ypart of a pair in MetaFun
@ 2020-11-26 15:09 Keith McKay
  2020-11-26 15:19 ` Fabrice L
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Keith McKay @ 2020-11-26 15:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2020 bytes --]

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

%%%%%%%%%%%%%%


[-- Attachment #1.2: Type: text/html, Size: 6795 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 15:09 Units of xpart and ypart of a pair in MetaFun Keith McKay
@ 2020-11-26 15:19 ` Fabrice L
  2020-11-26 17:12   ` Keith McKay
  2020-11-26 15:22 ` Hans Hagen
  2020-11-27  8:30 ` Taco Hoekwater
  2 siblings, 1 reply; 10+ messages in thread
From: Fabrice L @ 2020-11-26 15:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: mckaymeister


[-- Attachment #1.1: Type: text/plain, Size: 3310 bytes --]

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 <mailto:ntg-context@ntg.nl> / http://www.ntg.nl/mailman/listinfo/ntg-context <http://www.ntg.nl/mailman/listinfo/ntg-context>
> webpage  : http://www.pragma-ade.nl <http://www.pragma-ade.nl/> / http://context.aanhet.net <http://context.aanhet.net/>
> archive  : https://bitbucket.org/phg/context-mirror/commits/ <https://bitbucket.org/phg/context-mirror/commits/>
> wiki     : http://contextgarden.net <http://contextgarden.net/>
> ___________________________________________________________________________________
> 


[-- Attachment #1.2: Type: text/html, Size: 7962 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 15:09 Units of xpart and ypart of a pair in MetaFun Keith McKay
  2020-11-26 15:19 ` Fabrice L
@ 2020-11-26 15:22 ` Hans Hagen
  2020-11-27  8:30 ` Taco Hoekwater
  2 siblings, 0 replies; 10+ messages in thread
From: Hans Hagen @ 2020-11-26 15:22 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Keith McKay

On 11/26/2020 4:09 PM, Keith McKay wrote:
> 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.

cm is not really a unit but a multiplier

cf := 72/2.54; %Converts points/in to points/cm%

message(cm);
message(cf);



> 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
> 
> %%%%%%%%%%%%%%
> 
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 15:19 ` Fabrice L
@ 2020-11-26 17:12   ` Keith McKay
  2020-11-26 17:20     ` Fabrice L
  2020-11-26 17:25     ` Hans Hagen
  0 siblings, 2 replies; 10+ messages in thread
From: Keith McKay @ 2020-11-26 17:12 UTC (permalink / raw)
  To: Fabrice L, mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 4367 bytes --]

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 
>> <mailto: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 
>> <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context 
>> <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage 
>>  :http://www.pragma-ade.nl 
>> <http://www.pragma-ade.nl/>/http://context.aanhet.net 
>> <http://context.aanhet.net/> archive 
>>  :https://bitbucket.org/phg/context-mirror/commits/ 
>> <https://bitbucket.org/phg/context-mirror/commits/> wiki 
>>     :http://contextgarden.net <http://contextgarden.net/> 
>> ___________________________________________________________________________________
>>
>

[-- Attachment #1.2: Type: text/html, Size: 11950 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 17:12   ` Keith McKay
@ 2020-11-26 17:20     ` Fabrice L
  2020-11-26 20:29       ` Keith McKay
  2020-11-26 17:25     ` Hans Hagen
  1 sibling, 1 reply; 10+ messages in thread
From: Fabrice L @ 2020-11-26 17:20 UTC (permalink / raw)
  To: Keith McKay; +Cc: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 4854 bytes --]

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 <mailto: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 <mailto:ntg-context@ntg.nl> / http://www.ntg.nl/mailman/listinfo/ntg-context <http://www.ntg.nl/mailman/listinfo/ntg-context>
>>> webpage  : http://www.pragma-ade.nl <http://www.pragma-ade.nl/> / http://context.aanhet.net <http://context.aanhet.net/>
>>> archive  : https://bitbucket.org/phg/context-mirror/commits/ <https://bitbucket.org/phg/context-mirror/commits/>
>>> wiki     : http://contextgarden.net <http://contextgarden.net/>
>>> ___________________________________________________________________________________
>>> 


[-- Attachment #1.2: Type: text/html, Size: 12081 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 17:12   ` Keith McKay
  2020-11-26 17:20     ` Fabrice L
@ 2020-11-26 17:25     ` Hans Hagen
  2020-11-26 19:56       ` Keith McKay
  1 sibling, 1 reply; 10+ messages in thread
From: Hans Hagen @ 2020-11-26 17:25 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Keith McKay, Fabrice L

On 11/26/2020 6:12 PM, Keith McKay wrote:
> 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?


	for squig = 1 step 1 until 15:
		xcoord := (xpart a[i]/cf);
		ycoord := (ypart a[i]/cf);
         xcoord := xcoord randomized (xcoord/50);
         ycoord := ycoord randomized (ycoord/50);
		pp := pp  .. { curl 100 } (xcoord*cm, ycoord*cm);
	endfor;


> 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 
>>> <mailto: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 
>>> <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context 
>>> <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage 
>>>  :http://www.pragma-ade.nl 
>>> <http://www.pragma-ade.nl/>/http://context.aanhet.net 
>>> <http://context.aanhet.net/> archive 
>>>  :https://bitbucket.org/phg/context-mirror/commits/ 
>>> <https://bitbucket.org/phg/context-mirror/commits/> wiki 
>>>     :http://contextgarden.net <http://contextgarden.net/> 
>>> ___________________________________________________________________________________
>>>
>>
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 17:25     ` Hans Hagen
@ 2020-11-26 19:56       ` Keith McKay
  0 siblings, 0 replies; 10+ messages in thread
From: Keith McKay @ 2020-11-26 19:56 UTC (permalink / raw)
  To: Hans Hagen, mailing list for ConTeXt users, Fabrice L

Thanks again Hans and Fabrice, for the time you have both taken with my 
question and thanks for the code snippet Hans. Just one last 
confirmation from the snippet. Hans uses the correction factor cf on the 
x and yparts of a[i]. I taking this as meaning that this has to be done 
because the x and yparts of a[i] are returned as postscript points units 
and not as centimeters as in the pair. I maybe didn't make this clear in 
my original query.

Thanks for your patience.

Keith McKay

On 26/11/2020 17:25, Hans Hagen wrote:
> On 11/26/2020 6:12 PM, Keith McKay wrote:
>> 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?
>
>
>     for squig = 1 step 1 until 15:
>         xcoord := (xpart a[i]/cf);
>         ycoord := (ypart a[i]/cf);
>         xcoord := xcoord randomized (xcoord/50);
>         ycoord := ycoord randomized (ycoord/50);
>         pp := pp  .. { curl 100 } (xcoord*cm, ycoord*cm);
>     endfor;
>
>
>> 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 
>>>> <mailto: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 
>>>> <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context 
>>>> <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage 
>>>>  :http://www.pragma-ade.nl 
>>>> <http://www.pragma-ade.nl/>/http://context.aanhet.net 
>>>> <http://context.aanhet.net/> archive 
>>>>  :https://bitbucket.org/phg/context-mirror/commits/ 
>>>> <https://bitbucket.org/phg/context-mirror/commits/> wiki 
>>>>     :http://contextgarden.net <http://contextgarden.net/> 
>>>> ___________________________________________________________________________________
>>>>
>>>
>>
>> ___________________________________________________________________________________ 
>>
>> 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
>> ___________________________________________________________________________________ 
>>
>>
>
>
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 17:20     ` Fabrice L
@ 2020-11-26 20:29       ` Keith McKay
  0 siblings, 0 replies; 10+ messages in thread
From: Keith McKay @ 2020-11-26 20:29 UTC (permalink / raw)
  To: Fabrice L; +Cc: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 5426 bytes --]

/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 
>> <mailto: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 
>>>> <mailto: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 
>>>> <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context 
>>>> <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage 
>>>>  :http://www.pragma-ade.nl 
>>>> <http://www.pragma-ade.nl/>/http://context.aanhet.net 
>>>> <http://context.aanhet.net/> archive 
>>>>  :https://bitbucket.org/phg/context-mirror/commits/ 
>>>> <https://bitbucket.org/phg/context-mirror/commits/> wiki 
>>>>     :http://contextgarden.net <http://contextgarden.net/> 
>>>> ___________________________________________________________________________________
>>>>
>

[-- Attachment #1.2: Type: text/html, Size: 14928 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-26 15:09 Units of xpart and ypart of a pair in MetaFun Keith McKay
  2020-11-26 15:19 ` Fabrice L
  2020-11-26 15:22 ` Hans Hagen
@ 2020-11-27  8:30 ` Taco Hoekwater
  2020-11-27  9:42   ` Keith McKay
  2 siblings, 1 reply; 10+ messages in thread
From: Taco Hoekwater @ 2020-11-27  8:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users



> On 26 Nov 2020, at 16:09, Keith McKay <mckaymeister@gmail.com> wrote:
> 
> 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

As explained by various people, Metapost does not have dimensions. All lengths are implicit Postscript big points
(72/inch). Variables like “cm” just add a multiplication factor to your expressions, at no point is a dimension stored inside Metapost. 

Your equation:

  a0 = (2cm,11cm)

first expands into 
  
  a0 = (2*28.34645,11*28.34645)

because “cm” is a variable with a value (Its definition in plain.mp is "cm = 28.34645”)

Then, the two expressions in the a0 equation are resolved before the assignment, so what you actually wrote at the statement level is

  a0 = (56.6929, 311.8096);

At no point is there a “cm”-sized dimension.

===

Perhaps another option would be for you to do all your work without units, e.g. 

  a0 = (2,11) % assume scaling will happen later

and then in the end do the drawing on a scaled path:

  draw (pp scaled cm) …

as that may be less confusing? If the precision is an issue, you could counter the loss of precision you could use implied millimeters instead of centimeters.

Best wishes,
Taco





___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Units of xpart and ypart of a pair in MetaFun
  2020-11-27  8:30 ` Taco Hoekwater
@ 2020-11-27  9:42   ` Keith McKay
  0 siblings, 0 replies; 10+ messages in thread
From: Keith McKay @ 2020-11-27  9:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2242 bytes --]

Thanks Taco!
I understand much better now. I think it's best to leave the units out
until the drawing stage as you suggest.
Thanks again
Keith McKay

On Fri, 27 Nov 2020, 08:30 Taco Hoekwater, <taco@elvenkind.com> wrote:

>
>
> > On 26 Nov 2020, at 16:09, Keith McKay <mckaymeister@gmail.com> wrote:
> >
> > 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
>
> As explained by various people, Metapost does not have dimensions. All
> lengths are implicit Postscript big points
> (72/inch). Variables like “cm” just add a multiplication factor to your
> expressions, at no point is a dimension stored inside Metapost.
>
> Your equation:
>
>   a0 = (2cm,11cm)
>
> first expands into
>
>   a0 = (2*28.34645,11*28.34645)
>
> because “cm” is a variable with a value (Its definition in plain.mp is
> "cm = 28.34645”)
>
> Then, the two expressions in the a0 equation are resolved before the
> assignment, so what you actually wrote at the statement level is
>
>   a0 = (56.6929, 311.8096);
>
> At no point is there a “cm”-sized dimension.
>
> ===
>
> Perhaps another option would be for you to do all your work without units,
> e.g.
>
>   a0 = (2,11) % assume scaling will happen later
>
> and then in the end do the drawing on a scaled path:
>
>   draw (pp scaled cm) …
>
> as that may be less confusing? If the precision is an issue, you could
> counter the loss of precision you could use implied millimeters instead of
> centimeters.
>
> Best wishes,
> Taco
>
>
>
>
>
>
> ___________________________________________________________________________________
> 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
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 3397 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-11-27  9:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 15:09 Units of xpart and ypart of a pair in MetaFun Keith McKay
2020-11-26 15:19 ` Fabrice L
2020-11-26 17:12   ` Keith McKay
2020-11-26 17:20     ` Fabrice L
2020-11-26 20:29       ` Keith McKay
2020-11-26 17:25     ` Hans Hagen
2020-11-26 19:56       ` Keith McKay
2020-11-26 15:22 ` Hans Hagen
2020-11-27  8:30 ` Taco Hoekwater
2020-11-27  9:42   ` Keith McKay

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).