到海岸的最快路径
找出从美国本土各州州府到一个美国国界的最短的可能路径.
取得州府列表.
In[1]:=
![Click for copyable input](assets.zh/the-fastest-way-to-the-coast/In_88.png)
capitals =
EntityValue[
EntityClass["AdministrativeDivision", "ContinentalUSStates"],
"CapitalCity"]
Out[1]=
![](assets.zh/the-fastest-way-to-the-coast/O_71.png)
获取美国的多边形图.
In[2]:=
![Click for copyable input](assets.zh/the-fastest-way-to-the-coast/In_89.png)
us = EntityValue[Entity["Country", "UnitedStates"], "Polygon"]
Out[2]=
![](assets.zh/the-fastest-way-to-the-coast/O_72.png)
对每一个州府,计算多边图上与之相距最近的点.
In[3]:=
![Click for copyable input](assets.zh/the-fastest-way-to-the-coast/In_90.png)
borderpoints = Flatten[Nearest[First[us], GeoPosition[capitals]]]
Out[3]=
![](assets.zh/the-fastest-way-to-the-coast/O_73.png)
绘制全部测地路径.
In[4]:=
![Click for copyable input](assets.zh/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.zh/the-fastest-way-to-the-coast/O_74.png)