fix bugs, first working version
This commit is contained in:
15
rainbow.py
15
rainbow.py
@@ -12,9 +12,10 @@ center = [0,0]
|
||||
r = 1
|
||||
n = 1.3
|
||||
disk = Disk(center, r, n)
|
||||
dx = 0.01
|
||||
dx = 0.005
|
||||
N = int(2*r /dx - 1)
|
||||
min_intensity = 0.001
|
||||
max_ray = 10000
|
||||
|
||||
stack = []
|
||||
result = []
|
||||
@@ -46,9 +47,11 @@ def reflection_and_refraction(ray:Ray, intersection_point, normal, n):
|
||||
ray2 = Ray(intersection_point, k2n*normal+k2p, ray.intensity*(1-R))
|
||||
return ray1,ray2
|
||||
|
||||
def trace(disk:Disk, stack:list):
|
||||
while stack:
|
||||
def trace(disk:Disk, stack:list, max_ray:int):
|
||||
ray_count = 0
|
||||
while stack and ray_count < max_ray:
|
||||
ray = stack.pop()
|
||||
ray_count += 1
|
||||
if ray is None:
|
||||
continue
|
||||
if isinstance(ray, Ray):
|
||||
@@ -65,9 +68,9 @@ def trace(disk:Disk, stack:list):
|
||||
if direction[1] > 0:
|
||||
result.append([np.arccos(direction[1]), ray.intensity*direction[1]])
|
||||
|
||||
# init()
|
||||
stack.append(Ray([0.8, 2*r], [0,-1], 1))
|
||||
trace(disk, stack)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user