Message Boards Message Boards

1
|
10265 Views
|
2 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Heading Compass Gauge in Mathematica 9

Posted 13 years ago
I'm writing a dynamic weather dashboard to display conditions during hurricane Sandy on the east coast. I'd like to use an AngularGauge to display WeatherData "WindDirection", but I want it to look like a compass. Any tips on how to change the labels to display the four cardinal directions?
POSTED BY: Jesse Friedman
2 Replies
It is very easy to make your own compass completely from scratch. I show you two different ways. First is based on an existing image of a compass dial that you can find online. Let’s grab one from Wikipedia:

dialImage =  ColorNegate@Import["http://upload.wikimedia.org/wikipedia/commons/e/e9/Compass_rose.png"]



Now let’s define a function that draws compass needle in a given direction:

needle[x_,p_]:=Graphics[{
  {Red,Opacity[.85],Rotate[Polygon[{{-.1,0},{.1,0},{0,1}}],-x,{0,0}]},
  {Blue,Opacity[.85],Rotate[Polygon[{{-.1,0},{.1,0},{0,-1}}],-x,{0,0}]}},PlotRange->p]

And finally we can compose both to make an interactive compass:

Manipulate[
   Overlay[{dialImage, Dynamic@needle[x, 1.2]},   Alignment -> Center],
   {{x, Pi/12, "direction"}, -2 Pi, 2 Pi},  FrameMargins -> 0, ContentSize -> {340, 345}]



If you want to customize your dial, you can design your own:

 dialGraphics=Graphics[{
   {Brown,Opacity[1],Thickness[.005],Circle[{0,0},1.04]},
   {Orange,Opacity[.2],Thickness[.07],Circle[{0,0},.96]},
   Table[Rotate[Text[Style[k Degree,15],{0,.96}],-k Degree,{0,0}],{k,0,330,30}],
   Table[Rotate[Line[{{0,.85},{0,.9}}],-k Degree,{0,0}],{k,0,350,10}],
   Table[Rotate[Line[{{0,.89},{0,.9}}],-k Degree,{0,0}],{k,0,399,1}],
   Text[Style["N",25,FontFamily->"algerian"],{0,.7}],
   Rotate[Text[Style["S",25,FontFamily->"Algerian"],{0,.7}],Pi,{0,0}],
   Rotate[Text[Style["E",25,FontFamily->"Algerian"],{0,.7}],-Pi/2,{0,0}],
  Rotate[Text[Style["W",25,FontFamily->"Algerian"],{0,.7}],Pi/2,{0,0}],
  Rotate[Text[Style["NE",25,FontFamily->"Algerian"],{0,.7}],-Pi/4,{0,0}],
  Rotate[Text[Style["NW",25,FontFamily->"Algerian"],{0,.7}],Pi/4,{0,0}],
  Rotate[Text[Style["SW",25,FontFamily->"Algerian"],{0,.7}],3Pi/4,{0,0}],
  Rotate[Text[Style["SE",25,FontFamily->"Algerian"],{0,.7}],-3Pi/4,{0,0}]
},PlotRange->1.1]

You combine it with our needle in the same way as before
Manipulate[Overlay[{dialGraphics,Dynamic@needle[x,1.25]},Alignment->Center],{{x,Pi/12,"direction"},-2Pi,2Pi}]

POSTED BY: Vitaliy Kaurov
One basic approach is as follows:

AngularGauge[WeatherData["KCMI", "WindDirection"], {0, 360},
   ScaleOrigin -> {Pi/2, -3 Pi/2}, (* 0/360 at top, increasing clock-wise *)
   ScaleDivisions -> None, (* hide the default ticks *)
   GaugeFrameSize -> 0.2, (* thicken up the frame, to hold our own labels *)
   (* custom labels, in the correct positions *)
   GaugeLabels -> {Placed["N", {0, {0.5, 0}}], Placed["E", {90, {0, 0.5}}],
                   Placed["S", {180, {0.5, 1}}], Placed["W", {270, {1, 0.5}}]}
   ]

You'll probably also need TickStyle->Opacity[0] in your build, although that shouldn't be necessary in the final V9.
POSTED BY: Brett Champion
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract