# Metapost: get the radius of circle box

Followed is a small code. I want to get the radius of circle box. If I put the last sentence before the drawboxed command, the compilation failed due to unknown pair. It looks like only after drawing the circle box can I get the radius of circle box. But I want to draw the box somewhere relating to the radius B instead of the origin in the example. So,

1) Can I get the radius before drawing the box?

2) Or can I move the box after it was drawn? drawboxed (bulb) shifted p3 doesn't work.

outputtemplate := "%j-%c.eps";
prologues := 1 ;
input boxes
verbatimtex
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\begin{document}
etex

beginfig(1)
pair A;
circleit.bulb(btex foo etex);
bulb.c = origin;
drawboxed(bulb);
B = abs(bulb.e - bulb.w);
endfig;


No idea about 1), but you can manage 2) by saving the whole box as a picture (with the image command) and shifting this image where you want.

outputtemplate := "%j-%c.eps";
prologues := 1 ;
input boxes
verbatimtex
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\begin{document}
etex

beginfig(1)
circleit.bulb(btex foo etex);
%bulb.c = origin; % not needed, it's the default location
picture p; p = image(drawboxed(bulb));
B = abs(bulb.e - bulb.w);
draw p;
draw p shifted (2B, 0);
endfig;

end.


• The last edit is what I want. Learn to put it in picture. Thank you. – warem Oct 27 '17 at 11:21
• If you study boxes.mp carefully, you will see that you can also directly manipulate the contents and outline of a shape defined by boxit or circleit without saving them into another picture variable. pic bulb gives you the picture of the content, and bpath bulb gives you the surrounding path. You can then draw these shifted where ever you like. – Thruston Nov 1 '17 at 11:37
• @Thruston You 're right, and it's handy if you want to handle contents and outline separately. If you want to handle them simultaneously, which is the case here, it seems easier to me to store them both in the same picture variable. – Franck Pastor Nov 1 '17 at 18:23