【问题标题】:splitting polygon in 2 equal parts将多边形分成两等份
【发布时间】:2014-08-08 16:03:51
【问题描述】:

我有凸多边形,我想得到平行 X 轴的线,将多边形分成 2 个相等的区域。 我试图实现以下(对于X轴): 0. 将多边形的所有顶点按 Y 坐标递增的顺序排序。 1. 得到 Y 坐标最小的点 P。 2. 用穿过 P 的垂直线分割多边形。 3. 遍历所有顶点并将所有 x > P.x 的顶点添加到 q 数组,将所有其他顶点添加到 p 数组 4. 遍历所有顶点的数组,查看当前顶点所属的位置以及它可以投影在哪条线上。 5.计算我得到的梯形面积。

更新: 我决定选择 2 个顶点:最大和最小 Y 坐标以及它们给出的线 2 将所有顶点划分为 2 个数组 p 和 q。 现在我需要按给定的比例划分梯形。如果我知道底数和高度,我该怎么做? 如何以给定的比例分割由 p1 和 p2 顶点给出的梯形区域?

【问题讨论】:

    标签: algorithm polygons


    【解决方案1】:

    这是一种可以有效完成的方法:-

    1. A horizontal line cut the convex polygon at exactly two points.
    2. You can evaluate for each line segment forming the side of polygon 
       the interval of its y values.
    3. Using these intervals you can easily determine the overlapping pairs of lines using sorting.
    4. you now have interval of y values (y1,y2) and corresponding lines which are
       intersected within these interval.
    5. Consider a pair of line (l1,l2) that are intersected by given y=k where y1<=k<=y2
    6. x1 = (k-c1)/m1 and x2 = (k-c2)/m2
    7. find difference between the areas of two polygons formed by them is to minimized.
    8. minimize F(k) = (A1-A2)^2 = d/dk[(A1-A2)^2] = (A1-A2)*(d/dk(A1)-d/dk(A2)) = 0.
    9. as F(K) is only single variable continuous function in interval [y1,y2] you can easily find its solution.
    10. The given y=k is minimum for given interval for y.
    11. record minimum value of absolute diff for all interval and select the one which is 
        minimum in all intervals.
    

    时间复杂度:-

    Finding overlapping intervals is O(nlogn) using sorting.
    Finding minimum must take O(intervals*n).
    

    使用顶点查找多边形区域:-

    Area of polygon using vertices

    【讨论】:

      【解决方案2】:

      类似于另一个答案,除了更少的二分搜索操作,这也给出了一个准确的答案。对顶点的 y 坐标进行排序。设 m 和 M 是最小和最大 y 坐标。然后从中间顶点 y 坐标 y0 开始,看看穿过它的线是否面积相等。如果没有,则设置 m = y0 或 M = y0,具体取决于顶部或底部是否有更多面积。您将找到一个面积相等的顶点 y 坐标,或者您会找到两个相邻的顶点 y 坐标,其中一个给顶部更多面积,另一个给底部更多面积。所以你知道正确的分割是在这两个相邻的 y 坐标之间。根据正确分割线的位置象征性地计算顶部和底部区域(您可以这样做,因为分割线 y 坐标的范围不与任何顶点重叠)。然后设置两个面积表达式相等并求解正确的分割线。这种方法的优点是您可以获得准确的答案,并且最多只需要 lg(n) 二进制搜索操作,其中 n 是顶点的数量。

      如果你对多边形进行三角剖分,你将最多有 n 个三角形,每个三角形的面积都可以在恒定时间内预先计算,当你用分割线对三角形进行切片并对结果区域进行三角剖分时,这将产生大多数 O(n) 附加三角形,每个三角形的面积都可以在恒定时间内计算。所以算法的二分查找部分需要 O(n log n) 时间。最终计算(求解精确的分割线)需要线性时间。所以整体时间复杂度是 O(n log n)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-08
        • 2020-11-02
        • 2012-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多