preview

Research Paper On Import Numpy

Decent Essays

import numpy import matplotlib.pyplot as plt class Sphere: def __init__(self): z=1 def add(self, points, radius, color): return dict(type='sphere', points=numpy.array(points), radius=numpy.array(radius), color=numpy.array(color), reflection=.5) def intersect(self, e, s, pos, Rad): # Check for intersects A = numpy.dot(s, s) B = 2 * numpy.dot(s, (e - pos)) C = numpy.dot((e - pos), (e - pos)) - Rad * Rad delta = B * B - 4 * A * C if delta > 0: t1 = (-B - numpy.sqrt(delta)) / (2.0 * A) t2 = (-B + numpy.sqrt(delta)) / (2.0 * A) t1, t2 = min(t1, t2), max(t1, t2) if t2 >= 0: return …show more content…

obj = scene[idx] p = rayO + rayD * t n = getNormal(obj, p) k = getColor(obj, p) normal_l = (l-p) / numpy.linalg.norm(l - p) v = (e-p) / numpy.linalg.norm(e - p) # shadowed or not. hit = [] for j in range(len(scene)): obj_sh = scene[j] if j!= idx: result = intersect(p + n * .0001, normal_l, obj_sh) hit.append(result) #print(hit) if hit and min(hit) < numpy.inf: return # La. color1= La # Calculating Ld. color1 += obj.get('diffuse_c', Ld) * max(numpy.dot(n, normal_l), 0) * k # Calculating Ls. h = (normal_l + v) / numpy.linalg.norm(normal_l + v) color1 += obj.get('specular_c', Ls) * max(numpy.dot(n, h), 0) ** k * light_color return obj, p, n, color1 s = Sphere() p = Plane() # List of objects on scene. scene = [s.add([.75, .1, 1.], .6, [0., 0., 1.]), s.add([-.75, .1, 2.25], .7, [.5, .223, .5]), p.add([0., -.5, 0.], [0., 1., 0.], [.5, .223, .5]), ] l = numpy.array([5., 5., -10.]) light_color = numpy.zeros(3) La = .05 Ld = 1. Ls = 1. k = 50 nrows = 400 ncols = 300 Maxdepth = 2 # Max number of light reflections. col = numpy.zeros(3) e = numpy.array([0., 0.35,

Get Access