我有一组x和y坐标,相对于物体在不断旋转的圆形环境(10转/分钟)中的运动.如何区分物体的运动与环境的运动?

我try 了极坐标、速度和运动载体,得到了结果,但我想知道是否有人知道正确的路由. 主要是,我根据距旋转中心的距离对每个点进行反旋,转换为极坐标,创建一系列反旋位置.然后我计算每个original_points[idx]和derotated_points[idx+1]之间的运动载体.然后,我将第一个原始点作为新数组的起点,并向其添加第一个载体,存储新位置.这将是添加第二个载体的起点,等等……

看起来很合理,但我想知道是否还有其他方法.

推荐答案

这是一个非常好的领域,也是一个关于矩阵变换的好问题.如果您想了解这一点,请阅读本课程:https://graphics.stanford.edu/courses/cs248-01/

现在,让我们开始创建一些示例数据:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

rpm = 10  
omega = rpm * 2 * np.pi / 60  
time = np.linspace(0, 60, 60)  
speed = 0.1  

x_linear = speed * time
y_linear = np.zeros_like(time)

x_rotated = x_linear * np.cos(omega * time) - y_linear * np.sin(omega * time)
y_rotated = x_linear * np.sin(omega * time) + y_linear * np.cos(omega * time)

df = pd.DataFrame({
    'time': time,
    'x': x_rotated,
    'y': y_rotated
})


print(df)

这里,我假设rpm = 10,角速度(单位为rad(s))被给出为omega = rpm * 2 * np.pi / 60,物体的速度为speed = 0.1单位/秒.

这给你

         time         x             y
0    0.000000  0.000000  0.000000e+00
1    1.016949  0.049276  8.895896e-02
2    2.033898 -0.107882  1.724206e-01
3    3.050847 -0.304652 -1.623727e-02
4    4.067797 -0.177888 -3.658219e-01
5    5.084746  0.292265 -4.160862e-01
6    6.101695  0.606713  6.485704e-02
7    7.118644  0.276790  6.558492e-01
8    8.135593 -0.502393  6.399064e-01
9    9.152542 -0.903602 -1.455835e-01
10  10.169492 -0.344989 -9.566443e-01
11  11.186441  0.736640 -8.418588e-01
12  12.203390  1.192763  2.579585e-01
13  13.220339  0.381661  1.265744e+00
...
56  56.949153 -5.686844  3.030958e-01
57  57.966102 -3.074643 -4.913986e+00
58  58.983051  2.858029 -5.159620e+00
59  60.000000  6.000000 -5.732833e-14

现在,要go 旋转

def derotate_coordinates(df, omega):
    df['x_derotated'] = df['x']*np.cos(-omega*df['time']) - df['y']*np.sin(-omega*df['time'])
    df['y_derotated'] = df['x']*np.sin(-omega*df['time']) + df['y']*np.cos(-omega*df['time'])
    return df

比照适用的

df_derotated = derotate_coordinates(df.copy(), omega)

print(df_derotated)

会给你

         time         x             y  x_derotated   y_derotated
0    0.000000  0.000000  0.000000e+00     0.000000  0.000000e+00
1    1.016949  0.049276  8.895896e-02     0.101695  0.000000e+00
2    2.033898 -0.107882  1.724206e-01     0.203390 -1.387779e-17
3    3.050847 -0.304652 -1.623727e-02     0.305085  0.000000e+00
4    4.067797 -0.177888 -3.658219e-01     0.406780  0.000000e+00
5    5.084746  0.292265 -4.160862e-01     0.508475  0.000000e+00
6    6.101695  0.606713  6.485704e-02     0.610169  0.000000e+00
7    7.118644  0.276790  6.558492e-01     0.711864  0.000000e+00
8    8.135593 -0.502393  6.399064e-01     0.813559  0.000000e+00
9    9.152542 -0.903602 -1.455835e-01     0.915254  2.775558e-17
10  10.169492 -0.344989 -9.566443e-01     1.016949 -5.551115e-17
11  11.186441  0.736640 -8.418588e-01     1.118644  0.000000e+00
12  12.203390  1.192763  2.579585e-01     1.220339  0.000000e+00
13  13.220339  0.381661  1.265744e+00     1.322034 -5.551115e-17
...
56  56.949153 -5.686844  3.030958e-01     5.694915  0.000000e+00
57  57.966102 -3.074643 -4.913986e+00     5.796610  0.000000e+00
58  58.983051  2.858029 -5.159620e+00     5.898305 -4.440892e-16
59  60.000000  6.000000 -5.732833e-14     6.000000  0.000000e+00

如果您想将其可视化

plt.figure(figsize=(12, 6))

plt.subplot(1, 2, 1)
plt.plot(df['x'], df['y'], 'ro-')
plt.title('Path in Rotating Frame')
plt.xlabel('X')
plt.ylabel('Y')
plt.axis('equal')

plt.subplot(1, 2, 2)
plt.plot(df_derotated['x_derotated'], df_derotated['y_derotated'], 'bo-')
plt.title('Path After Derotation')
plt.xlabel('X')
plt.ylabel('Y')
plt.axis('equal')

plt.show()

这给

enter image description here

更新:在3D中,仅仅因为这是一个迷人的话题

在这种情况下,让我们定义一个旋转螺旋并在极坐标下工作:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

t = np.linspace(0, 4 * np.pi, 100)
x = t * np.sin(t)
y = t * np.cos(t)
z = t

original_points = np.vstack([x, y, z])

def rotation_matrix_y(theta):
    cos_theta, sin_theta = np.cos(theta), np.sin(theta)
    return np.array([
        [cos_theta, 0, sin_theta],
        [0, 1, 0],
        [-sin_theta, 0, cos_theta]
    ])

def rotation_matrix_z(theta):
    cos_theta, sin_theta = np.cos(theta), np.sin(theta)
    return np.array([
        [cos_theta, -sin_theta, 0],
        [sin_theta, cos_theta, 0],
        [0, 0, 1]
    ])

theta_z = np.radians(45)  
theta_y = np.radians(30)  
rot_matrix_z = rotation_matrix_z(theta_z)
rot_matrix_y = rotation_matrix_y(theta_y)

combined_rot_matrix = rot_matrix_y @ rot_matrix_z
rotated_points = combined_rot_matrix @ original_points


inverse_combined_rot_matrix = np.transpose(combined_rot_matrix)

derotated_points = inverse_combined_rot_matrix @ rotated_points

fig = plt.figure(figsize=(18, 6))
ax1 = fig.add_subplot(131, projection='3d')
ax1.plot(*original_points, 'r')
ax1.set_title('Original Spiral')
ax1.set_xlim([-20, 20])
ax1.set_ylim([-20, 20])
ax1.set_zlim([0, 40])

ax2 = fig.add_subplot(132, projection='3d')
ax2.plot(*rotated_points, 'b')
ax2.set_title('Rotated Spiral')
ax2.set_xlim([-20, 20])
ax2.set_ylim([-20, 20])
ax2.set_zlim([0, 40])

ax3 = fig.add_subplot(133, projection='3d')
ax3.plot(*derotated_points, 'g')
ax3.set_title('Derotated Spiral')
ax3.set_xlim([-20, 20])
ax3.set_ylim([-20, 20])
ax3.set_zlim([0, 40])

plt.show()

这给 you

enter image description here

Python相关问答推荐

使用GEKKO在简单DTE系统中进行一致初始化

LAB中的增强数组

如何调整spaCy token 化器,以便在德国模型中将数字拆分为行末端的点

将numpy数组存储在原始二进制文件中

点到面的Y距离

如何删除索引过go 的lexsort深度可能会影响性能?' &>

Pandas 有条件轮班操作

将数据框架与导入的Excel文件一起使用

在Polars(Python库)中将二进制转换为具有非UTF-8字符的字符串变量

使用groupby Pandas的一些操作

Pandas—合并数据帧,在公共列上保留非空值,在另一列上保留平均值

Python—从np.array中 Select 复杂的列子集

未知依赖项pin—1阻止conda安装""

手动设置seborn/matplotlib散点图连续变量图例中显示的值

Python—为什么我的代码返回一个TypeError

如何反转一个框架中列的值?

如何在Python中将超链接添加到PDF中每个页面的顶部?

如何用FFT确定频变幅值

Pythonquests.get(Url)返回Colab中的空内容

Pandas 删除只有一种类型的值的行,重复或不重复