【问题标题】:How to measure the distance between The control Polygon and the nth subdivision curve?如何测量控制多边形与第n条细分曲线之间的距离?
【发布时间】:2020-10-29 16:41:42
【问题描述】:
  • 我有一个 m 个点的控制多边形,比如 m = 6,我正在应用 n 个细化,比如 n = 5,使用不同的细分方案:

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

我的问题是:

如何测量得到的具有不同点数的细分曲线与原始控制多边形之间的距离?

#========================
# 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

【问题讨论】:

    标签: python geometry polygon shapely


    【解决方案1】:

    解决方案在 Shapely 库中,Hausdorff Distance 已经在那里实现:

    polygon2.hausdorff_distance(polygon)
    

    【讨论】:

      猜你喜欢
      • 2013-02-13
      • 1970-01-01
      • 2017-06-04
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 2023-01-28
      相关资源
      最近更新 更多