#!python import numpy as np import sys # Make up test cases with polygonal luminaires. # Step 1: generate a random triangle that lies in the +y half-space. # Make sure it faces the origin. v = np.transpose(np.random.rand(3,3) - [[0.5], [0], [0.5]]) normal = np.cross(v[1] - v[0], v[2] - v[0]) if (np.dot(normal, v[0]) > 0): v = np.flipud(v) # Step 2: compute the irradiance using Lambert's formula. # See Arvo's thesis, equations 3.1 to 3.3. def norm(x): return np.sqrt(np.dot(x,x)) Phi = 0 # vector irradiance for k0 in range(3): k1 = (k0 + 1) % 3 Theta = np.arccos(np.dot(v[k0], v[k1]) / (norm(v[k0]) * norm(v[k1]))) Gamma1 = np.cross(v[k0], v[k1]) Gamma = Gamma1 / norm(Gamma1) Phi += 1 / 4.0 * Theta * Gamma irradiance = -np.dot(Phi, [0,1,0]) # Step 3: write out a nori test scene, wrapped in a t-test xml_text = """ """ obj_text = """v %g %g %g v %g %g %g v %g %g %g f 1 2 3 """ if len(sys.argv) < 3: print "Usage: python polylum.py " sys.exit(-1) fname_obj = sys.argv[2] f_xml = open(sys.argv[1], 'w') f_xml.write(xml_text % (.5 / np.pi * irradiance, fname_obj)) f_xml.close() f_obj = open(fname_obj, 'w') f_obj.write(obj_text % tuple(v.flat)) f_obj.close()