Exemplo n.º 1
0
        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 = vectorized.SimpleBlend(vectorized.Ellipsoid(m1), vectorized.Ellipsoid(m2))
            return iobj_v
Exemplo n.º 2
0
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 = vectorized.SimpleBlend(vectorized.Ellipsoid(m1), vectorized.Ellipsoid(m2))
    assert vectorized.SimpleBlend == simple_blend.SimpleBlend

    return iobj
Exemplo n.º 3
0
    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 = vectorized.Ellipsoid(m)
        msg = "vectorized.Ellipsoid(m): "+str(e)

        va = e.implicitFunction(xa)
        ga = e.implicitGradient(xa)
        check_vector4_vectorized(ga)
        N = xa.shape[0]
        check_scalar_vectorized(va, N)
        assert ga.ndim == 2
        assert ga.shape == (N, 4)
        assert correctGrad.shape == (N, 4)

        correctScalar = 0
        less_a = np.less(np.abs(va - correctScalar), TOLERANCE)
        #print(va - correctScalar)

        if not np.all(less_a):
            print("Some error:")
            print(xa)
            print(va)
            print(ga)
            print(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, 0:3], correctGrad[i, 0:3])
            self.assertTrue(are_parallel, "Incorrect gradient: not parallel "+msg)
            self.assertTrue( are_directed, "parallel but opposite directions "+msg)
Exemplo n.º 4
0
def first_csg(scale):
    # scale not tested
    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 = vectorized.CrispSubtract(vectorized.CrispUnion(vectorized.Ellipsoid(m1), vectorized.Ellipsoid(m2)), vectorized.Ellipsoid(m3))
    return iobj
Exemplo n.º 5
0
def blend_example1():
    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 = vectorized.SimpleBlend(vectorized.Ellipsoid(m1), vectorized.Ellipsoid(m2))

    # print(iobj.a)
    # print(iobj.b)

    # iobj = Ellipsoid(m1)

    # iobj = CrispUnion( Ellipsoid(m1), Ellipsoid(m2) )

    return iobj
Exemplo n.º 6
0
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 = vectorized.Ellipsoid(m1), vectorized.Ellipsoid(m2)
    iobj = vectorized.SimpleBlend(a, b)

    a, b = nonvec.Ellipsoid(m1), nonvec.Ellipsoid(m2)
    iobj_ = nonvec.SimpleBlend(a, b)

    return (iobj, iobj_)
Exemplo n.º 7
0
def ell_example1(scale):
    # scale not tested
    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 = vectorized.Ellipsoid(m1)
    iobj_ = nonvec.Ellipsoid(m1)

    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.2)

    return (iobj, iobj_)
Exemplo n.º 8
0
def rdice_(ns=nonvec, scale=1., rotated=True):
    # m = np.eye(4)
    # m[0:3, 3] = [0, 0, 0]
    # m[2, 2] = 0.8
    # m[1, 2] = -0.4
    d = dice(scale, ns=ns)

    MOON = True
    if MOON:
        # Accompanying moon for the dice! (satelite)
        m1 = np.eye(4) * .3
        m1[0:3, 3] = [1.1, 1.1, 0]
        m1[3, 3] = 1
        s = vectorized.Ellipsoid(m1)
        return ns.CrispUnion(d, s)

    return d
    iobj = ns.Transformed(d)
    iobj  \
        .move(-0.2 * scale, -0.2 * scale, 0) \
        .resize(0.9)
    iobj.rotate(20, along=make_vector4(1, 1, 1), units="deg")
    return iobj
Exemplo n.º 9
0
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 = vectorized.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 = vectorized.CrispSubtract(iobj, vectorized.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 = vectorized.CrispSubtract(iobj, vectorized.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 = vectorized.Ellipsoid(m_small)
        iobj = vectorized.CrispSubtract(iobj, small_obj)
        # iobj = CrispUnion( iobj, small_obj )

    xa = vectorized.repeat_vect4(10, make_vector4(1, 1, 1))
    ga = iobj.implicitGradient(xa)
    va = iobj.implicitFunction(xa)
    # print(va)
    # print(ga)
    return iobj