蟒蛇。如何从ax,y点列表和偏移距离获取偏移样条曲线的x,y坐标

番荔枝

我需要对机翼轮廓曲线进行偏移的平行包围,但是我无法弄清楚如何使所有点与所需轮廓上的主轮廓曲线上的点等距。

这是我的机翼轮廓示例 在此处输入图片说明

这是我最好的,不是很好的方法 在此处输入图片说明

编辑@Patrick距离为0.2的解在此处输入图片说明

帕特里克·莫平

您必须对无穷大/零的斜率进行特殊处理,但是基本方法是使用插值法计算一个点的斜率,然后找到垂直斜率,然后计算该距离处的点。

我从此处修改了示例,以添加第二张图。它可以与您提供数据文件一起使用,但是您可能需要更改其他信封的符号计算。

编辑根据您对希望信封连续的评论,我在末尾添加了一个俗气的半圆形,非常适合您。本质上,在创建信封时,可以使信封更圆,更凸,效果会更好。另外,您需要重叠开头和结尾,否则就会有空白。

而且,几乎可以肯定它会变得更有效率-无论如何我都不是一个麻木的专家,所以这只是纯Python。

def offset(coordinates, distance):
    coordinates = iter(coordinates)
    x1, y1 = coordinates.next()
    z = distance
    points = []
    for x2, y2 in coordinates:
        # tangential slope approximation
        try:
            slope = (y2 - y1) / (x2 - x1)
            # perpendicular slope
            pslope = -1/slope  # (might be 1/slope depending on direction of travel)
        except ZeroDivisionError:
            continue
        mid_x = (x1 + x2) / 2
        mid_y = (y1 + y2) / 2

        sign = ((pslope > 0) == (x1 > x2)) * 2 - 1

        # if z is the distance to your parallel curve,
        # then your delta-x and delta-y calculations are:
        #   z**2 = x**2 + y**2
        #   y = pslope * x
        #   z**2 = x**2 + (pslope * x)**2
        #   z**2 = x**2 + pslope**2 * x**2
        #   z**2 = (1 + pslope**2) * x**2
        #   z**2 / (1 + pslope**2) = x**2
        #   z / (1 + pslope**2)**0.5 = x

        delta_x = sign * z / ((1 + pslope**2)**0.5)
        delta_y = pslope * delta_x

        points.append((mid_x + delta_x, mid_y + delta_y))
        x1, y1 = x2, y2
    return points

def add_semicircle(x_origin, y_origin, radius, num_x = 50):
    points = []
    for index in range(num_x):
        x = radius * index / num_x
        y = (radius ** 2 - x ** 2) ** 0.5
        points.append((x, -y))
    points += [(x, -y) for x, y in reversed(points)]
    return [(x + x_origin, y + y_origin) for x, y in points]

def round_data(data):
    # Add infinitesimal rounding of the envelope
    assert data[-1] == data[0]
    x0, y0 = data[0]
    x1, y1 = data[1]
    xe, ye = data[-2]

    x = x0 - (x0 - x1) * .01
    y = y0 - (y0 - y1) * .01
    yn = (x - xe) / (x0 - xe) * (y0 - ye) + ye
    data[0] = x, y
    data[-1] = x, yn
    data.extend(add_semicircle(x, (y + yn) / 2, abs((y - yn) / 2)))
    del data[-18:]

from pylab import *

with open('ah79100c.dat', 'rb') as f:
    f.next()
    data = [[float(x) for x in line.split()] for line in f if line.strip()]

t = [x[0] for x in data]
s = [x[1] for x in data]


round_data(data)

parallel = offset(data, 0.1)
t2 = [x[0] for x in parallel]
s2 = [x[1] for x in parallel]

plot(t, s, 'g', t2, s2, 'b', lw=1)

title('Wing with envelope')
grid(True)

axes().set_aspect('equal', 'datalim')

savefig("test.png")
show()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

获取JPanel坐标的x和y偏移量

D3.js如何获取x和y轴的位置/偏移

如何获取视图的X和Y坐标

如何从UnsafeMutableBufferPointer获取x和y坐标

如何根据绘图曲线的X坐标(QWT)获得Y坐标?

样条图上的标记点绑定到 x 和 y 轴

如何从dlib 68 x-y坐标测量面部地标中2点之间的距离

给定一组 x 和 y 坐标,在 javascript 中获取曲线的方程

如何将图像数据分成x,y坐标?(蟒蛇)

如何从python中的2D列表中获取最大x和最小y坐标?

使用 x,y 坐标点列表绘制曲线峰

合并(2个列表)X坐标列表和Y坐标列表以获取(1个列表)XY坐标列表

X和Y在带偏移的画布中不匹配

根据具有最小和最大偏移量的中心点计算随机 X 和 Y

如何找到x距AB线段的距离和y距BC线段的距离的点的位置?

单击时如何获取图像的X和Y坐标(快速)

React Native-如何从ScrollView获取视图的Y偏移值?

本征样条插值-如何在任意点x处获得样条y值?

如何获取 Lissajous 曲线表中所有曲线的 X 和 Y 位置?

我可以分别为WPF Bezier曲线控制点的X和Y坐标设置动画吗?

生成具有最小距离的随机x和y坐标

返回x和y坐标元组的列表

通过x,y坐标列表在图像中绘制圆和X点.asp C#

使用R中的欧式距离在曲线上找到X,Y坐标

获取临时密钥 x 和 y 坐标

Netbeans:获取X和Y坐标

从注释iOS获取X和Y坐标

根据椭圆曲线点的x和y值生成PublicKey

MouseMotionListener显示(x,y)偏移量