Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: "Traveling salesman on a hemisphere" problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121597] Re: "Traveling salesman on a hemisphere" problem
  • From: Dana DeLouis <dana01 at me.com>
  • Date: Wed, 21 Sep 2011 05:35:19 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

> with the arcane from http://en.wikipedia.org/wiki/Great-circle_distance,

> arclen[{_, {F1_, L1_}}, {_, {F2_, L2_}}] :=
>  Module[{f1 = F1 Degree, l1 = L1 Degree, f2 = F2 Degree, l2 = L2
> Degree, dl = (L1 - L2) Degree},
>   ArcTan[Sin[f1] Sin[f2] + Cos[f1] Cos[f2] Cos[dl],
>              Sqrt[(Cos[f2] Sin[dl])^2 + (Cos[f1] Sin[f2] - Sin[f1]
> Cos[f2] Cos[dl])^2]]]

Hi.  I know the OP has a solution, but I thought the Vector form on the link Olaf provided was an interesting alternative.

ArcLen[Pt1_,Pt2_]:=Module[
{fx,t},

fx[{Lat_,Long_}]:=
{
Cos[Lat]*Cos[Long],
Cos[Lat]*Sin[Long],
Sin[Lat]
};

t={Pt1,Pt2}*Degree;

Apply[Dot,Map[fx,t]]//ArcCos
]

(* Some Examples *)

ArcLen[{21,44.7},{57.3,7}]
0.7945159

ArcLen[{0,0},{90,0}]
Pi/2

ArcLen[{0,0},{0,180}]
Pi

= = =

The article mentions an ArcTan version...

ArcLen2[Pt1_,Pt2_]:=Module[
{fx,t},

fx[{Lat_,Long_}]:={
Cos[Lat]*Cos[Long],
Cos[Lat]*Sin[Long],
Sin[Lat]};

t={Pt1,Pt2}*Degree;
t=Map[fx,t];

ArcTan[Apply[Dot,t],Norm[Apply[Cross,t]]]
]

ArcLen2[{21,44.7},{57.3,7}]
0.7945159

Anyway, I just thought it was interesting.
I do not know of a way to get the built-in commands such as
GeoPositionXYZ or any of the other commands to work with spherical objects.

= = = 
Dana DeLouis
$Version
8.0 for Mac OS X x86 (64-bit) (November 6, 2010)






On Sep 16, 5:55 am, Olaf <olaf.rogal... at googlemail.com> wrote:
> Hi Peter,
> 
> with the arclen fromhttp://en.wikipedia.org/wiki/Great-circle_distance,
> the following code will give you the shortest route.
> 
> stars = {
>    {"M51", {21, 44.7}},
>    {"NGC2721", {4, -17}},
>    {"a funny comet", {57.3, 7}},
>    {"absolutely must see", {23, -176.3}}};
> 
> arclen[{_, {F1_, L1_}}, {_, {F2_, L2_}}] :=
>  Module[{f1 = F1 Degree, l1 = L1 Degree, f2 = F2 Degree, l2 = L2
> Degree, dl = (L1 - L2) Degree},
>   ArcTan[Sin[f1] Sin[f2] + Cos[f1] Cos[f2] Cos[dl],
>              Sqrt[(Cos[f2] Sin[dl])^2 + (Cos[f1] Sin[f2] - Sin[f1]
> Cos[f2] Cos[dl])^2]]]
> 
> tour = FindShortestTour[stars, DistanceFunction -> arclen]
> 
> sortedStars = starlist[[tour[[2]]]]
> 
> And here some eye-candy:
> 
> p2c[{_, {f_, l_}}] := {Cos[f Degree] Cos[l Degree],
>   Sin[f Degree] Cos[l Degree], Sin[l Degree]}
> greatCircleArc[{q_, p_}] :=
>  Module[{u = p2c[q], v = p2c[p], a}, a = VectorAngle[u, v];
>   Table[Evaluate[RotationTransform[t, {u, v}][u]], {t, 0, a,
>     a/Ceiling[10 a]}]]
> 
> Graphics3D[
>  {Sphere[{0, 0, 0}, 0.97],
>   {Black, Thick, Arrow[{{0, 0, -1.3}, {0, 0, 1.3}}]},
>   {Red, PointSize[Medium], Point[Map[p2c, sortedStars]]},
>   {Blue, Thick,
>    Map[Line, Map[greatCircleArc, Partition[sortedStars, 2, 1]]]}
>   }, SphericalRegion -> True]
> 
> Regards, Olaf







  • Prev by Date: Re: Plot axis length and size ratio (TwoPlot revive)
  • Next by Date: Re: Compilation: Avoiding inlining
  • Previous by thread: Re: "Traveling salesman on a hemisphere" problem
  • Next by thread: Compilation: Avoiding inlining