diff --git a/rainbow.py b/rainbow.py index fa076a2..9498566 100644 --- a/rainbow.py +++ b/rainbow.py @@ -69,14 +69,43 @@ def trace(disk:Disk, stack:list, max_ray:int): result.append([np.arccos(direction[1]), ray.intensity*direction[1]]) print("ray trace finish, total ray count:",ray_count) -init() -# stack.append(Ray([0.8, 2*r], [0,-1], 1)) -trace(disk, stack, max_ray) +def water_density(t): + data_t = np.linspace(0,101,102) + data_rho = np.array([999.79,999.84,999.88,999.92,999.97,999.92,999.88,999.84,999.79,999.72,999.65,999.55,999.44,999.32,999.19,999.05,998.90,998.74,998.56,998.36,998.16,997.96,997.74,997.50,997.25,996.99,996.74,996.48,996.20,995.90,995.59,995.29,995.97,994.65,994.33,994.98,993.64,993.28,992.93,992.55,992.17,991.78,991.39,990.99,990.57,990.16,989.75,989.33,988.90,988.45,988.04,987.55,987.06,986.58,986.19,985.70,985.22,984.73,984.67,983.18,983.13,982.70,982.22,981.64,981.06,980.48,979.91,979.33,978.85,978.28,977.70,977.13,976.56,975.99,975.41,974.84,974.27,973.70,973.14,972.47,971.81,971.25,970.59,969.93,969.27,968.61,967.96,967.30,966.65,965.99,965.34,964.69,964.04,963.39,962.64,961.90,961.26,960.52,959.78,959.04,958.40,957.67]) + return np.interp(t, data_t, data_rho) -with open("result.csv", 'w', newline='') as f: - writer = csv.writer(f) - writer.writerows(result) +def water_refraction_index(t, wavelength): + rhobar = 0.999974950 * (1 - (t - 3.983035)*(t - 3.983035)*(t + 301.797)/(522528.9*(t+69.34881))) + print(rhobar) + a0 = 0.244257733 + a1 = 0.00974634476 + a2 = -0.00373234996 + a3 = 0.000268678472 + a4 = 0.0015892057 + a5 = 0.00245934259 + a6 = 0.90070492 + a7 = -0.0166626219 + Tstar = 273.15 + Tbar = 1 + t/Tstar + lambdastar = 589 + lambdabar = wavelength/lambdastar + lambda_IR = 5.432937 + lambda_UV = 0.229202 + C = a0 + a1*rhobar + a2*Tbar + a3*lambdabar*lambdabar*Tbar + a4/(lambdabar*lambdabar) + a5/((lambdabar+lambda_UV)*(lambdabar-lambda_UV)) + a6/((lambdabar + lambda_IR)*(lambdabar - lambda_IR)) + a7*rhobar*rhobar + C *= rhobar + n = np.sqrt((2*C+1)/(1-C)) + return n -with open("points.csv", 'w', newline='') as f: - writer = csv.writer(f) - writer.writerows(points) +# init() +# # stack.append(Ray([0.8, 2*r], [0,-1], 1)) +# trace(disk, stack, max_ray) + +# with open("result.csv", 'w', newline='') as f: +# writer = csv.writer(f) +# writer.writerows(result) + +# with open("points.csv", 'w', newline='') as f: +# writer = csv.writer(f) +# writer.writerows(points) + +print(water_refraction_index(10, 226.5))