国境までの最短経路
アメリカの隣接する州の各州都から,アメリカの国境の任意の点までの最短経路を求める.
州都のリストを得る.
In[1]:=
![Click for copyable input](assets.ja/the-fastest-way-to-the-coast/In_88.png)
capitals =
EntityValue[
EntityClass["AdministrativeDivision", "ContinentalUSStates"],
"CapitalCity"]
Out[1]=
![](assets.ja/the-fastest-way-to-the-coast/O_71.png)
アメリカの多角形を得る.
In[2]:=
![Click for copyable input](assets.ja/the-fastest-way-to-the-coast/In_89.png)
us = EntityValue[Entity["Country", "UnitedStates"], "Polygon"]
Out[2]=
![](assets.ja/the-fastest-way-to-the-coast/O_72.png)
それぞれの州都について,多角形の境界上の一番近い点を計算する.
In[3]:=
![Click for copyable input](assets.ja/the-fastest-way-to-the-coast/In_90.png)
borderpoints = Flatten[Nearest[First[us], GeoPosition[capitals]]]
Out[3]=
![](assets.ja/the-fastest-way-to-the-coast/O_73.png)
すべての測地経路を描画する.
In[4]:=
![Click for copyable input](assets.ja/the-fastest-way-to-the-coast/In_91.png)
GeoGraphics[{us, Point[capitals], Red, Arrowheads[0.015],
Arrow /@ GeoPath /@ Thread[{capitals, borderpoints}]}]
Out[4]=
![](assets.ja/the-fastest-way-to-the-coast/O_74.png)