Re: Polar Plot of Data
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Polar Plot of Data
- From: villegas
- Date: Wed, 14 Apr 93 04:11:48 CDT
A function that does the following transformation on ordered pairs: (r, theta) |===> ( r cos(theta), r sin(theta) ) can be expressed in Mathematica by the following construct: {#1 Cos[#2], #1 Sin[#2]} & This represents a function that multiplies its first argument (understood to be the modulus r) by the cosine and sine of the second argument (understood to be the angle theta), and returns the pair of results (understood to be x and y, respectively). If we have a list of pairs polarpairs = { {r1, theta1}, {r2, theta2}, ..., {rn, thetan}} we can apply the function to all of these in one command: Apply[ {#1 Cos[#2], #1 Sin[#2]} &, polarpairs, {1} ] (you can bring the #1 to the outside; Mathematica will automatically multiplier scalars by the components of a vector). This is the main operation you need to define the general polar plotting routine that you want. Here is such a routine: PolarListPlot[pairs:{ {_, _}.. }, opts___] := Module[{xypairs, points, curve}, xypairs = Apply[#1 * {Cos[#2], Sin[#2]} &, pairs, {1}]; points = Map[Point, xypairs]; curve = Line[xypairs]; Show[Graphics[{ {PointSize[0.02], points}, curve }, opts ]] ] For your application, you might want a function that converts your pairs (azimuth, elevation) to ordinary polar pairs. I'm not sure I completely understand your coordinate system, but after looking up "azimuth" and "elevation", I decided that maybe an example of this type of system would measure the azimuthal angle with respect to a ray pointing due east, with angles increasing as you go counter- clockwise. Just like theta in the polar system, which makes for a simple example. And the elevation would be the angle that the line connecting the origin to the sun makes with the xy-plane (this would be the plane of the horizon). We could imagine the sun travelling on a great circle of the unit sphere, say the cross section of the sphere determined by the plane y = z. The following would give us (azimuth, elevation) pairs at equally spaced x values, and the angles would be in degrees: elevation[x_] := (180/Pi) ArcSin[Sqrt[1 - x^2]/Sqrt[2]] azimuth[x_] := (180/Pi) ArcTan[x, Sqrt[1 - x^2]/Sqrt[2]] Let's make a list of positions using these coordinates: sunpositions = Table[{azimuth[x], elevation[x]}, {x, 1, -1, -1/10}]; Here's a function that will convert this coordinate system into the standard polar (again, I am not sure if I have understood your system, but this could certainly be modified to fit the way you actually specify coordinates of the sun: CelestialToPolar[pairs:{{_, _}..}] := Apply[ {Cos[#2 Degree], #1 Degree}&, pairs, {1}] Now we convert the pairs in our astronomical system to standard polar, which the general plotting function can handle: sunpolar = CelestialToPolar[sunpositions]; A sanity check. These values look plausible for an object travelling east to west along an arc in the sky elevated 45 degrees: N[sunpolar] {{1., 0}, {0.951315, 0.329949}, {0.905539, 0.487616}, {0.863134, 0.62494}, {0.824621, 0.755969}, {0.790569, 0.886077}, {0.761577, 1.01782}, {0.738241, 1.15232}, {0.72111, 1.28976}, {0.710634, 1.42961}, {0.707107, 1.5708}, {0.710634, 1.71198}, {0.72111, 1.85183}, {0.738241, 1.98928}, {0.761577, 2.12378}, {0.790569, 2.25552}, {0.824621, 2.38562}, {0.863134, 2.51665}, {0.905539, 2.65398}, {0.951315, 2.81164}, {1., 3.14159}} Now for the test: PolarListPlot[sunpolar, Axes->True, AspectRatio->Automatic] When I did this, it looked like about what I expected if I were to project the sun onto the ground at different times from morning to night. Robby Villegas