Python. How to get the x,y coordinates of a offset spline from a x,y list of points and offset distance

前端 未结 2 1453
独厮守ぢ
独厮守ぢ 2021-02-06 07:45

I need to make an offset parallel enclosure of an airfoil profile curve, but I cant figure out how to make all the points be equidistant to the points on the primary profile cur

2条回答
  •  甜味超标
    2021-02-06 08:08

    If you are willing (and able) to install a third-party tool, I'd highly recommend the Shapely module. Here's a small sample that offsets both inward and outward:

    from StringIO import StringIO
    import matplotlib.pyplot as plt
    import numpy as np
    import requests
    import shapely.geometry as shp
    
    # Read the points    
    AFURL = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/ah79100c.dat'
    afpts = np.loadtxt(StringIO(requests.get(AFURL).content), skiprows=1)
    
    # Create a Polygon from the nx2 array in `afpts`
    afpoly = shp.Polygon(afpts)
    
    # Create offset airfoils, both inward and outward
    poffafpoly = afpoly.buffer(0.03)  # Outward offset
    noffafpoly = afpoly.buffer(-0.03)  # Inward offset
    
    # Turn polygon points into numpy arrays for plotting
    afpolypts = np.array(afpoly.exterior)
    poffafpolypts = np.array(poffafpoly.exterior)
    noffafpolypts = np.array(noffafpoly.exterior)
    
    # Plot points
    plt.plot(*afpolypts.T, color='black')
    plt.plot(*poffafpolypts.T, color='red')
    plt.plot(*noffafpolypts.T, color='green')
    plt.axis('equal')
    plt.show()
    

    And here's the output; notice how the 'bowties' (self-intersections) on the inward offset are automatically removed:

提交回复
热议问题