如何测量控制多边形与第n个细分曲线之间的距离?

时间:2020-10-29 16:41:42

标签: python geometry polygon shapely

  • 我有一个m个点的控制多边形,例如m = 6,并且我正在通过不同的细分方案应用n个细化条件,例如n = 5

    Chaikin,角点切割,4点方案,广义4点方案,3度均匀样条。

我的问题是:

如何测量不同点数的细分曲线与原始控件Polygon之间的距离?

Distance

#========================
# Import Libraries
#========================
import numpy as np
import matplotlib.pyplot as plt
# !pip install shapely
from shapely.geometry import Point, Polygon 

#========================
# Define the Polygon
#========================
# Define Control Points
P1 = Point(0.0, 0.0)
P2 = Point(1.0, 2.0)
P3 = Point(2.0, 2.0)
P4 = Point(4.0, 4.0)
P5 = Point(5.0, 9.0)
P6 = Point(1.0, 7.0)
# control Points List
PointList = [P1, P2, P3, P4, P5, P6]
# Define a Polygon from the list of the control points
Polygn = Polygon(PointList)
#==========================================
# Uniform Spline of Degree k = 3
#==========================================
plt.figure(num='Uniform Spline of degree k =3 Subdivision Scheme')

for n in range(5):
    PointList2 = []
    for idx in range(len(PointList)):
        # Get Three of adjacent points
        P1n = PointList[idx-2]
        P2n = PointList[idx-1]
        P3n = PointList[idx]
        # Get new First Control Point
        x21n = 0.125 * (P1n.x + 6*P2n.x + P3n.x)
        y21n = 0.125 * (P1n.y + 6*P2n.y + P3n.y)
        P21n = Point(x21n, y21n)
        PointList2.append(P21n)
        # Get new Second Control Point
        x22n = 0.5 * (P2n.x+P3n.x)
        y22n = 0.5 * (P2n.y+P3n.y)
        P22n = Point(x22n, y22n)
        PointList2.append(P22n)
    # Assign the New list of points to the old one
    PointList = PointList2
    # print(len(PointList2))
    Polygn2 = Polygon(PointList2)
    
    # 
    plt.plot(*Polygn.exterior.xy, 'ro--', linewidth=1, markersize=4, label='Original')
    plt.plot(*Polygn2.exterior.xy, 'go-', linewidth=1, markersize=2, label='Subdivision ({})'.format(n+1))
    plt.legend(bbox_to_anchor=(.68, .14), loc='upper left', borderaxespad=0.)
    plt.show(block=False)
    plt.pause(1)
    plt.clf()
#=========================
# Distance Finction
#=========================
def dist(Polygn, Polygn2):
 pass
 # return max_dist

1 个答案:

答案 0 :(得分:0)

该解决方案位于 Shapely 库中,Hausdorff Distance已在该库中实现:

polygon2.hausdorff_distance(polygon)