def getAveragePolygonConditions(digits, eps): pT.containsPoint_eps = eps pT.convexRun_eps = eps repeats = 0 result = 0 while (repeats < 10000): n = 0 K = [] L = [] # error possible or is len(K) == 0 checked first? while len(K) * len(L) == 0 or not pT.isConvex(K) or not pT.isConvex( L) or not pT.isConvexRun(K) or not pT.isConvexRun(L): P = rP.getRandomNoncenteredPolarPolygon(math.floor(4)) Q = rP.getRandomNoncenteredPolarPolygon(math.floor(4)) K = rP.getCartesian(P) L = rP.getCartesian(Q) rP.roundVertices(K, digits) rP.roundVertices(L, digits) n += 1 result += n repeats += 1 if repeats % 1000 == 0: print(repeats) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') print(result / repeats)
def normalsTest(repeats, verticesNumber, test_eps): for i in range(repeats): P = rP.getRandomPolygon(verticesNumber) coneVol = cV.getConeVol(P) diff = math.fabs(getSumOuterNormal(P) - verticesNumber) if diff > test_eps: #print( P ) #print( diff ) normalNormsPrint(coneVol) print(' normalsTest failed at') print(len(coneVol)) print(len(P)) pT.plotPoly(P, 'r') break
def compareResults(P, alternativeParams): cD = cV.getConeVol(P) alternatePoint = cV.gamma(cD, alternativeParams) P_alternative = polygonReconstruct(cD, alternatePoint) cD_alternative = cV.getConeVol(P_alternative) pT.plotPoly(P, 'b') pT.plotPoly(P_alternative, 'r') print(len(P_alternative)) print('difference in coneVolume matrices') print(M.distMatrix(M.Matrix(cD), M.Matrix(cD_alternative))) print(' sigma value of alternative params') print(cV.sigma(alternativeParams, cD))
def logMinRationalAutoTest(repeats, digits, eps_logMinRational): n = 0 logMinTrue = 0 logMinFalse = 0 logMinTriangleFalse = 0 centeredFails = 0 while n < repeats: K = rRP.getRandomRoundedPolygon(5, digits) L = rRP.getRandomRoundedPolygon(6, digits) R = rRP.getRationalWithDigits(K, digits) S = rRP.getRationalWithDigits(L, digits) info_R = rP.getCenterAndVolumeRational(R) info_S = rP.getCenterAndVolumeRational(S) rP.translateRational(R, info_R[0]) rP.translateRational(S, info_S[0]) info_R = rP.getCenterAndVolumeRational(R) info_S = rP.getCenterAndVolumeRational(S) logMinValues = logMinTestRationalPreparation(R, S) while (True): try: if not logMinTestRational2( logMinValues, eps_logMinRational) and not logMinTestRational1( logMinValues, eps_logMinRational ) and not logMinTestRationalNormalizing( logMinValues, eps_logMinRational): #centeredNorm = info_R[0][0] * info_R[0][0] + info_R[0][1] * info_R[0][1] + info_S[0][0] * info_S[0][0] + info_S[0][1] * info_S[0][1] #print( centeredNorm ) if len(R) == 3 or len(S) == 3: #print( 'das darf nicht sein') rP.printRationalPolygon(R) rP.printRationalPolygon(S) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') logMinTriangleFalse += 1 break else: print('logMin Gegenbeispiel') rP.printRationalPolygon(R) rP.printRationalPolygon(S) pT.plotPoly(R, 'r') pT.plotPoly(S, 'g') logMinFalse += 1 else: logMinTrue += 1 n = n + 1 break except OverflowError or ZeroDivisionError: break print('done') print([logMinTrue, logMinFalse, centeredFails, logMinTriangleFalse])
def logMinRoundAutoTest(repeats, roundMethod, digits, bringInPosition, getPosition, eps_position, eps_volume, eps_normals, eps_logMin): n = 0 logMinTrue = 0 logMinFalse = 0 logMinTriangleFalse = 0 while n < repeats: P = rP.getRandomNoncenteredPolarPolygon( math.floor(10 * random.random()) + 4) Q = rP.getRandomNoncenteredPolarPolygon( math.floor(10 * random.random()) + 4) K = rP.getCartesian(P) L = rP.getCartesian(Q) roundMethod(K, digits) roundMethod(L, digits) #because of roundig, convexity can be lost and support function can get negativ # because of rounding, two edges can be the same. # and then norm vector will be [] or something ? Because a type error ouccurs while (True): try: if not logMinTest(K, L, bringInPosition, eps_logMin): if pT.isConvex(K) and pT.isConvex(L) and pT.isConvexRun( K) and pT.isConvexRun(L): if M.norm(getPosition(K)) + M.norm( getPosition(L)) < eps_position: if math.fabs(rP.getVolume(K) - 1) + math.fabs( rP.getVolume(L) - 1) < eps_volume: # which bound is sufficient for a stable logMin calculation? a bound of 0.00003 seems to be always fulfilled... if pT.getWorsteNormalsDirection( K) < eps_normals: if len(K) == 3 or len(L) == 3: print('das darf nicht sein') print(K) print(L) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') logMinTriangleFalse += 1 else: print('logMin Gegenbeispiel') print(K) print(L) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') logMinFalse += 1 else: logMinTrue += 1 break except TypeError: break n = n + 1 print('done') print([logMinTrue, logMinFalse, logMinTriangleFalse])
def logMinTest(orderedCartPolygon_1, orderedCartPolygon_2, bringInPosition, eps_prod): K = orderedCartPolygon_1 L = orderedCartPolygon_2 bringInPosition(K) bringInPosition(L) rP.makeUnitVolume(K) rP.makeUnitVolume(L) # not sure if makeUnitVolume destroys the centered property... it is clear that it needs it for the normalization of volume bringInPosition(K) bringInPosition(L) coneVol = cV.getConeVol(K) #print( coneVol ) prod = 1 for i in range(len(K)): # Reihenfolge der Normalenvektoren sollte jetzt egal sein u = [coneVol[i - 1][0], coneVol[i - 1][1]] h_1 = rP.supportFunctionCartesianCentered(L, u) h_2 = rP.supportFunctionCartesianCentered(K, u) quotient = h_1 / h_2 if quotient == 0: print('quotient von logMin war gleich 0...') print(u) print(L[i - 1]) print(K[i - 1]) #print( quotient) #print( K[ i - 1] ) #print( u ) if quotient >= 0: prod = prod * math.pow(quotient, coneVol[i - 1][2]) else: print(' quotient von logMin war negativ') print(u) print(coneVol[i - 1][2]) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') if prod + eps_prod >= 1: return True else: print(1 - prod) return False
def logMinAutoTest(repeats, bringInPosition, getPosition, eps_position, eps_volume, eps_normals, eps_logMin): n = 0 logMinTrue = 0 logMinFalse = 0 logMinTriangleFalse = 0 while n < repeats: P = rP.getRandomNoncenteredPolarPolygon(math.floor(3)) Q = rP.getRandomNoncenteredPolarPolygon(math.floor(4)) K = rP.getCartesian(P) L = rP.getCartesian(Q) if not logMinTest(K, L, bringInPosition, eps_logMin): if pT.isConvex(K) and pT.isConvex(L) and pT.isConvexRun( K) and pT.isConvexRun(L): if M.norm(getPosition(K)) + M.norm( getPosition(L)) < eps_position: if math.fabs(rP.getVolume(K) - 1) + math.fabs( rP.getVolume(L) - 1) < eps_volume: # which bound is sufficient for a stable logMin calculation? a bound of 0.00003 seems to be always fulfilled... if pT.getWorsteNormalsDirection(K) < eps_normals: if len(K) == 3 or len(L) == 3: print('das darf nicht sein') print(K) print(L) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') logMinTriangleFalse += 1 else: print('logMin Gegenbeispiel') print(K) print(L) pT.plotPoly(K, 'r') pT.plotPoly(L, 'g') logMinFalse += 1 else: logMinTrue += 1 n = n + 1 print('done') print([logMinTrue, logMinFalse, logMinTriangleFalse])
[-0.7554665420833026, -1.2359424238428496]] L_CubeFailD = [[0.5789479878788385, 2.5862453164905914], [0.24361326317280213, 2.086601346490969], [-0.536719358231424, -2.6111171677640317], [-0.4582006091393752, -2.9754640716418455]] #pT.plotPoly( L_2 , 'g') #pT.plotPoly( rP.getCartesian(P_2) , 'g') #pT.plotPoly( rP.getCartesian(Q_2) , 'g') #print( pT.isConvex( K_3 )) #print( pT.isConvexRun( K_3 )) #print( pT.isConvex( L_3 )) #print( pT.isConvexRun( L_3 )) #print( rP.getCenter(K_2)) #print( rP.getCenter(L_2)) #print( logMin.logMinTest( P_2 , Q_2 ) ) test_1 = K_2 test_2 = L_2 pT.plotPoly(K_44, 'r') pT.plotPoly(L_44, 'g') pT.plotPoly(K_78, 'r') pT.plotPoly(L_78, 'g') pT.plotPoly(K_68, 'r') pT.plotPoly(L_68, 'g') #testRun with 1000 repeats for logMin with triangle yielded: # [658, 0, 0] if both are centered # # [694, 0, 0] if both are barycentered