def implicitFunction(self, p): check_vector3_vectorized(p) N = p.shape[0] # print "self.lamda", self.lamda theta = p[:, 2] * self.lamda # print theta.shape # assert theta.shape == (N,) ca = np.cos(theta) sa = np.sin(theta) # print theta.shape, "theta" # print theta p2 = np.concatenate(( ca[:, np.newaxis] * p[:, 0, np.newaxis] - sa[:, np.newaxis] * p[:, 1, np.newaxis], sa[:, np.newaxis] * p[:, 0, np.newaxis] + ca[:, np.newaxis] * p[:, 1, np.newaxis], p[:, 2, np.newaxis], ), axis=1) v = self.base_object.implicitFunction(p2) check_scalar_vectorized(v) return v
def implicitFunction(self, p): check_vector3_vectorized(p) va = self.a.implicitFunction(p) vb = self.b.implicitFunction(p) c = 1.0 - np.greater(va, vb) v = va * c + vb * (1 - c) check_scalar_vectorized(v) return v
def implicitFunction(self, p): check_vector3_vectorized(p) p = np.concatenate((p, np.ones((p.shape[0], 1))), axis=1) tp = np.dot(self.invmatrix, np.transpose(p)) tp = np.transpose(tp) tp = tp[:, :3] v = self.base_object.implicitFunction(tp) check_scalar_vectorized(v) return v
def implicitFunction(self, pa): check_vector3_vectorized(pa) pa = np.concatenate((pa, np.ones((pa.shape[0], 1))), axis=1) tp = np.dot(self.invmatrix, np.transpose( pa)) # inefficient. todo: multiply from right => will be efficient tp = np.transpose(tp) tp = tp[:, :3] v = self.sphere.implicitFunction(tp) check_scalar_vectorized(v) return v
def implicitFunction(self, p): check_vector3_vectorized(p) va = self.a.implicitFunction(p) vb = self.b.implicitFunction(p) fa = self.afactor fb = self.bfactor v = -(1 - (fa*np.exp(va) + fb*np.exp(vb)) / (fa+fb)) check_scalar_vectorized(v) return v
def ellipsoid_point_and_gradient_vectorized(self, m, xa, correctGrad, center=None): """ Checks if the point x is on the surface, and if the gradient is correct.""" e = vector3.Ellipsoid(m) msg = "Ellipsoid(m): " + str(e) va = e.implicitFunction(xa) ga = e.implicitGradient(xa) check_vector3_vectorized(ga) N = xa.shape[0] check_scalar_vectorized(va, N) assert ga.ndim == 2 assert ga.shape == (N, 3) assert correctGrad.shape == (N, 3) correctScalar = 0 less_a = np.less(np.abs(va - correctScalar), TOLERANCE) if not np.all(less_a): sys.stderr.write("Some error:") sys.stderr.write(xa) sys.stderr.write(va) sys.stderr.write(ga) sys.stderr.write(e) self.assertTrue(np.all(less_a), ("Implicit Function's scalar value incorrect")) for i in range(ga.shape[0]): (are_parallel, are_directed) = vectors_parallel_and_direction( ga[i, :], correctGrad[i, :]) self.assertTrue(are_parallel, "Incorrect gradient: not parallel " + msg) self.assertTrue(are_directed, "parallel but opposite directions " + msg)