3
$\begingroup$

i'm going to plot some angles in Trigonometric circle by using Graphic command how can i use filling axes by different colors in this program or color between the angles?

angles[t_] := Module[{o = {0, 0}, p = {Cos[t], Sin[t]}, rot},
   rot = If[TrueQ[Pi/2 < Mod[t, 2 Pi] < 3 Pi/2], t + Pi, t];
   {{Opacity[0.3], Line[{o, p}]}, 
    Rotate[Inset[Style[Row[{t}], FontSize -> 18], p/2], rot]}];
Graphics[{Red, Circle[{0, 0}, 1], Blue, 
  Table[angles[
    t  Degree ], {t  , {52, 0, 220, 180, 132, 282, 90, 320}}]}, 
 Axes -> True, Ticks -> None]

Thanks.

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Aug 19 '15 at 19:37
5
$\begingroup$

Filling is not an option for Graphics, One approach is to use a PieChart as a background.

angles[t_] := 
  Module[{o = {0, 0}, p = {Cos[t], Sin[t]}, rot}, 
   rot = If[TrueQ[Pi/2 < Mod[t, 2 Pi] < 3 Pi/2], t + Pi, t];
   {{Opacity[0.3], Line[{o, p}]}, 
    Rotate[Inset[Style[Row[{t}], FontSize -> 18], p/2], rot]}];

ang = {52, 0, 220, 180, 132, 282, 90, 320} Degree // Sort;

ang = Append[ang, First[ang] + 360 Degree];

Show[
 PieChart[Differences@ang/(360 Degree), 
  SectorOrigin -> {0, "Counterclockwise"}, 
  ColorFunction -> ({Opacity[0.65], 
      ColorData["TemperatureMap"][RandomReal[]]} &),
  ColorFunctionScaling -> True],
 Graphics[{Red, Circle[{0, 0}, 1], Blue, 
   Table[angles[t Degree], {t, {52, 0, 220, 180, 132, 282, 90, 320}}]}]]

enter image description here

$\endgroup$
4
$\begingroup$

I think using circular sectors generated with Disk may be easier:

SeedRandom[3]

Clear[sector, angles]
sector[color_, angle_List] := {color, Disk[{0, 0}, .995, {angle[[1]], angle[[2]]} Degree]}

angles[t_] := Module[
  {o = {0, 0}, p = {Cos[t], Sin[t]}, rot},
  rot = If[TrueQ[Pi/2 < Mod[t, 2 Pi] < 3 Pi/2], t + Pi, t];
  {{Opacity[0.3], Line[{o, p}]}, Rotate[Inset[Style[Row[{t}], FontSize -> 18], p/2], rot]}
  ]

listofangles = Sort@{52, 0, 220, 180, 132, 282, 90, 320};
listofcolors = RandomReal[1, Length[listofangles]];


Graphics[{
  (* The outer circle *)
  Thick, Red, Circle[],

  (* Circular sectors generated from listofangles, colored by listofcolors*)
  MapThread[
   sector[Hue[#1], #2] &,
   {listofcolors, Append[Partition[listofangles, 2, 1], {listofangles[[-1]], 360}]}
   ],

  (* Angles values and separating lines, from OP's code *)
  {Darker@Blue, Table[angles[t Degree], {t, listofangles}]}
}]

Colored disk


I used a list of randomly chosen colors here. However, you can specify colors of your choosing by assigning a list of color names to listofcolors. You need to specify as many colors as you have angles in listofangles.

$\endgroup$

Your Answer

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

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