I hate to rely on ChatGPT for some of this code, but this stuff is just too cool & in this case makes it easy.
I ran into some issues with changing the pitch to bigger numbers, but if I made the pitch too large, it would not work. Early on in this development, I had wanted to make a true offset of the female threads from the male threads, but with the pitch distance it usually would not work. I decided to unbind that pitch from the helix & made a separate pitch for each. Problem solved, but not quite. How do I calculate those vertex points of the offset lines. I did thread profiles from 15 degrees to 65 degrees to see if I could see a correlation, I could use to get the angle to use with right triangles thinking I could use right triangles to find those points. There does not seem to be a correlation that I can see, so I decided to try ChatGPT to see what it came up with & it was almost perfect. I only had to change the offset distance from positive to negative. Here is an image of the test threads at 20 degrees. The green lines are what I am looking for. I gave it the coordinate points from this 2d drawing, so I could easily test that it works.
In python code, given the points P1 = (0,-.75), P2 = (1.7172,-.125) & P3 = (1.7172,.125) offset 0.2 in the positive direction these 2 lines together and compute the vertex point of the offset line. The vertex point should be X = 1.9172 and Y = -0.2650
import numpy as np
def offset_point(px, py, ox, oy, distance):
"""Offset a point (px, py) in the direction (ox, oy) by a specified distance."""
norm = np.sqrt(ox**2 + oy**2)
return (px + distance * ox / norm, py + distance * oy / norm)
def line_intersection(l1, l2):
"""Find the intersection of two lines given by points l1 and l2."""
xdiff = (l1[0][0] - l1[1][0], l2[0][0] - l2[1][0])
ydiff = (l1[0][1] - l1[1][1], l2[0][1] - l2[1][1])
def det(a, b):
return a[0] * b[1] - a[1] * b[0]
div = det(xdiff, ydiff)
if div == 0:
raise Exception('Lines do not intersect')
d = (det(*l1), det(*l2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
return x, y
# Points P1, P2, P3
P1 = (0, -0.75)
P2 = (1.7172, -0.125)
P3 = (1.7172, 0.125)
# Offset distance
offset_distance = 0.2
# Offsetting direction is perpendicular to the line segment direction
def perpendicular_vector(px, py):
return -py, px
# Offset points for each line
offset_P1 = offset_point(*P1, *perpendicular_vector(P2[0] - P1[0], P2[1] - P1[1]), offset_distance)
offset_P2_1 = offset_point(*P2, *perpendicular_vector(P2[0] - P1[0], P2[1] - P1[1]), offset_distance)
offset_P2_2 = offset_point(*P2, *perpendicular_vector(P3[0] - P2[0], P3[1] - P2[1]), offset_distance)
offset_P3 = offset_point(*P3, *perpendicular_vector(P3[0] - P2[0], P3[1] - P2[1]), offset_distance)
# Find intersection of the two offset lines
vertex_point = line_intersection((offset_P1, offset_P2_1), (offset_P2_2, offset_P3))
print("The vertex point of the offset lines is:", vertex_point)