Heres what i was thinking: You'll also need the solve_eq from the previous work
from collections import namedtuple
def calculate_xy_path(_start, _end, _sag, density=None):
l_x = np.linspace(_start.x, _sag.x, density)
r_x = np.linspace(_sag.x, _end.x, density)
l_y = np.linspace(_start.y, _sag.y, density)
r_y = np.linspace(_sag.y, _end.y, density)
l_z = calculate_z_path(_start, _sag, density)[::-1]
r_z = calculate_z_path(_sag, _end, density)
return Path(x=l_x, y=l_y, z=l_z), Path(x=r_x, y=r_y, z=r_z)
def calculate_z_path(_start, _end, density):
distance = math.sqrt(((_start.x - _end.x)**2) + ((_start.y - _end.y)**2))
sag_value = abs(_start.z - _end.z)
bottom_value = min(_start.z, _end.z)
_path = np.linspace(0, distance, density)
c = solve_eq(sag_value, distance, max_decimals=3)
_z_path = ((c * np.cosh(_path/c))-c)
_z_path = np.clip(_z_path, 0, sag_value)
return _z_path + bottom_value
Point = namedtuple("Point", "x y z")
Path = namedtuple("Path", "x y z")
start_point = Point(x=300, y=300, z=50)
end_point = Point(x=400, y=400, z=50)
sag_point = Point(x=350, y=350, z=40)
left_path, right_path = calculate_xy_path(start_point, end_point, sag_point, 20)
full_path = Path(
x=np.concatenate((left_path.x, right_path.x)),
y=np.concatenate((left_path.y, right_path.y)),
z=np.concatenate((left_path.z, right_path.z))
)
Then to test plot
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d')
ax.plot(full_path.x, full_path.y, full_path.z)
for p in [start_point, sag_point, end_point]:
ax.scatter([p.x], [p.y], [p.z], c='r')