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.
-
$\begingroup$ can you post a sample image - a drawing or from a website. $\endgroup$– SumitApr 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$– J. M.'s persistent exhaustion ♦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$– SarahMay 18, 2016 at 23:33
2 Answers
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}]
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.
-
$\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$ 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$– SarahMay 16, 2016 at 11:10
-
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}]
-
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$– kirmaApr 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$– kirmaApr 24, 2016 at 14:13