1
$\begingroup$

So I am new to Mathematica still learning basic codes.. However I need help to become quicker in my research. Can anyone help me with the simplicit code to plot 2 concentric circles and a polygon of sides n (that I can manipulate) inscribed in one circle and circumscribed about the other.

$\endgroup$
3
  • $\begingroup$ can you post a sample image - a drawing or from a website. $\endgroup$
    – Sumit
    Apr 24, 2016 at 12:08
  • $\begingroup$ Are your polygons always regular (as kirma assumes in his answer)? Not all polygons are circumscribable or inscribable. $\endgroup$ Apr 24, 2016 at 12:27
  • $\begingroup$ So the polygon does not have to always be regular, as long as I have the circumscribed and inscribed, and my circles fixed $\endgroup$
    – Sarah
    May 18, 2016 at 23:33

2 Answers 2

2
$\begingroup$

A simpler and minimal version

Manipulate[
 Graphics[{Red, Circle[{0, 0}, Cos[Pi/n]], Blue, Circle[{0, 0}, 1], 
 Green, Line[{Cos[2 Pi #/n], Sin[2 Pi #/n]} & /@ Range[0, n]]}],
 {n, 3, 30, 1}]

enter image description here

Inner circle will adjust itself according to the polygon.

For fixed inner circle

Manipulate[
 Graphics[{Red, Circle[{0, 0}, 1], Blue, Circle[{0, 0}, 1/Cos[Pi/n]], 
 Green, Line[
 1/Cos[Pi/n] {Cos[2 Pi #/n], Sin[2 Pi #/n]} & /@ Range[0, n]]}, 
 PlotRange -> 2 {{-1, 1}, {-1, 1}}], {n, 3, 30, 1}]

If you don't use PlotRange, you would not be able to see the difference.

$\endgroup$
10
  • $\begingroup$ Alternatively: Manipulate[Graphics[{Blue, Circle[], Red, Circle[{0, 0}, Cos[π/n]], Directive[EdgeForm[Green], FaceForm[]], RegularPolygon[n]}], {n, 3, 30, 1}] $\endgroup$ Apr 24, 2016 at 13:08
  • $\begingroup$ I am still with M9, @J.M. $\endgroup$
    – Sumit
    Apr 24, 2016 at 13:18
  • $\begingroup$ That's fine, I left it just for people who can try it out on later versions. $\endgroup$ Apr 24, 2016 at 13:20
  • $\begingroup$ If I want the polygon to stay circumscribed about the circle however with the circle inside to stay fixed,, so as n increases the circle inside is fixed but the polygon is still circumscribed about it. $\endgroup$
    – Sarah
    May 16, 2016 at 11:10
  • $\begingroup$ Can you help me with that? $\endgroup$
    – Sarah
    May 16, 2016 at 11:10
6
$\begingroup$

There are numerous ways to do this in Mathematica, and it's hard to say which would be most useful for learning. Here's one; a unit circle is drawn, then a polygon with no filling and black edge on basis of CirclePoints which generates points of a regular polygon lying on the unit circle. Finally, mean of two first points is taken, and distance to the origin is used as the radius of the incircle. Manipulate is then used to control the value of n.

Manipulate[
 With[{points = CirclePoints[n]}, 
  Graphics[{Circle[], FaceForm[None], EdgeForm[Black], Polygon[points], 
    Circle[{0, 0}, Norm[Mean[Take[points, 2]]]]}]], {n, 3, 10, 1}]

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Here is a one-line derivation of the formula for the inradius of a regular $n$-gon, based on kirma's observation: PowerExpand[Simplify[ComplexExpand[Abs[(1 + E^(2 π I/n))/2]]]]. $\endgroup$ Apr 24, 2016 at 13:12
  • $\begingroup$ @J.M. It was a strange experiment of the "avoid explicit trigonometry" sorts. :) $\endgroup$
    – kirma
    Apr 24, 2016 at 13:53
  • $\begingroup$ Why all the anathema? ;) :P $\endgroup$ Apr 24, 2016 at 14:03
  • $\begingroup$ @J.M. I guess I wanted to write the solution starting from CirclePoints, and it didn't turn out too awkward to do so. The first sentence in my answer expresses the Weltschmerz involved in expressing the solution only in this manner. :) $\endgroup$
    – kirma
    Apr 24, 2016 at 14:13

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.