feat: flake perfect

This commit is contained in:
Krzysztof Rudnicki 2024-12-27 12:33:06 +01:00
parent df9da83336
commit 0a497f35a2

View File

@ -77,7 +77,8 @@ def intersect_sphere(ray_origin, ray_direction, sphere_center, sphere_radius):
def calculate_sphere_intersection(a, b, c, disc): def calculate_sphere_intersection(a, b, c, disc):
""" """
Calculate the intersection distance of a ray with a sphere using the quadratic formula. Calculate the
intersection distance of a ray with a sphere using the quadratic formula.
Parameters: Parameters:
a (float): Coefficient of t^2 in the quadratic equation. a (float): Coefficient of t^2 in the quadratic equation.
@ -86,8 +87,10 @@ def calculate_sphere_intersection(a, b, c, disc):
disc (float): Discriminant of the quadratic equation. disc (float): Discriminant of the quadratic equation.
Returns: Returns:
float: The distance from the origin to the intersection point with the sphere. float:
Returns +inf if there is no intersection or if the intersection is behind the origin. The distance from the origin to the intersection point with the sphere.
Returns +inf if there is no intersection
or if the intersection is behind the origin.
""" """
if disc > 0: if disc > 0:
distance_squared = np.sqrt(disc) distance_squared = np.sqrt(disc)
@ -358,7 +361,7 @@ SPECULAR_K = 50
DEPTH_MAX = 5 # Maximum number of light reflections. DEPTH_MAX = 5 # Maximum number of light reflections.
col = np.zeros(3) # Current color. col = np.zeros(3) # Current color.
O = np.array([0., 0.35, -1.]) # Camera. camera_origin = np.array([0., 0.35, -1.]) # Camera.
Q = np.array([0., 0., 0.]) # Camera pointing to. Q = np.array([0., 0., 0.]) # Camera pointing to.
img = np.zeros((IMAGE_HEIGHT, IMAGE_WIDTH, 3)) img = np.zeros((IMAGE_HEIGHT, IMAGE_WIDTH, 3))
@ -373,9 +376,9 @@ for i, x in enumerate(np.linspace(S[0], S[2], IMAGE_WIDTH)):
for j, y in enumerate(np.linspace(S[1], S[3], IMAGE_HEIGHT)): for j, y in enumerate(np.linspace(S[1], S[3], IMAGE_HEIGHT)):
col[:] = 0 col[:] = 0
Q[:2] = (x, y) Q[:2] = (x, y)
D = normalize(Q - O) D = normalize(Q - camera_origin)
DEPTH = 0 DEPTH = 0
rayO, rayD = O, D rayO, rayD = camera_origin, D
REFLECTION = 1. REFLECTION = 1.
# Loop through initial and secondary rays. # Loop through initial and secondary rays.
while DEPTH < DEPTH_MAX: while DEPTH < DEPTH_MAX: