日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

滑动轨迹 曲线 python_python – 计算轨迹(路径)中的转折点/枢轴点

發布時間:2025/3/15 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 滑动轨迹 曲线 python_python – 计算轨迹(路径)中的转折点/枢轴点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

您可以使用

Ramer-Douglas-Peucker (RDP) algorithm來簡化路徑。然后,您可以計算簡化路徑每段的方向變化。對應于方向最大變化的點可以稱為轉折點:

RDP算法的Python實現可以在on github中找到。

import matplotlib.pyplot as plt

import numpy as np

import os

import rdp

def angle(dir):

"""

Returns the angles between vectors.

Parameters:

dir is a 2D-array of shape (N,M) representing N vectors in M-dimensional space.

The return value is a 1D-array of values of shape (N-1,), with each value

between 0 and pi.

0 implies the vectors point in the same direction

pi/2 implies the vectors are orthogonal

pi implies the vectors point in opposite directions

"""

dir2 = dir[1:]

dir1 = dir[:-1]

return np.arccos((dir1*dir2).sum(axis=1)/(

np.sqrt((dir1**2).sum(axis=1)*(dir2**2).sum(axis=1))))

tolerance = 70

min_angle = np.pi*0.22

filename = os.path.expanduser('~/tmp/bla.data')

points = np.genfromtxt(filename).T

print(len(points))

x, y = points.T

# Use the Ramer-Douglas-Peucker algorithm to simplify the path

# http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm

# Python implementation: https://github.com/sebleier/RDP/

simplified = np.array(rdp.rdp(points.tolist(), tolerance))

print(len(simplified))

sx, sy = simplified.T

# compute the direction vectors on the simplified curve

directions = np.diff(simplified, axis=0)

theta = angle(directions)

# Select the index of the points with the greatest theta

# Large theta is associated with greatest change in direction.

idx = np.where(theta>min_angle)[0]+1

fig = plt.figure()

ax =fig.add_subplot(111)

ax.plot(x, y, 'b-', label='original path')

ax.plot(sx, sy, 'g--', label='simplified path')

ax.plot(sx[idx], sy[idx], 'ro', markersize = 10, label='turning points')

ax.invert_yaxis()

plt.legend(loc='best')

plt.show()

以上使用兩個參數:

> RDP算法采用一個參數,公差,其中代表簡化路徑的最大距離可能偏離原來的路徑。公差越大,粗魯的路徑就越簡單。>另一個參數是min_angle,它定義了被認為是一個轉折點。 (我正在轉彎點是原始路徑上的任何一點,簡化路徑上的進入和退出向量之間的角度大于min_angle)。

總結

以上是生活随笔為你收集整理的滑动轨迹 曲线 python_python – 计算轨迹(路径)中的转折点/枢轴点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。