def blend2(): m1 = np.eye(4) * 1 m1[0:3, 3] = [0, 1, 0] m1[3, 3] = 1 m2 = np.eye(4) * 2 m2[0:3, 3] = [2.5, 0, 0] m2[3, 3] = 1 iobj_v = vector3.SimpleBlend(vector3.Ellipsoid(m1), vector3.Ellipsoid(m2)) return iobj_v
def blend_example1(scale_ignored): m1 = np.eye(4) * 1 # m1[1,1] = 0.4 m1[0:3, 3] = [0, 1, 0] m1[3, 3] = 1 m2 = np.eye(4) * 2 m2[0:3, 3] = [2.5, 0, 0] m2[3, 3] = 1 iobj = vector3.SimpleBlend(vector3.Ellipsoid(m1), vector3.Ellipsoid(m2)) return iobj
def blend_example2_discs(scale): m1 = np.eye(4) * 1.3 * scale m1[1, 1] = 0.4 * scale m1[1, 2] = 0.4 * scale m1[0:3, 3] = [0, 1 * scale, 0] m1[3, 3] = 1 m2 = np.eye(4) * 2 * scale m2[0:3, 3] = [2 * scale, 0, 0] m2[2, 2] = 0.4 * scale m2[3, 3] = 1 iobj = vector3.SimpleBlend(vector3.Ellipsoid(m1), vector3.Ellipsoid(m2)) return iobj
def blend_example2(scale=1.): # not tested for scale != 1. m1 = np.eye(4) * 1.3 * scale m1[1, 1] = 0.4 * scale m1[1, 2] = 0.4 * scale m1[0:3, 3] = [0, 1 * scale, 0] m1[3, 3] = 1 m2 = np.eye(4) * 2 m2[0:3, 3] = [2 * scale, 0, 0] m2[2, 2] = 0.4 * scale m2[3, 3] = 1 a, b = vector3.Ellipsoid(m1), vector3.Ellipsoid(m2) iobj = vector3.SimpleBlend(a, b) return iobj
def first_csg(scale): m1 = np.eye(4) * 2 * scale m1[1, 1] = 0.4 * scale m1[0:3, 3] = [0, 0, 0] m1[3, 3] = 1 m2 = np.eye(4) * 1. * scale rcenter = np.array([0.5, 0, 0]) * scale m2[0:3, 3] = rcenter[0:3] m2[3, 3] = 1 m3 = np.eye(4) * 1.2 * scale m3[0:3, 3] = [1.5 * scale, 0, 0] m3[3, 3] = 1 iobj = vector3.CrispSubtract(vector3.CrispUnion(vector3.Ellipsoid(m1), vector3.Ellipsoid(m2)), vector3.Ellipsoid(m3)) return iobj
def hole_crisp(c, i, j, k): m = np.eye(4) dot_size = 0.25 * dice_scale m[0, 0] = dot_size m[1, 1] = dot_size m[2, 2] = dot_size distance = (0.5-0.05)*dice_size m[0:3, 3] = np.array([distance*i, distance*j, distance*k]) s1 = vector3.Ellipsoid(m) c = vector3.CrispSubtract(c, s1) return c
def ell_example1(scale): scale = 1.0 m1 = np.eye(4) * 1.3 * scale m1[1, 1] = 0.4 * scale m1[1, 2] = 0.4 * scale m1[0:3, 3] = [0, 1 * scale, 0] m1[3, 3] = 1 iobj = vector3.Ellipsoid(m1) # (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.2) return iobj
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)
def bowl_15_holes(scale_ignored): big_radius = 3 big_radius2 = 2.7 # +0.3-0.001 small_radius = 0.6 """ Make a sphere """ m_big = np.eye(4) * big_radius m_big[0:3, 3] = [0, 0, 0] m_big[3, 3] = 1 iobj = vector3.Ellipsoid(m_big) """ Cut a sphere out pf it """ m_big2 = np.eye(4) * big_radius2 m_big2[0:3, 3] = [0, 0, 0] m_big2[3, 3] = 1 iobj = vector3.CrispSubtract(iobj, vector3.Ellipsoid(m_big2)) """ Cut the top part""" m_big3 = np.eye(4) * 10 m_big3[0:3, 3] = [0, 0, 10.2] m_big3[3, 3] = 1 iobj = vector3.CrispSubtract(iobj, vector3.Ellipsoid(m_big3)) """ Cut 15 small spheres from it """ for i in range(0, 15): m_small = np.eye(4) * small_radius if False: unsat = True while unsat: c = make_random_vector(big_radius, 1)[0:3] unsat = c[2] > 0 # th0 = (i/15.0)*(3.1415926536*2) # th = 5*th0 z0 = (i / 15.0) * big_radius # z0 = np.sqrt(1-(float(i)/15.0)**2) * big_radius # print(z0) # th = i * np.pi*2 * 5/ 4.45 # th = (np.pi*2) * float(i) * 4.0 / 5.0 # th = (np.pi*2) * float(i) * (1.0/5.0 * 1.0/2.0 * 1.0/5.0) * 5 NN = float(8) # th = (np.pi*2) * float(i) * (1.0/5.0 + 1.0/5.0 * 1.0/2.0 * 1.0/5.0) th = (np.pi * 2) * float(i) * (1.0 / NN + 1.0 / NN * 1.0 / NN / 2.0) c = make_vector4(np.cos(th) * big_radius, np.sin(th) * big_radius, -z0) c = normalize_vector(c) * big_radius c[3] = 1 # print( np.sqrt(np.dot(c,c)) ) m_small[0:3, 3] = c[0:3] m_small[3, 3] = 1 small_obj = vector3.Ellipsoid(m_small) iobj = vector3.CrispSubtract(iobj, small_obj) # iobj = CrispUnion( iobj, small_obj ) # ga = iobj.implicitGradient(xa) # va = iobj.implicitFunction(xa) # print(va) # print(ga) return iobj