我有一组测量点(x,y),我试图计算一组等距平行点,这些点是基于直线上的原始点。数学对我来说有点混乱,每次我调整计算都不会正确。每个点都应该与原始直线的距离完全相同。
在示例1中,在直线的垂直部分中,该距离看起来更远,然后在弯曲或更水平的部分中,该距离更接近原始示例1:enter image description here
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('data.csv')
print(df.columns)
print(df.head())
df_s = df[["TVD","VS"]].sort_values(axis=0, by='TVD', ascending=True).reset_index(drop=True)
df_s['TVD'] = df_s['TVD']*-1
print(df.info())
# df_s.to_csv('filt.csv')
print(df_s.head())
# Define the original curved line
df_s = df_s[df_s['TVD']>-5000]
y = df_s['TVD']
x = df_s['VS']
# Define the distance between the original and parallel lines
distance = 50
# Calculate the offset for the parallel line
dx = np.gradient(x)
dy = np.gradient(y)
ds = np.sqrt(dx**2 + dy**2)
dxn = dx / ds
dyn = dy / ds
x_offset = distance * dyn
y_offset = -distance * dxn
# Calculate the new curved line
x_new = x + x_offset
y_new = y + y_offset
# Plot the original and parallel lines
plt.plot(x, y, label='Original')
plt.plot(x_new, y_new, label='Parallel')
plt.legend()
plt.show()
在示例2中,它穿过直线.....示例2:enter image description here
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('data.csv')
print(df.columns)
print(df.head())
df_s = df[["TVD","VS"]].sort_values(axis=0, by='TVD', ascending=True).reset_index(drop=True)
df_s['TVD'] = df_s['TVD']*-1
print(df.info())
# df_s.to_csv('filt.csv')
print(df_s.head())
# Define the original curved line
df_s = df_s[df_s['TVD']>-5000]
y = df_s['TVD']
x = df_s['VS']
# Define the distance between the original and parallel lines
distance = 50
# Calculate the inclination angle at each point along the original line
dx = np.gradient(x)
dy = np.gradient(y)
inclination = np.arctan2(dy, dx)
# Calculate the adjusted distance for the parallel line
adjusted_distance = distance * np.cos(inclination)
# Calculate the offset for the parallel line
x_offset = adjusted_distance * np.sin(inclination)
y_offset = -adjusted_distance * np.cos(inclination)
# Calculate the new curved line
x_new = x + x_offset
y_new = y + y_offset
# Plot the original and parallel lines
plt.plot(x, y, label='Original')
# plt.plot(x_new, y_new, label='Parallel')
plt.legend()
plt.show()
示例3是我想要计算的内容。手绘版本示例3:enter image description here
我能想到的一切,包括询问ChatGPT。
1条答案
按热度按时间wwodge7n1#
您的第一种方法很好,但绘图在X轴和Y轴上具有不同的比例(请查看标注值差异),因此
使用
Axes.set_aspect()
(examples)均衡比例