如何逆时针订购积分 [英] How to order points anti clockwise
问题描述
让这些得分.
pt={{-4.65371,0.1},{-4.68489,0.103169},{-4.78341,0.104834},{-4.83897,0.100757},
{-4.92102,0.0949725},{-4.93456,0.100181},{-4.89166,0.122666},{-4.78298,0.129514},
{-4.72723,0.121442},{-4.68355,0.11023},{-4.65371,0.1},{-4.66924,0.10173},
{-4.93059,0.0966989},{-4.93259,0.105094},{-4.91074,0.116966},{-4.90635,0.094878},
{-4.66846,0.105327},{-4.92647,0.0956182},{-4.93433,0.102498},{-4.9333,0.0982262},
{-4.66257,0.10102}};
现在它们处于特定顺序(对我来说是一种疾病!),如果我们查看ListLinePLot
Now they are in certain order (for me is a disorder!) which can be seen if we look at the ListLinePLot
picUnorder=ListLinePlot[pt,Frame-> True,Mesh-> All,MeshStyle-> PointSize[Large]];
SeepicUnorder=ListLinePlot[pt,Frame-> True,Mesh-> All,MeshStyle->
PointSize[Large]]/.Line[rest_]:>{Arrowheads[Table[0.02,{i,0,1,.02}]],Arrow[rest]};
GraphicsGrid[{{picUnorder,SeepicUnorder}}]
但是我们需要像下面的图片一样订购它们.
But we need to order them like the picture below.
有人对逆时针方向对此类2D点进行排序的算法提出任何建议,以便我们可以通过在重新排列的点上使用ListLinePlot
来重新排列点列表以创建类似上图所示的几何图形? ?
Does anybody has some suggestion for a algorithm to sort such 2D points in counter clockwise direction so that we can rearrange the list of points to create a geometry like the last pic just by using ListLinePlot
on the rearranged points????
使用建议,我们将获得以下内容.
Using the suggestion we get something like the following.
center=Mean[pt];
pts=SortBy[pt,Function[p,{x,y}=p-center;ArcTan[x,y]]];
Show[ListPlot[pt],ListLinePlot[pts,Mesh-> All,MeshStyle->
PointSize[Large]],Frame-> True]
BR
推荐答案
I've just read in a comment to nikie's answer that what you really want is the algorithm for an airfoil. So, I am posting another (unrelated) answer to this problem:
似乎比一般问题更容易,因为它几乎是凸的".我认为以下算法可降低FindShortestTour本质上在急性顶点处所具有的风险:
Seems easier than the general problem, because it is "almost convex". I think the following algorithm reduce the risks that FindShortestTour inherently has at the acute vertex:
- 找到
ConvexHull
(占上表面和攻击面) - 从集合中删除凸包中的点
- 用剩余的点执行
FindShortestTour
- 在最近的端点处连接两条曲线
- Voilà
- Find the
ConvexHull
(that accounts for the upper and attack surfaces) - Remove from the set the points in the convex hull
- Perform a
FindShortestTour
with the remaining points - Join both curves at the nearest endpoints
- Voilà
赞:
pt1 = Union@pt;
<< ComputationalGeometry`
convexhull = ConvexHull[pt1, AllPoints -> True];
pt2 = pt1[[convexhull]];
pt3 = Complement[pt1, pt2];
pt4 = pt3[[(FindShortestTour@pt3)[[2]]]];
If[Norm[Last@pt4 - First@pt2] > Norm[Last@pt4 - Last@pt2], pt4 = Reverse@pt4];
pt5 = Join[pt4, pt2, {pt4[[1]]}];
Graphics[{Arrowheads[.02], Arrow@Partition[pt5, 2, 1],
Red, PointSize[Medium], Point@pt1}]
这篇关于如何逆时针订购积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!