Is it possible to draw a hollow circle using polygon?

Is it possible to draw a hollow circle using polygon?



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?





$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 '18 at 13:04



Annulus


FilledCurve





$begingroup$
But, with the command polygon no. right? something like playing with the points that you input to Polygon?
$endgroup$
– Msen Rezaee
Sep 18 '18 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 '18 at 19:02



FaceForm


EdgeForm


Polygon


FilledCurve




3 Answers
3



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


Polygon


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.


EdgeForm





$begingroup$
thanks a lot for the answer
$endgroup$
– Msen Rezaee
Sep 18 '18 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 '18 at 14:03





$begingroup$
@Kuba I expect to see red everywhere except on the thin surface of my circle
$endgroup$
– Msen Rezaee
Sep 18 '18 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 '18 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$
– Msen Rezaee
Sep 18 '18 at 14:18



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:


Annulus


Graphics[
FaceForm,
EdgeForm[Black],
Annulus
]



Mathematica graphics



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:


FilledCurve


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



enter image description here



Thanks for contributing an answer to Mathematica Stack Exchange!



But avoid



Use MathJax to format equations. MathJax reference.



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế