2nd day edit 2: Fixed precision inaccuracy, made as foolproof as possible, translated into EN
from math import sqrt def dylkaKrivkylengthOfCurve(bodypoints, H1, H2, tolerancetoleration): A = body[0]points[0] E = body[points[-1] if len(bodypoints) == 2: # prvniround koloone Ba = [(H1[0] - A[0])*0.25 + A[0], (H1[1] - A[1])*0.25 + A[1], (H1[2] - A[2])*0.25 + A[2]] Bb = [(E[0] - H2[0])*0.25 + H2[0], (E[1] - H2[1])*0.25 + H2[1], (E[2] - H2[2])*0.25 + H2[2]] B = [(Bb[0] - Ba[0])*0.25 + Ba[0], (Bb[1] - Ba[1])*0.25 + Ba[1], (Bb[2] - Ba[2])*0.25 + Ba[2]] Ca = [(H1[0] - A[0])*0.5 + A[0], (H1[1] - A[1])*0.5 + A[1], (H1[2] - A[2])*0.5 + A[2]] Cb = [(E[0] - H2[0])*0.5 + H2[0], (E[1] - H2[1])*0.5 + H2[1], (E[2] - H2[2])*0.5 + H2[2]] C = [(Cb[0] - Ca[0])*0.5 + Ca[0], (Cb[1] - Ca[1])*0.5 + Ca[1], (Cb[2] - Ca[2])*0.5 + Ca[2]] Da = [(H1[0] - A[0])*0.75 + A[0], (H1[1] - A[1])*0.75 + A[1], (H1[2] - A[2])*0.75 + A[2]] Db = [(E[0] - H2[0])*0.75 + H2[0], (E[1] - H2[1])*0.75 + H2[1], (E[2] - H2[2])*0.75 + H2[2]] D = [(Db[0] - Da[0])*0.75 + Da[0], (Db[1] - Da[1])*0.75 + Da[1], (Db[2] - Da[2])*0.75 + Da[2]] bodypoints = [A, B, C, D, E] dylkaPuvodnioriginalLength = velikostVektorulengthOfVector(A, E) dylkaNovanewLength = velikostVektorulengthOfVector(A, B) + velikostVektorulengthOfVector(B, C) + velikostVektorulengthOfVector(C, D) + velikostVektorulengthOfVector(D, E) if dylkaNovanewLength - tolerancetoleration < dylkaPuvodnioriginalLength: return(round(dylkaNovanewLength/tolerancetoleration)*tolerance*toleration) return(dylkaKrivkylengthOfCurve(bodypoints, H1, H2, tolerancetoleration)) else: # nasledujicifollowing kolarounds useceknumberOfSegments = len(bodypoints) - 1 body2points2 = [] i = useceknumberOfSegments while i > 0: t = 2*i - 1 bodApointA = [(H1[0] - A[0])*(t/(2*usecek2*numberOfSegments)) + A[0], (H1[1] - A[1])*(t/(2*usecek2*numberOfSegments)) + A[1], (H1[2] - A[2])*(t/(2*usecek2*numberOfSegments)) + A[2]] bodBpointB = [(E[0] - H2[0])*(t/(2*usecek2*numberOfSegments)) + H2[0], (E[1] - H2[1])*(t/(2*usecek2*numberOfSegments)) + H2[1], (E[2] - H2[2])*(t/(2*usecek2*numberOfSegments)) + H2[2]] bodpoint = [(bodB[0]pointB[0] - bodA[0]pointA[0])*(t/(2*usecek2*numberOfSegments)) + bodA[0]pointA[0], (bodB[1]pointB[1] - bodA[1]pointA[1])*(t/(2*usecek2*numberOfSegments)) + bodA[1]pointA[1], (bodB[2]pointB[2] - bodA[2]pointA[2])*(t/(2*usecek2*numberOfSegments)) + bodA[2]]pointA[2]] body2points2.insert(0, bodpoint) # predpojuju,i protozeam postupjuprepending odzadubecause I advance back first i -= 1 noveBodynewPoints = [] i = 0 while i < useceknumberOfSegments: # spojitjoin bodypoints aand body2points2 zipemusing zipper method noveBodynewPoints.append(body[i]points[i]) noveBodynewPoints.append(body2[i]points2[i]) i += 1 noveBodynewPoints.append(body[usecek]points[numberOfSegments]) dylkaNovanewLength = 0 i = useceknumberOfSegments while i > 0: dylkaNovanewLength += velikostVektorulengthOfVector(noveBody[2*i]newPoints[2*i], noveBody[2*inewPoints[2*i - 1]) dylkaNovanewLength += velikostVektorulengthOfVector(noveBody[2*inewPoints[2*i - 1], noveBody[2*inewPoints[2*i - 2]) i -= 1 dylkaPuvodnioriginalLength = 0 i = int(useceknumberOfSegments/2) while i > 0: dylkaPuvodnioriginalLength += velikostVektorulengthOfVector(body[2*i]points[2*i], body[2*ipoints[2*i - 1]) dylkaPuvodnioriginalLength += velikostVektorulengthOfVector(body[2*ipoints[2*i - 1], body[2*ipoints[2*i - 2]) i -= 1 if dylkaNovanewLength - tolerancetoleration < dylkaPuvodnioriginalLength: return(round(dylkaNovanewLength/tolerancetoleration)*tolerance*toleration) return(dylkaKrivkylengthOfCurve(noveBodynewPoints, H1, H2, tolerancetoleration)) def velikostVektorulengthOfVector(P, Q): return(sqrt((P[0] - Q[0])*(P[0] - Q[0]) + (P[1] - Q[1])*(P[1] - Q[1]) + (P[2] - Q[2])*(P[2] - Q[2]))) bod1point1 = [0, 0, 0] bod2point2 = [1, 0, 0] madlo1handle1 = [0, 1, 0] madlo2handle2 = [1, 1, 0] tolerancetoleration = 0.01 print("dylka krivky = ", dylkaKrivky([bod1, bod2], madlo1, madlo2, tolerance)) print("length of curve = ", lengthOfCurve([point1, point2], handle1, handle2, toleration)) def pomocnafindPoints(bodypoints, H1, H2, tolerancetoleration, lengthOfCurv): A = body[0]points[0] E = body[points[-1] if len(bodypoints) == 2: # prvniround koloone Ba = [(H1[0] - A[0])*0.25 + A[0], (H1[1] - A[1])*0.25 + A[1], (H1[2] - A[2])*0.25 + A[2]] Bb = [(E[0] - H2[0])*0.25 + H2[0], (E[1] - H2[1])*0.25 + H2[1], (E[2] - H2[2])*0.25 + H2[2]] B = [(Bb[0] - Ba[0])*0.25 + Ba[0], (Bb[1] - Ba[1])*0.25 + Ba[1], (Bb[2] - Ba[2])*0.25 + Ba[2]] Ca = [(H1[0] - A[0])*0.5 + A[0], (H1[1] - A[1])*0.5 + A[1], (H1[2] - A[2])*0.5 + A[2]] Cb = [(E[0] - H2[0])*0.5 + H2[0], (E[1] - H2[1])*0.5 + H2[1], (E[2] - H2[2])*0.5 + H2[2]] C = [(Cb[0] - Ca[0])*0.5 + Ca[0], (Cb[1] - Ca[1])*0.5 + Ca[1], (Cb[2] - Ca[2])*0.5 + Ca[2]] Da = [(H1[0] - A[0])*0.75 + A[0], (H1[1] - A[1])*0.75 + A[1], (H1[2] - A[2])*0.75 + A[2]] Db = [(E[0] - H2[0])*0.75 + H2[0], (E[1] - H2[1])*0.75 + H2[1], (E[2] - H2[2])*0.75 + H2[2]] D = [(Db[0] - Da[0])*0.75 + Da[0], (Db[1] - Da[1])*0.75 + Da[1], (Db[2] - Da[2])*0.75 + Da[2]] bodypoints = [A, B, C, D, E] dylkaPuvodnilongestSegment = velikostVektorulengthOfVector(A, EB) dylkaNovalenBC = velikostVektorulengthOfVector(AB, BC) + velikostVektoru(B, C) + velikostVektoru lenCD = lengthOfVector(C, D) + velikostVektoru lenDE = lengthOfVector(D, E) if dylkaNovalenBC -> tolerancelongestSegment: longestSegment = lenBC if lenCD > longestSegment: longestSegment = lenBC if lenDE > longestSegment: longestSegment = lenBC if longestSegment < dylkaPuvodnitoleration: return(bodypoints) return(pomocnafindPoints(bodypoints, H1, H2, tolerancetoleration, lengthOfCurv)) else: # nasledujicifollowing kolarounds useceknumberOfSegments = len(bodypoints) - 1 body2points2 = [] i = useceknumberOfSegments while i > 0: t = 2*i - 1 bodApointA = [(H1[0] - A[0])*(t/(2*usecek2*numberOfSegments)) + A[0], (H1[1] - A[1])*(t/(2*usecek2*numberOfSegments)) + A[1], (H1[2] - A[2])*(t/(2*usecek2*numberOfSegments)) + A[2]] bodBpointB = [(E[0] - H2[0])*(t/(2*usecek2*numberOfSegments)) + H2[0], (E[1] - H2[1])*(t/(2*usecek2*numberOfSegments)) + H2[1], (E[2] - H2[2])*(t/(2*usecek2*numberOfSegments)) + H2[2]] bodpoint = [(bodB[0]pointB[0] - bodA[0]pointA[0])*(t/(2*usecek2*numberOfSegments)) + bodA[0]pointA[0], (bodB[1]pointB[1] - bodA[1]pointA[1])*(t/(2*usecek2*numberOfSegments)) + bodA[1]pointA[1], (bodB[2]pointB[2] - bodA[2]pointA[2])*(t/(2*usecek2*numberOfSegments)) + bodA[2]]pointA[2]] body2points2.insert(0, bodpoint) # predpojuju,i protozeam postupjuprepending odzadubecause I advance back first i -= 1 noveBodynewPoints = [] i = 0 while i < useceknumberOfSegments: # spojitjoin bodypoints aand body2points2 zipemusing zipper method noveBodynewPoints.append(body[i]points[i]) noveBodynewPoints.append(body2[i]points2[i]) i += 1 noveBodynewPoints.append(body[usecek]points[numberOfSegments]) dylkaNovanewLength = 0 i = useceknumberOfSegments while i > 0: dylkaNovanewLength += velikostVektorulengthOfVector(noveBody[2*i]newPoints[2*i], noveBody[2*inewPoints[2*i - 1]) dylkaNovanewLength += velikostVektorulengthOfVector(noveBody[2*inewPoints[2*i - 1], noveBody[2*inewPoints[2*i - 2]) i -= 1 dylkaPuvodnioriginalLength = 0 i = int(useceknumberOfSegments/2) longestSegment = 0 while i > 0: dylkaPuvodnibyHowMuch +== velikostVektorulengthOfVector(body[2*i]points[2*i], body[2*ipoints[2*i - 1]) dylkaPuvodniif byHowMuch > longestSegment: longestSegment = byHowMuch originalLength += velikostVektorubyHowMuch byHowMuch = lengthOfVector(body[2*ipoints[2*i - 1], body[2*ipoints[2*i - 2]) if byHowMuch > longestSegment: longestSegment = byHowMuch originalLength += byHowMuch i -= 1 if#print(longestSegment) dylkaNova - tolerance if longestSegment < dylkaPuvodnitoleration: return(noveBodynewPoints) return(pomocnafindPoints(noveBodynewPoints, H1, H2, tolerancetoleration, lengthOfCurv)) def bodNaKrivcepointOnCurve(bod1point1, bod2point2, madlo1handle1, madlo2handle2, kdeplacement, tolerancetoleration, lengthOfCurv): dylkaCelkemaggregateLength = dylkaKrivkylengthOfCurve([bod1[point1, bod2]point2], madlo1handle1, madlo2handle2, tolerancetoleration) dylkaBodulengthOfUnfinishedCurve = dylkaCelkem*kdeaggregateLength*placement sekvencesequence = pomocnafindPoints([bod1[point1, bod2]point2], madlo1handle1, madlo2handle2, tolerancetoleration, lengthOfCurv) celkovaDylkaaggregateLength = 0 for i, s in enumerate(sekvencesequence): print("dylkaaggregateLength pred+= "lengthOfVector([sequence[i][0], celkovaDylka) sequence[i][1], sequence[i][2]], [sequence[i + 1][0], celkovaDylkasequence[i +=+ velikostVektoru(sekvence[i]1][1], sekvence[isequence[i + 1]1][2]]) if celkovaDylkaaggregateLength >= dylkaBodulengthOfUnfinishedCurve: printreturn("skutecna dylka[round(sequence[i ",+ celkovaDylka1][0]/toleration) *toleration, round(sequence[i + 1][1]/toleration)*toleration, returnround(sekvence[isequence[i + 1]1][2]/toleration)*toleration]) bod1point1 = [0, 0, 0] bod2point2 = [1, 0, 0] madlo1handle1 = [0, 1, 0] madlo2handle2 = [1, 1, 0] tolerancetoleration = 0.01 kdeplacement = 0.3 lengthOfCurv = lengthOfCurve([point1, point2], handle1, handle2, toleration) print("bod"point naon krivcecurve = ", bodNaKrivcepointOnCurve(bod1point1, bod2point2, madlo1handle1, madlo2handle2, kdeplacement, tolerancetoleration, lengthOfCurv))