-1

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Tyler
  • 1

2 Answers2

0

Your first approach is fine, but plot has distinct scales over X- and Y- axes (look at label values differences), so

Equalize scale using Axes.set_aspect() (examples)

MBo
  • 77,366
  • 5
  • 53
  • 86
0

Here is how I solved this problem for future reference.

import math
    
    def rotate_point_about_point(x1, y1, shift, angle):
       # Convert angle to radians
       angle_rad = math.radians(angle)
    
       # Calculate sine and cosine of angle
       cos_angle = math.cos(angle_rad)
       sin_angle = math.sin(angle_rad)
    
       # Translate point 2 so that point 1 is at the origin
       x2,y2 = x1+shift, y1
       x2 -= x1
       y2 -= y1
    
       # Rotate point 2 about the origin
       right_x = x2 * cos_angle - y2 * sin_angle
       right_y = x2 * sin_angle + y2 * cos_angle
    
       # Translate point 2 back to its original position relative to point 1
       right_x += x1
       right_y += y1
       # ---------
    
       # Translate point 2 so that point 1 is at the origin
       x3,y3 = x1-shift, y1
       x3 -= x1
       y3 -= y1
    
       # Rotate point 2 about the origin
       left_x = x3 * cos_angle - y3 * sin_angle
       left_y = x3 * sin_angle + y3 * cos_angle
    
       # Translate point 2 back to its original position relative to point 1
       left_x += x1
       left_y += y1
    
       return (right_x, right_y, left_x, left_y)
    
    <!-- begin snippet: js hide: false console: true babel: false -->
    
    <!-- language: lang-html -->
    
        import math
    
        def rotate_point_about_point(x1, y1, shift, angle):
           # Convert angle to radians
           angle_rad = math.radians(angle)
    
           # Calculate sine and cosine of angle
           cos_angle = math.cos(angle_rad)
           sin_angle = math.sin(angle_rad)
    
           # Translate point 2 so that point 1 is at the origin
           x2,y2 = x1+shift, y1
           x2 -= x1
           y2 -= y1
    
           # Rotate point 2 about the origin
           right_x = x2 * cos_angle - y2 * sin_angle
           right_y = x2 * sin_angle + y2 * cos_angle
    
           # Translate point 2 back to its original position relative to point 1
           right_x += x1
           right_y += y1
           # ---------
    
           # Translate point 2 so that point 1 is at the origin
           x3,y3 = x1-shift, y1
           x3 -= x1
           y3 -= y1
    
           # Rotate point 2 about the origin
           left_x = x3 * cos_angle - y3 * sin_angle
           left_y = x3 * sin_angle + y3 * cos_angle
    
           # Translate point 2 back to its original position relative to point 1
           left_x += x1
           left_y += y1
    
           return (right_x, right_y, left_x, left_y)
    
Tyler
  • 1