Draw and Quantity

I'd like to use Quantity in my graphics, but I can't figure out how to do it even for a very simple Circle.

(* draw a circle with center in (3,2) and radius 5 *)

Graphics[Circle[{3, 2}, 5]]

(* why it won't work with Quantity? *)

x = Quantity[3, "Meters"];
y = Quantity[2, "Meters"];
r = Quantity[5, "Meters"];

Graphics[Circle[{x, y}, r]]


Errors are:

1) Coordinate {Quantity[3, "Meters"], Quantity[2, "Meters"]} should be a pair of numbers, or a Scaled or Offset form.

2) Radius Quantity[5, "Meters"] should be a positive number or pair of positive numbers, or a Scaled or Offset form.

Could you help me please? Thank you, Luca-

Quantity itself can't be used as its own value. You need to extract the numerical value itself, like this

x = Quantity[3, "Meters"];
y = Quantity[2, "Meters"];
r = Quantity[5, "Meters"];

Graphics[Circle[{QuantityMagnitude[x, "Meters"],
QuantityMagnitude[y, "Meters"]},
QuantityMagnitude[r, "Meters"]]
]


You can think of Quantity as an "object" with one of its properties is its numerical value (with no units) that you can obtain from the object with the QuantityMagnitude call

• Thank you for your help. I'm sorry I haven't enough reputation points to vote up your answer. Is Magnitude a property of Quantity objects? Is there a way to inspect properties of a give object? For instance, if I have a Point[] object, is there a way to inspect what properties I can query? Thank you again, Luca- – Luca Apr 4 '15 at 9:27
• @Luca M is not OO Language, but uses functions. So to find what "methods" can be used on "object" Point you look at help and see all the settings and commands that can be applied to it. Also if you do ??Point you'll see the options Options[Point]={VertexColors->None,VertexNormals->None} There are also modifiers you can apply to point, such as PointSize and change its color etc... – Nasser Apr 4 '15 at 9:44
• ok, thank you. My path to learn Mathematica seems "not so short"! – Luca Apr 4 '15 at 9:54
• I think it would be better to extract numbers for an explicit unit, otherwise mixed units will give unexpected results. In v10 that would be something like QuantityMagnitude[x,"Meters"], for v9 you'd need an extra call to UnitConvert... – Albert Retey Apr 4 '15 at 9:57
• @AlbertRetey good point. Since the units are all the same in this example, this will not make a difference, but will update for illustration and to remind one of this. thanks. – Nasser Apr 4 '15 at 10:05

Another explanation is, that Circle is a graphical primitive, not a pure mathematical function in itself, and therefore does not accept units.

When one uses a mathematical object, units can be used throughout.

Example: The circle centered on $(xc,yc)$ with radius $r$ $$(x-xc)^2+(y-yc)^2=r^2$$ can be drawn with units in Mathematica using ContourPlot:

{xc,yc,r}=Quantity[#, "Meters"]&/@{3,2,5};

ContourPlot[(x-xc)^2 + (y-yc)^2 == r^2,
{x, Quantity[-3, "Meters"], Quantity[8, "Meters"]},
{y, Quantity[-3, "Meters"], Quantity[8, "Meters"]},
PlotRange->{{-10,10}, {-10,10}}]


Mathematica automatically takes care of converting units, so you can mix e.g. "Feet" and "Millimeters" etc.

• thank you for your further explanation! Does the same problem (a graphics primitive that doesn't accept units) apply also to Arrows[], Point[] and so on? – Luca Apr 4 '15 at 9:32
• @Luca: Yes, I think so. Just give it a try. – Jinxed Apr 4 '15 at 9:35
• Honestly I don't think that it is worth to spend too much effort to understand/explain something like this. It simply reflects what WRI's programmers did implement, I think it would be possible to have graphics primitives accept quantities as well. If they don't but ContourPlot does then this IMHO looks somewhat inconsistent, but probably for good reasons (e.g. performance, consistency, compatibility...) and most probably has to just be accepted "as is"... – Albert Retey Apr 4 '15 at 9:52