22
$\begingroup$

Struggling often with Trigonometry I would like to have some code to generate this Unit Circle Trigonometry. Would be of great help when I need to transform some data :

enter image description here

$\endgroup$
2
  • 14
    $\begingroup$ Is your question: how to create this figure in Mathematica? Can you please describe what you tried so far and where you got stuck? You've been using Mathematica for a while, so to avoid the repliers spend too much time on writing up what you can already do yourself, please focus on the detail which you really couldn't solve. $\endgroup$
    – Szabolcs
    Commented Feb 29, 2012 at 17:11
  • $\begingroup$ Is your question just how to generate this exact figure in Mathematica? Why would you need to, if you already have the figure you included in the question? $\endgroup$
    – tparker
    Commented Jan 28, 2017 at 7:26

3 Answers 3

36
$\begingroup$

There are a couple tricky points here. Here's a start, which I imagine you can finish.

markings[t_] := Module[{o={0,0},p={Cos[t],Sin[t]}, 
  t2=Together[t],tFormat, rot},
  tFormat = If[Denominator[t2]=!=1, 
    Row[{Numerator[t2],"/",Denominator[t2]}]];
  rot = If[TrueQ[Pi/2<Mod[t,2Pi]<3Pi/2],t+Pi,t];
    {{Opacity[0.3],Line[{o,p}]},
     Rotate[Inset[Style[
       Row[{t(180/Pi)Degree, " = ",tFormat}],
     FontSize->18], p/2],rot], 
     Text[{Cos[t],Sin[t]},p,-1.3p]}
];
Graphics[{
  Circle[{0,0},1],
  Table[markings[t],{t,{Pi/6,Pi/4,2Pi/3}}]
}]

enter image description here

In addition to finishing it, logical enhancements would include: Making the Circle thicker, adjusting the size and/or format of the point labels, adding Points on the boundary, and/or making it dynamic.

Have fun!

$\endgroup$
3
  • $\begingroup$ Ooh! Making it dynamic would be interesting. (and, you already got my +1) $\endgroup$
    – rcollyer
    Commented Feb 29, 2012 at 17:32
  • $\begingroup$ @Mark, Thank you very much ! $\endgroup$
    – 500
    Commented Feb 29, 2012 at 17:43
  • $\begingroup$ doesn't tFormat need to include how the thing should look if the condition is False, i.e., unaltered t2? Or was that the thing for 500 to work out on his own? $\endgroup$
    – Verbeia
    Commented Mar 1, 2012 at 6:16
42
$\begingroup$

Here's a dynamic version (sorry, I couldn't resist).

Manipulate[
 DynamicModule[{alist, pt, pc},
  pt[a_] := {Cos[a], Sin[a]};
  alist = 
   Union[Range[0, 2 Pi - Pi/6, Pi/6], Range[0, 2 Pi - Pi/4, Pi/4]];
  a = Nearest[alist, Mod[ArcTan @@ p, 2 Pi, 0]][[1]];
  pc = pt[a];

  Graphics[{
    Circle[],
    {LightGray, Line[{{0, 0}, pt[#]}] & /@ alist},
    {PointSize[Medium], Blue, Point[pt /@ alist]},
    {AbsoluteThickness[2], Line[{{0, 0}, pc}]},
    {PointSize[Large], Red, Point[pc]},
    Text[pc, pc, -2 pc],
    Text[Framed[Row[{a/Pi/2 360, "\[Degree] = ", a}], 
      Background -> White, FrameStyle -> None], pc/2, {0, 0}, 
     pt[Mod[a, Pi, -Pi/2]]]},
   PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}]],
 {{p, {1, 0}}, Locator, Appearance -> None},
 {{a, 0}, None}]

Mathematica graphics

$\endgroup$
7
  • 1
    $\begingroup$ If only I would have thought of that! :) $\endgroup$ Commented Feb 29, 2012 at 19:01
  • $\begingroup$ @Heike, Thank You so much. This is so cool ! $\endgroup$
    – 500
    Commented Feb 29, 2012 at 19:11
  • 1
    $\begingroup$ @Heike Very nice. Perhaps we should all upvote a question that generates such pleasing answers... Funny that this Q still has 0 votes at the moment. $\endgroup$
    – cormullion
    Commented Feb 29, 2012 at 20:10
  • $\begingroup$ +1 for aesthetics (white background on the text, etc...) $\endgroup$ Commented Feb 29, 2012 at 20:11
  • $\begingroup$ @cormullion The question actually currently has two Upvotes and two Downvotes. $\endgroup$ Commented Feb 29, 2012 at 20:14
2
$\begingroup$
Clear["Global`*"]

cpts[r_Real, a_List] := {r Cos[#], r Sin[#]} & /@ a

rmain = 1;
anglesRadians = # + {0, π/6, π/4, π/3} & /@ 
    Range[0, 3 π/2, π/2] // Flatten;
(*anglesRadians=Range[0,2π,π/12];*) 
anglesDegrees = anglesRadians (180/π);
coords = (StringForm["(``,``)", Cos[#], Sin[#]] & /@ anglesRadians);
tancoords = (StringForm["``", Tan[#]] & /@ anglesRadians) /. 
   ComplexInfinity -> ∞;
labels = Rotate[#, 
       If[π/2 < Last@# < 3 π/2, Last@# + π, Last@#]] & /@ 
     TraditionalForm[#] & /@ (StringForm["``° = `` rad", 
       First@#, Last@#] & /@ 
     Transpose[{anglesDegrees, anglesRadians}] );

ListPlot[Evaluate@MapThread[Callout[#1, Style[#2, 12]
     (*,CalloutMarker\[Rule]"CirclePoint"*)
     (*,CalloutStyle\[Rule]Blue*)
     , LeaderSize -> {12, ArcTan @@ #1, 4}] &
   , {cpts[1.0 rmain, anglesRadians], coords}
   ]
 , PlotStyle -> {AbsolutePointSize[6], Red}
 , PlotRange -> {{ -rmain, rmain}, {- rmain, rmain}}
 (* PlotRange for the tangent ring *)
 (*{{ -1.4rmain,1.4rmain},{ -1.4rmain,1.4rmain}}*) 
 , AspectRatio -> Automatic
 , Axes -> False
 , ImageSize -> 600
 , PlotRangePadding -> {Scaled[0.12], Scaled[0.12]}
 , Epilog -> {
   {Thin, Dashed, Line[{{0, 0}, #}] & /@
     cpts[0.4 rmain, anglesRadians]}
   , {Thin, Dashed, MapThread[Line[{#1, #2}] &
     , {cpts[0.8 rmain, anglesRadians]
      , cpts[1.0 rmain, anglesRadians]}
     ]}
   , {MapThread[Text[Style[#1, 12, Blue], #2] &
     , {labels, cpts[0.6 rmain, anglesRadians]}] }
   
   (*--------------------------------*)
   (* enable only if an annulus with Tan() values  is required
   , expect to do some tinkering to fonts/plotrange *)
   
   (*,{FaceForm[{Opacity[0.2,Nest[Lighter,Brown,1]]}]
   ,EdgeForm[{Dashed,Black}]
   ,Annulus[{0,0},{1.5rmain,1.75rmain}]}
   ,{ MapThread[Text[Style[#1,11,Black],#2]&
   ,{tancoords,cpts[1.62 rmain,anglesRadians]}]}*)
   
   (*--------------------------------*)
   }
 , Prolog -> {
   {FaceForm[Nest[Lighter, Cyan, 3]], EdgeForm[{Dashed, Black}], 
    Disk[{0, 0}, rmain]}
   }
 ]

enter image description here


Usage notes

  1. rmain is the radius of the main circle. If the user chooses a value other than 1, it would still work, but then the user must keep the Axes and Frame turned off or else the labels would not make much sense.

  2. The function cpts generates points around the main circle for the list of angles. This is used many times while plotting various primitives.

  3. I wanted to use Callout, so resorted to ListPlot.

  4. An Annulus that displays Tan[θ] values can be enabled by un-commenting the indicated code lines.

$\endgroup$
1
  • $\begingroup$ very nice! ... (don't mind the ... I just had to PadRight :-) ) $\endgroup$
    – bmf
    Commented Feb 3, 2023 at 9:31

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