I have a set of survey points (x,y) and I am trying to calculate a set of equidistant parallel points based off of the original point on the line. The math is a bit confusing for me and every time I adjust the calculations it never comes out right. Each point should be exactly the same distance away from the original line.
In example 1, in the vertical section of the line it appears that the distance seems further away and then in the curved or more horizontal section the distance is closer to the original Example 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()
In example 2, it crosses over the line..... Example 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()
Example 3 is what I am looking to calculate..hand drawn version Example 3: enter image description here
Everything I can think of, including asking ChatGPT.