def stratisfied(triangleJ, triangleI, areaI, samples=1, depth=1): """ Stratisfied_simple berekent de integraal van de vormfactoren. depth = het aantal keer dat de driehoek wordt opgedeeld in drie, het totaal aantal samples = samples*(3**depth) """ if depth == 0: return uniform_test2(triangleJ, triangleI, areaI, samples) else: centroidI, centroidJ = triangle_mesh.centroid( triangleI), triangle_mesh.centroid(triangleJ) I0, I1, I2 = np.array(triangleI), np.array(triangleI), np.array( triangleI) J0, J1, J2 = np.array(triangleJ), np.array(triangleJ), np.array( triangleJ) I0[0], I1[1], I2[2] = centroidI, centroidI, centroidI J0[0], J1[1], J2[2] = centroidJ, centroidJ, centroidJ return (stratisfied(J0, I0, areaI, samples, depth - 1) + stratisfied(J0, I1, areaI, samples, depth - 1) + stratisfied(J0, I2, areaI, samples, depth - 1) + stratisfied(J1, I0, areaI, samples, depth - 1) + stratisfied(J1, I1, areaI, samples, depth - 1) + stratisfied(J1, I2, areaI, samples, depth - 1) + stratisfied(J2, I0, areaI, samples, depth - 1) + stratisfied(J2, I1, areaI, samples, depth - 1) + stratisfied(J2, I2, areaI, samples, depth - 1)) / 3.0
def uniform_cheat(triangleJ, triangleI, areaI, kdtree, samples=6): """ Uniforme monte-carlo integratie van de vormfactor samples zijn standaard = 6 Hoeken en visibility worden maar 1 keer berekend Uit tests blijkt dit toch niet zo precies :( """ som = 0.0 dist_crit = math.sqrt(areaI/(3.2*samples)) p, q = triangle_mesh.centroid(triangleI), triangle_mesh.centroid(triangleJ) dist = triangle_mesh.distance(p,q) if dist <= dist_crit: return uniform(triangleJ, triangleI, kdtree, samples=6) angles = triangle_mesh.angle_second(triangleI, triangleJ, p, q) if not visibility.visible(kdtree, p,q): return 0.0 som += integrand(angles[0], angles[1], triangle_mesh.distance(p,q)) for k in range(samples-1): pointI = triangle_mesh.random_point2(triangleI) pointJ = triangle_mesh.random_point2(triangleJ) angles = triangle_mesh.angle_second(triangleI, triangleJ, pointI, pointJ) som += integrand(angles[0], angles[1], triangle_mesh.distance(pointI,pointJ)) samples = float(samples) formfactor = som/samples*areaI return formfactor
def cheat_integration(triangleJ, triangleI, areaI, kdtree): """ Voor als de driehoeken zeer klein zijn """ p, q = triangle_mesh.centroid(triangleI), triangle_mesh.centroid(triangleJ) angles = triangle_mesh.angle_second(triangleI, triangleJ, p, q) # start = time.time() visible = visibility.visible(kdtree, p, q) if visible: return areaI*integrand(angles[0], angles[1], triangle_mesh.distance(p, q)) return 0.0
def uniform_test2(triangleJ, triangleI, areaI, samples=4): """ Uniforme monte-carlo integratie van de vormfactor samples zijn standaard = 4 """ if int(areaI) > samples: samples = int(areaI) + 1 stopcrit = samples + 10 dist_crit = math.sqrt(areaI / (3.2 * samples)) centroidJ, centroidI = triangle_mesh.centroid( triangleJ), triangle_mesh.centroid(triangleI) angles = triangle_mesh.angle_second(triangleI, triangleJ, centroidI, centroidJ) centr_dist = triangle_mesh.distance(centroidJ, centroidI) som = 0.0 formfactor = 0.0 som += formfactors.integrand(angles[0], angles[1], centr_dist) counter = 1.0 while counter < samples and stopcrit != 0: # print("point ", k) # print(triangleI) pointI = triangle_mesh.random_point2(triangleI) pointJ = triangle_mesh.random_point2(triangleJ) dist = triangle_mesh.distance(pointI, pointJ) if dist > dist_crit: # print(pointI,pointJ) # visible = visibility.visible(kdtree, pointI, pointJ) # print(pointI,pointJ,visible) # print("visible:", visible) if True: # print("checked visibility") angles = triangle_mesh.angle_second(triangleI, triangleJ, pointI, pointJ) som += formfactors.integrand(angles[0], angles[1], dist) counter += 1.0 else: samples += 1 dist = centr_dist angles = triangle_mesh.angle_second(triangleI, triangleJ, pointI, pointJ) som += formfactors.integrand(angles[0], angles[1], dist) counter += 1.0 stopcrit -= 1 # print(som, samples, triangle_mesh.triangle_area_carth(triangleI)) formfactor = som / float(counter) * areaI return formfactor
def uniform(triangleJ, triangleI, areaI, kdtree, samples=4): """ Uniforme monte-carlo integratie van de vormfactor samples zijn standaard = 4 """ #print("calculating formfactor") centroidJ, centroidI = triangle_mesh.centroid(triangleJ), triangle_mesh.centroid(triangleI) if normal_opt(triangleJ,triangleI,centroidJ,centroidI): return 0.0 if int(areaI) > samples: samples = int(areaI) + 1 dist_crit = (areaI/(3.2*samples))**0.5 angles = triangle_mesh.angle_second(triangleI, triangleJ, centroidI, centroidJ) centr_dist = triangle_mesh.distance(centroidJ,centroidI) som = 0.0 formfactor = 0.0 if visibility.visible(kdtree, centroidI, centroidJ): som += integrand(angles[0], angles[1], centr_dist) else: return 0.0 counter = 1.0 while counter < samples: # print("point ", k) # print(triangleI) pointI = triangle_mesh.random_point2(triangleI) pointJ = triangle_mesh.random_point2(triangleJ) dist = triangle_mesh.distance(pointI,pointJ) if dist > dist_crit: # print(pointI,pointJ) # visible = visibility.visible(kdtree, pointI, pointJ) # print(pointI,pointJ,visible) # print("visible:", visible) # if visible: # print("checked visibility") angles = triangle_mesh.angle_second(triangleI, triangleJ, pointI, pointJ) som += integrand(angles[0], angles[1], dist) counter +=1.0 else: samples += 1 dist = centr_dist angles = triangle_mesh.angle_second(triangleI, triangleJ, pointI, pointJ) som += integrand(angles[0], angles[1], dist) counter +=1.0 # print(som, samples, triangle_mesh.triangle_area_carth(triangleI)) formfactor = som/float(counter)*areaI return formfactor
def uniform_cheat(triangleJ, triangleI, samples=6): """ Uniforme monte-carlo integratie van de vormfactor samples zijn standaard = 6 Hoeken en visibility worden maar 1 keer berekend """ som = 0.0 p, q = triangle_mesh.centroid(triangleI), triangle_mesh.centroid(triangleJ) angles = triangle_mesh.angle_second(triangleI, triangleJ, p, q) som += formfactors.integrand(angles[0], angles[1], triangle_mesh.distance(p, q)) for k in range(samples - 1): pointI = triangle_mesh.random_point(triangleI) pointJ = triangle_mesh.random_point(triangleJ) som += formfactors.integrand(angles[0], angles[1], triangle_mesh.distance(pointI, pointJ)) samples = float(samples) area = triangle_mesh.triangle_area_carth(triangleI) formfactor = som / samples * area return formfactor