Curvature radius along a Spline
DoDo3341 opened this issue · comments
Delta Design commented
Hey, I am working on a project where I want to calculate the curvature radius along dxf contours. With LINE and ARC this is obviously quite simple to achieve, however I am stuggling to achieve satisfactory results with SPLINE.
My approach was to find points along the spline:
for t in np.linspace(0, 1, round(len/minstep)):
point, derivative,derivative2 = ct.derivative(t, 2)
splinePt.append(point)
radii` = calculate_curvature_radii(splinePt)
and then use three consecutive points to approximate the radii alon the spine as described here
def circumradius(p1,p2,p3):
'''
Calculates the circumradius for three 2D points
'''
x1, x2, x3, y1, y2, y3 = p1.x, p2.x, p3.x, p1.y,p2.y,p3.y
den = 2*((x2-x1)*(y3-y2)-(y2-y1)*(x3-x2))
num = ( (((x2-x1)**2) + ((y2-y1)**2)) * (((x3-x2)**2)+((y3-y2)**2)) * (((x1-x3)**2)+((y1-y3)**2)) )**(0.5)
if ( den == 0 ):
print('Failed: points are either collinear or not distinct')
return 0
R = abs(num/den)
return R
the method does work in principle, but the values fluctuate a lot. Is there a more precise/simple way of achieving this?
Thanks in advance!