ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Keith McKay <mckaymeister@gmail.com>
Subject: Re: Units of xpart and ypart of a pair in MetaFun
Date: Thu, 26 Nov 2020 16:22:15 +0100	[thread overview]
Message-ID: <a3bd2ed1-f61b-5561-7c76-21f3afa10b80@xs4all.nl> (raw)
In-Reply-To: <68dba0aa-8cc8-0a93-29bf-81afc7bf9079@gmail.com>

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
___________________________________________________________________________________

  parent reply	other threads:[~2020-11-26 15:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 15:09 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 [this message]
2020-11-27  8:30 ` Taco Hoekwater
2020-11-27  9:42   ` Keith McKay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3bd2ed1-f61b-5561-7c76-21f3afa10b80@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=mckaymeister@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).