2
$\begingroup$

The question is simple. I have the following commands

r = 0.24;
R = 0.25;    

unitcircle = 
      Table[{Sin[\[Theta]], Cos[\[Theta]]}, {\[Theta], 2 \[Pi], 0, -\[Pi]/
         40}] // N;
    incircle = r*unitcircle;
    outcircle = R*unitcircle;

which define the outer points and inner points of a hollow circle. Is it possible to draw such a hollow circle using the polygon command?

$\endgroup$
3
  • 3
    $\begingroup$ Kind of yes, but should you? No. See Annulus and if it should be a polygon take a look at FilledCurve. $\endgroup$
    – Kuba
    Sep 18, 2018 at 13:04
  • $\begingroup$ But, with the command polygon no. right? something like playing with the points that you input to Polygon? $\endgroup$
    – KratosMath
    Sep 18, 2018 at 13:06
  • $\begingroup$ If you want to have a differing FaceForm and EdgeForm and no defects, and also everything on the background to appear in an honest fashion, plain Polygon is not enough. FilledCurve is the way to go. $\endgroup$
    – kirma
    Sep 18, 2018 at 19:02

3 Answers 3

5
$\begingroup$

Polygon is always filled (it can be filled with white). Use Circle for a "hollow" circle.

r = 0.24; R = 0.25;

Graphics[Circle[{0, 0}, #] & /@ {r, R}]

enter image description here

Graphics[{EdgeForm[Black], White, Polygon[CirclePoints[#, 50]] & /@ {R, r}}]

enter image description here

Note that since the polygons are filled, the smaller circle must be drawn on top (last) to be seen.

EDIT: For a red background, either

Graphics[{White, Annulus[{0, 0}, {r, R}]}, Background -> Red]

enter image description here

Or,

Graphics[{White, Polygon[CirclePoints[R, 50]], Red, 
  Polygon[CirclePoints[r, 50]]}, Background -> Red]

enter image description here

You could also use EdgeForm to make the borders more distinct.

$\endgroup$
6
  • $\begingroup$ thanks a lot for the answer $\endgroup$
    – KratosMath
    Sep 18, 2018 at 13:16
  • $\begingroup$ @MsenRezaee the question is, what do you expect to see if there is e.g. a red background. $\endgroup$
    – Kuba
    Sep 18, 2018 at 14:03
  • $\begingroup$ @Kuba I expect to see red everywhere except on the thin surface of my circle $\endgroup$
    – KratosMath
    Sep 18, 2018 at 14:07
  • $\begingroup$ @MsenRezaee that is unclear for me. What should be between those black edges, and what should be inside the inner edge. $\endgroup$
    – Kuba
    Sep 18, 2018 at 14:15
  • $\begingroup$ @Kuba in the case of a red background, I expect to see red outside the outer edge and inside the inner edge. But not on the thin surface of the circle. $\endgroup$
    – KratosMath
    Sep 18, 2018 at 14:18
3
$\begingroup$

Here's one way:

outer = CirclePoints[2, 100];
AppendTo[outer, First[outer]];
inner = CirclePoints[1, 100];
AppendTo[inner, First[inner]];
Graphics@Polygon[Join[inner, Reverse[outer]]]

Mathematica graphics

A hollow annulus is trickier:

Graphics[{
  FaceForm[],
  EdgeForm[Black],
  Polygon[Join[inner, Reverse[outer]]],
  White, Thickness[0.01],
  Line[{1.03 First[inner], 0.985 First[outer]}]
  }]

Mathematica graphics

I couldn't get away with just a polygon for this one, I had to cover up the line from where the inner circle connects to the outer. Had I done this with a polygon it would still be two polygons and not one. We can also draw another polygon like the first one here above in white to make the first one appear hollow.

As an aside, I see that Annulus has been mentioned but no one has shown how to make it hollow as far as I can tell:

Graphics[{
  FaceForm[],
  EdgeForm[Black],
  Annulus[]
  }]

Mathematica graphics

$\endgroup$
3
$\begingroup$

FilledCurve can be used to achieve polygons with holes defined using lines (but also filled Bezier curves and B-splines can be used). Here one is formed by two very circle-like polygons). Red line on background for illustrative purposes:

Graphics[
 {Thick, Red, Line[.25 {{-1, -1}, {1, 1}}], FaceForm@White, EdgeForm@Black, 
  FilledCurve[{Line@CirclePoints[#, 100]} & /@ {.24, .25}]}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.