def normal(self, p): """ Surface normal at point p, calculated through the gradient """ a, b, c = self.a, self.b, self.c n = Vec(-2 * p.x / a ** 2, -2 * p.y / b ** 2, -2 * (p.z + c) / c ** 2) return n.normalize()
def reflect(self,pos,t): if t is False or t is None or type(t) is list and (t[0] is False or t[0] is None): return pos if type(pos) is Vec and type(t[0]) is Vec: if type(t[1]) is str: if t[1]=='y': dirvec=V(0,1) if t[1]=='x': dirvec=V(1,0) elif type(t[1]) is Vec: dirvec = t[1] else: raise ValueError( "Reflection direction "+str(t[1])+" is not a string or vector") out=Vec(pos) out-=t[0] out=out.reflect(dirvec) out+=t[0] return out else: return False