MetaFun: Confusion with `function()` and `xyscaled`
Dear ConTeXt/MetaFun folks, looking at the example for grid and functions in the MetaFun manual [1] section 9.3 drawoptions(withpen pencircle scaled .25pt withcolor .5white) ; draw hlingrid(0, 20, .2, 20cm, 10cm) ; draw vloggrid(0, 10, .5, 10cm, 20cm) ; drawoptions(withpen pencircle scaled .50pt) ; draw hlingrid(0, 20, 1, 20cm, 10cm) ; draw vloggrid(0, 10, 1, 10cm, 20cm) ; fmt_pictures := false ; % use TeX as formatting engine textextoffset := ExHeight ; % a variable set by ConTeXt draw hlintext.lft(0, 20, 5, 20cm, "@3e") ; draw vlogtext.bot(0, 10, 9, 10cm, "@3e") ; draw function(1,"log(x)","x",1,10,1) xyscaled (10cm,2cm) withpen pencircle scaled 5mm withcolor transparent(1,.5,yellow) ; I am confused how the resulting function is scaled correctly. The resulting dimensions seem to be 10cm and 18 cm. So I guess the 2 cm mean to shift it up some how. Could someone please explain to me how `xyscaled` works in this case please. I though `xyscaled (αcm, ζcm)` would set the object/path to a width of α cm and a height of ζ cm. Thanks, Paul [1] http://www.pragma-ade.com/general/manuals/metafun-s.pdf
Am Freitag, den 21.10.2011, 01:14 +0200 schrieb Paul Menzel:
Dear ConTeXt/MetaFun folks,
looking at the example for grid and functions in the MetaFun manual [1] section 9.3
drawoptions(withpen pencircle scaled .25pt withcolor .5white) ; draw hlingrid(0, 20, .2, 20cm, 10cm) ; draw vloggrid(0, 10, .5, 10cm, 20cm) ; drawoptions(withpen pencircle scaled .50pt) ; draw hlingrid(0, 20, 1, 20cm, 10cm) ; draw vloggrid(0, 10, 1, 10cm, 20cm) ;
fmt_pictures := false ; % use TeX as formatting engine textextoffset := ExHeight ; % a variable set by ConTeXt draw hlintext.lft(0, 20, 5, 20cm, "@3e") ; draw vlogtext.bot(0, 10, 9, 10cm, "@3e") ;
draw function(1,"log(x)","x",1,10,1) xyscaled (10cm,2cm) withpen pencircle scaled 5mm withcolor transparent(1,.5,yellow) ;
I am confused how the resulting function is scaled correctly. The resulting dimensions seem to be 10cm and 18 cm. So I guess the 2 cm mean to shift it up some how.
Could someone please explain to me how `xyscaled` works in this case please. I though `xyscaled (αcm, ζcm)` would set the object/path to a width of α cm and a height of ζ cm.
Looking up the definition of the macro `xyscaled` it is indeed just a short version of `xscaled αcm yscaled ζcm`. $ more mp-tool.mp […] %D More robust: % let normalscaled = scaled ; % let normalxscaled = xscaled ; % let normalyscaled = yscaled ; % % def scaled expr s = normalscaled (s) enddef ; % def xscaled expr s = normalxscaled (s) enddef ; % def yscaled expr s = normalyscaled (s) enddef ; %D Shorter primarydef p xyscaled q = begingroup ; save qq ; pair qq ; qq = paired(q) ; ( p if xpart qq<>0 : xscaled (xpart qq) fi if ypart qq<>0 : yscaled (ypart qq) fi ) endgroup enddef ; […] I am still confused though what happens in the above example scaling the path of the function. Trying \starttext \startMPcode draw fullsquare xscaled 10cm yscaled 2cm; \stopMPcode \stoptext the resulting rectangle has the dimensions of 10 cm width and 2 cm height but the path of the function above does not. Thanks, Paul
Hi Paul, I agree, this is confusing on the first sight. But scaling is not meant as 'scaling to' a dimension. In fact is is just a simple multiplication. The reason why it seems to work this way with 'fullsquare' and such predefined paths is, that they have a 'neutral' size/scale (bounding box size of filled path is (1pt,1pt)). Multiplying such a path with (x,y) gives an object with size (1*x,1*y). In general: if the bounding box of an object has the size (a,b) and you scale it with (x,y), the resulting object has a size of (ax,by). That's all the magic. I must admit that this wasn't clear to me before you came up with your question. So thanks for that. :-) Best wishes, Peter Am 21.10.2011 13:38, schrieb Paul Menzel:
Am Freitag, den 21.10.2011, 01:14 +0200 schrieb Paul Menzel:
Dear ConTeXt/MetaFun folks,
looking at the example for grid and functions in the MetaFun manual [1] section 9.3
drawoptions(withpen pencircle scaled .25pt withcolor .5white) ; draw hlingrid(0, 20, .2, 20cm, 10cm) ; draw vloggrid(0, 10, .5, 10cm, 20cm) ; drawoptions(withpen pencircle scaled .50pt) ; draw hlingrid(0, 20, 1, 20cm, 10cm) ; draw vloggrid(0, 10, 1, 10cm, 20cm) ;
fmt_pictures := false ; % use TeX as formatting engine textextoffset := ExHeight ; % a variable set by ConTeXt draw hlintext.lft(0, 20, 5, 20cm, "@3e") ; draw vlogtext.bot(0, 10, 9, 10cm, "@3e") ;
draw function(1,"log(x)","x",1,10,1) xyscaled (10cm,2cm) withpen pencircle scaled 5mm withcolor transparent(1,.5,yellow) ;
I am confused how the resulting function is scaled correctly. The resulting dimensions seem to be 10cm and 18 cm. So I guess the 2 cm mean to shift it up some how.
Could someone please explain to me how `xyscaled` works in this case please. I though `xyscaled (αcm, ζcm)` would set the object/path to a width of α cm and a height of ζ cm.
Looking up the definition of the macro `xyscaled` it is indeed just a short version of `xscaled αcm yscaled ζcm`.
$ more mp-tool.mp […] %D More robust:
% let normalscaled = scaled ; % let normalxscaled = xscaled ; % let normalyscaled = yscaled ; % % def scaled expr s = normalscaled (s) enddef ; % def xscaled expr s = normalxscaled (s) enddef ; % def yscaled expr s = normalyscaled (s) enddef ;
%D Shorter
primarydef p xyscaled q = begingroup ; save qq ; pair qq ; qq = paired(q) ; ( p if xpart qq<>0 : xscaled (xpart qq) fi if ypart qq<>0 : yscaled (ypart qq) fi ) endgroup enddef ; […]
I am still confused though what happens in the above example scaling the path of the function.
Trying
\starttext \startMPcode draw fullsquare xscaled 10cm yscaled 2cm; \stopMPcode \stoptext
the resulting rectangle has the dimensions of 10 cm width and 2 cm height but the path of the function above does not.
Thanks,
Paul
[1] http://www.pragma-ade.com/general/manuals/metafun-s.pdf
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
Dear Peter, thank you for your answer. Am Freitag, den 21.10.2011, 17:02 +0200 schrieb Peter Rolf:
I agree, this is confusing on the first sight. But scaling is not meant as 'scaling to' a dimension. In fact is is just a simple multiplication. The reason why it seems to work this way with 'fullsquare' and such predefined paths is, that they have a 'neutral' size/scale (bounding box size of filled path is (1pt,1pt)).
So how can I find out what the dimension of the path of a function is? Not scaling it, it also looked pretty small, so I am guessing (1pt,1pt).
Multiplying such a path with (x,y) gives an object with size (1*x,1*y). In general: if the bounding box of an object has the size (a,b) and you scale it with (x,y), the resulting object has a size of (ax,by). That's all the magic.
but if you use numbers with a unit than it should not be multiplied but expanded to that value, should not it? Otherwise I am unsure how multiplication works with a unit.
I must admit that this wasn't clear to me before you came up with your question. So thanks for that. :-)
Thank you for your answer. As written above it is still not entirely clear to me. I hope you can remedy my last confusion. Thanks a lot, Paul
Am 21.10.2011 17:26, schrieb Paul Menzel:
Dear Peter,
thank you for your answer.
Am Freitag, den 21.10.2011, 17:02 +0200 schrieb Peter Rolf:
I agree, this is confusing on the first sight. But scaling is not meant as 'scaling to' a dimension. In fact is is just a simple multiplication. The reason why it seems to work this way with 'fullsquare' and such predefined paths is, that they have a 'neutral' size/scale (bounding box size of filled path is (1pt,1pt)).
So how can I find out what the dimension of the path of a function is? Not scaling it, it also looked pretty small, so I am guessing (1pt,1pt).
I guess in this case its size is (10,log(10)) + pen size when drawn.
Multiplying such a path with (x,y) gives an object with size (1*x,1*y). In general: if the bounding box of an object has the size (a,b) and you scale it with (x,y), the resulting object has a size of (ax,by). That's all the magic.
but if you use numbers with a unit than it should not be multiplied but expanded to that value, should not it? Otherwise I am unsure how multiplication works with a unit.
1pt is the base unit in MP (used if no dimension is given; probably stored as 65536sp (scaled point) units). Now if you use pure numerics for scale, such as 'xscaled 2', this is interpreted as '2pt' (or 2*65536sp). If you use any dimension, it is also converted into scaled points. All the same for MP. If I'm right this should all be the same (untested) xscaled 2 xscaled 2pt xscaled (2*65536sp) 1 = 1pt = 65536sp
I must admit that this wasn't clear to me before you came up with your question. So thanks for that. :-)
Thank you for your answer. As written above it is still not entirely clear to me. I hope you can remedy my last confusion.
Thanks a lot,
Paul
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
Am Freitag, den 21.10.2011, 18:08 +0200 schrieb Peter Rolf:
Am 21.10.2011 17:26, schrieb Paul Menzel:
Am Freitag, den 21.10.2011, 17:02 +0200 schrieb Peter Rolf:
I agree, this is confusing on the first sight. But scaling is not meant as 'scaling to' a dimension. In fact is is just a simple multiplication. The reason why it seems to work this way with 'fullsquare' and such predefined paths is, that they have a 'neutral' size/scale (bounding box size of filled path is (1pt,1pt)).
So how can I find out what the dimension of the path of a function is? Not scaling it, it also looked pretty small, so I am guessing (1pt,1pt).
I guess in this case its size is (10,log(10)) + pen size when drawn.
That was it kind of. Probably the most of my confusion resulting from the use of the inverse function. So all in all the width is 1 – the x-coordinates seem to be scaled to the width of 1 – and the height is 10, as ten is the highest value. Therefore the width has to be multiplied with 10cm to get it to 10cm and since the height it 10 already multiplying it with 2cm gets it to 20cm.
Multiplying such a path with (x,y) gives an object with size (1*x,1*y). In general: if the bounding box of an object has the size (a,b) and you scale it with (x,y), the resulting object has a size of (ax,by). That's all the magic.
but if you use numbers with a unit than it should not be multiplied but expanded to that value, should not it? Otherwise I am unsure how multiplication works with a unit.
1pt is the base unit in MP (used if no dimension is given; probably stored as 65536sp (scaled point) units).
In the manual I only found bp for »big point«, which equal PostScript points equaling 1/72 of an inch.
Now if you use pure numerics for scale, such as 'xscaled 2', this is interpreted as '2pt' (or 2*65536sp). If you use any dimension, it is also converted into scaled points. All the same for MP.
If I'm right this should all be the same (untested)
xscaled 2 xscaled 2pt
This gives the same result.
xscaled (2*65536sp)
I could not test the above because the numbers got too big and MetaPost complained.
1 = 1pt = 65536sp
[…] Thanks, Paul
Am 23.10.2011 16:12, schrieb Paul Menzel:
Am Freitag, den 21.10.2011, 18:08 +0200 schrieb Peter Rolf:
Am 21.10.2011 17:26, schrieb Paul Menzel:
Am Freitag, den 21.10.2011, 17:02 +0200 schrieb Peter Rolf:
I agree, this is confusing on the first sight. But scaling is not meant as 'scaling to' a dimension. In fact is is just a simple multiplication. The reason why it seems to work this way with 'fullsquare' and such predefined paths is, that they have a 'neutral' size/scale (bounding box size of filled path is (1pt,1pt)).
So how can I find out what the dimension of the path of a function is? Not scaling it, it also looked pretty small, so I am guessing (1pt,1pt).
I guess in this case its size is (10,log(10)) + pen size when drawn.
That was it kind of. Probably the most of my confusion resulting from the use of the inverse function.
So all in all the width is 1 – the x-coordinates seem to be scaled to the width of 1 – and the height is 10, as ten is the highest value. Therefore the width has to be multiplied with 10cm to get it to 10cm and since the height it 10 already multiplying it with 2cm gets it to 20cm.
I see. I must admit that I haven't looked deeper into function (never used it). If I want to test the bounding box of a graphic, I normally use a small debugging macro (last code line of nearly all of my graphics). It simply draws a small red frame at the bounding box borders. You can use the 'Measuring Tool' in Acrobat (also Reader?) or even better the 'Object Inspector' to get the exact size. minlinewidth:= .143pt; def wirepen= pencircle scaled minlinewidth enddef ; def drawbb = drawoptions() ; interim linejoin:= mitered; draw (llcorner currentpicture) shifted ( .5minlinewidth, .5minlinewidth) -- (lrcorner currentpicture) shifted (-.5minlinewidth, .5minlinewidth) -- (urcorner currentpicture) shifted (-.5minlinewidth,-.5minlinewidth) -- (ulcorner currentpicture) shifted ( .5minlinewidth,-.5minlinewidth) -- cycle withpen wirepen withcolor red; % draw boundingbox currentpicture withpen wirepen withcolor red ; % was not neutral! enddef ;
Multiplying such a path with (x,y) gives an object with size (1*x,1*y). In general: if the bounding box of an object has the size (a,b) and you scale it with (x,y), the resulting object has a size of (ax,by). That's all the magic.
but if you use numbers with a unit than it should not be multiplied but expanded to that value, should not it? Otherwise I am unsure how multiplication works with a unit.
1pt is the base unit in MP (used if no dimension is given; probably stored as 65536sp (scaled point) units).
In the manual I only found bp for »big point«, which equal PostScript points equaling 1/72 of an inch.
It can't be helped, I always mix this up. :-D It's 'bp' for MP and for Adobe products, and 'pt' for TeX. Ask me in a few weeks and I can't give the correct answer.
Now if you use pure numerics for scale, such as 'xscaled 2', this is interpreted as '2pt' (or 2*65536sp). If you use any dimension, it is also converted into scaled points. All the same for MP.
If I'm right this should all be the same (untested)
xscaled 2 xscaled 2pt
This gives the same result.
xscaled (2*65536sp)
I could not test the above because the numbers got too big and MetaPost complained.
My fault. In the meantime I have checked it and 'sp' is not a predefined constant in MP (couldn't find it in the manual). Also never used it in MP.
1 = 1pt = 65536sp
[…]
Thanks,
Paul
___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
On 23-10-2011 17:17, Peter Rolf wrote:
If I want to test the bounding box of a graphic, I normally use a small debugging macro (last code line of nearly all of my graphics). It simply draws a small red frame at the bounding box borders. You can use the 'Measuring Tool' in Acrobat (also Reader?) or even better the 'Object Inspector' to get the exact size.
minlinewidth:= .143pt;
def wirepen= pencircle scaled minlinewidth enddef ;
def drawbb = drawoptions() ; interim linejoin:= mitered; draw (llcorner currentpicture) shifted ( .5minlinewidth, .5minlinewidth) -- (lrcorner currentpicture) shifted (-.5minlinewidth, .5minlinewidth) -- (urcorner currentpicture) shifted (-.5minlinewidth,-.5minlinewidth) -- (ulcorner currentpicture) shifted ( .5minlinewidth,-.5minlinewidth ) -- cycle withpen wirepen withcolor red; % draw boundingbox currentpicture withpen wirepen withcolor red ; % was not neutral! enddef ;
draw boundingbox currentpicture enlarged -.5minlinewidth withpen wirepen withcolor red ;
My fault. In the meantime I have checked it and 'sp' is not a predefined constant in MP (couldn't find it in the manual). Also never used it in MP.
1 = 1pt = 65536sp
sp's would overflow anyway Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Could someone please explain to me how `xyscaled` works in this case please. I though `xyscaled (αcm, ζcm)` would set the object/path to a width of α cm and a height of ζ cm.
IIRC, xysized does that. (I am usually confused between ..sized and ..scaled, but one of them scales to the given dimensions). Aditya
On 21-10-2011 22:53, Aditya Mahajan wrote:
Could someone please explain to me how `xyscaled` works in this case please. I though `xyscaled (αcm, ζcm)` would set the object/path to a width of α cm and a height of ζ cm.
IIRC, xysized does that. (I am usually confused between ..sized and ..scaled, but one of them scales to the given dimensions).
scaled is just multiplication so x scaled 1cm is x * 1 * cm which can be pretty large Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Dear MetaFun folks, Am Freitag, den 21.10.2011, 01:14 +0200 schrieb Paul Menzel:
looking at the example for grid and functions in the MetaFun manual [1] section 9.3
drawoptions(withpen pencircle scaled .25pt withcolor .5white) ; draw hlingrid(0, 20, .2, 20cm, 10cm) ; draw vloggrid(0, 10, .5, 10cm, 20cm) ; drawoptions(withpen pencircle scaled .50pt) ; draw hlingrid(0, 20, 1, 20cm, 10cm) ; draw vloggrid(0, 10, 1, 10cm, 20cm) ;
fmt_pictures := false ; % use TeX as formatting engine textextoffset := ExHeight ; % a variable set by ConTeXt draw hlintext.lft(0, 20, 5, 20cm, "@3e") ; draw vlogtext.bot(0, 10, 9, 10cm, "@3e") ;
draw function(1,"log(x)","x",1,10,1) xyscaled (10cm,2cm) withpen pencircle scaled 5mm withcolor transparent(1,.5,yellow) ;
the labeling of the vertical axis (y-coordinate) is not incorrect. The maximum value is 10 and therefore it should probably be corrected as follows. - draw hlingrid(0, 20, 1, 20cm, 10cm) ; + draw hlingrid(0, 20, 2, 20cm, 10cm) ; - draw hlintext.lft(0, 20, 5, 20cm, "@3e") ; + draw hlintext.lft(0, 10, 5, 20cm, "@3e") ; Furthermore on the bottom labels seem to be incorrect in the figure, it goes from 1 to 0, but this seems to be a bug in the used ConTeXt version, since I do not have that problem when compiling(?) that example locally. Please find the corrected example attached. […] Thanks and I hope I did not mess up, Paul
participants (4)
-
Aditya Mahajan
-
Hans Hagen
-
Paul Menzel
-
Peter Rolf