AngularFormat again
- To: mathgroup at smc.vnet.net
- Subject: [mg21037] AngularFormat again
- From: "Alan W.Hopper" <awhopper at hermes.net.au>
- Date: Sun, 12 Dec 1999 23:51:06 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi everybody, Thanks to all who replied to my query a little while back on how to produce a degree, arcminute, arcsecond format with the respective symbols in place. Here is a summary, In[1]:= Off[General::spell1] From Jens-Peer Kuska , > In[21]:= > Clear[dms]; > dms[n_]:=Module[{d,m,s,a}, > d=IntegerPart[n]; > a=60*FractionalPart[n]; > m=IntegerPart[a]; > s=60*FractionalPart[a]; > Angle[{d,m,s}]] > In[22]:= > Angle/: MakeBoxes[Angle[{deg_,min_,sec_}],f_:TraditionalForm]:= > RowBox[{MakeBoxes[deg,f],"\[Degree]", > MakeBoxes[min,f],"\[CloseCurlyQuote]", > MakeBoxes[sec,f],"\[CloseCurlyDoubleQuote]"}] >> In[23]:= >> Clear[dms]; >> Format[dms[n_]] := Module[{d, m, s, a}, d = IntegerPart[n]; >> a = 60*FractionalPart[n]; >> m = IntegerPart[a]; >> s = 60*FractionalPart[a]; >> SequenceForm[d, "° ", m, "' ", s, "\""]] >>> In[24]:= >>> Clear[dms]; >>> dms[n_]:=Module[{d,m,s,a}, >>> d=IntegerPart[n]; >>> a=60*FractionalPart[n]; >>> m=IntegerPart[a]; >>> s=60*FractionalPart[a]; >>> DegMinSecForm[d,m,s]] >>>In[25]:= >>> dmsString[DegMinSecForm[d_,m_,s_]]:= >>> { >>> ToString[d]<>"°\[ThinSpace]"<>ToString[m]<> >>> "'\[ThinSpace]"<>ToString[s]<>"\"" >>> } >>>In[26]:= >>> MakeBoxes[n_DegMinSecForm,form_]:= >>> MakeBoxes[#,form]& @@dmsString[n] Jens-Peer's, Helmut's, and Ted's programs all give the degree, arcminute, and arcsecond symbols after their respective numerical values, in their output, (after an input of dms[real No]). Thanks also to , Peter Breitfeld [mg 20905] with 2 programs (a bit lengthy to reproduce), which have an option for symbolic hour, minute, second format from decimal hours. Both symbolic angular and time units can be re-formatted to decimal fractions, with Peter's handy programs. And David Park has been most helpful with a private communication consisting of a package for the variant angular format used in Astronomy. Lastly, I wonder if anyone has a comment to make on the program below which shows the difficulty in getting a 'correct' angle from coordinates in all the 4 quadrants of the real Cartesian plane. Should there be a built-in option to always get a positive angle result in Mathematica? In[27]:= quads4[x_,y_]:= Module[{a1,a2,a3,quots}, N[ a1 = ArcTan[y/x]/ Degree; a2 = ArcTan[x,y]/ Degree; a3 = a2; If[a3 < 0, a3 = a3 + 360]; quots = Tan[a3 Degree]; {a1,a2,a3,quots},12]] In[28]:= coords= {{0.5,0.7},{-0.5,0.7},{-0.5,-0.7},{0.5,-0.7}}; In[29]:= TableForm[Apply[quads4,coords,1], TableHeadings->{None,{"a1","a2","a3","tan a3"}}, TableAlignments->Center] Out[30]= a1 a2 a3 tan a3 54.462... 54.462... 54.462... 1.4 -54.462... 125.5376... 125.5376... -1.4 54.462... -125.5376... 234.462... 1.4 -54-462... -54.462... 305.5376... -1.4 I know that a2 is valid by Mathematica's Tan and ArcTan definitions, (Help Browser - ArcTan[x, y] gives the arc tangent of y/x, taking into account which quadrant the point a is in.) But I personally prefer the a3 result. Alan Hopper, awhopper at hermes.net.au