Exemple #1
0
    def __init__(self,
                 crv,
                 pnt=[0., 0., 0.],
                 vector=[1., 0., 0.],
                 theta=2. * math.pi):
        if not isinstance(crv, Crv.Crv):
            raise NURBSError, 'Parameter crv not derived from Crv class!'
        # Translate and rotate the curve into alignment with the z-axis
        T = translate(-numerix.asarray(pnt, numerix.Float))
        # Normalize vector
        vector = numerix.asarray(vector, numerix.Float)
        len = numerix.sqrt(numerix.add.reduce(vector * vector))
        if len == 0:
            raise ZeroDivisionError, "Can't normalize a zero-length vector"
        vector = vector / len
        if vector[0] == 0.:
            angx = 0.
        else:
            angx = math.atan2(vector[0], vector[2])
        RY = roty(-angx)
        vectmp = numerix.ones((4, ), numerix.Float)
        vectmp[0:3] = vector
        vectmp = numerix.dot(RY, vectmp)
        if vectmp[1] == 0.:
            angy = 0.
        else:
            angy = math.atan2(vector[1], vector[2])
        RX = rotx(angy)
        crv.trans(numerix.dot(RX, numerix.dot(RY, T)))
        arc = Crv.Arc(1., [0., 0., 0.], 0., theta)

        narc = arc.cntrl.shape[1]
        ncrv = crv.cntrl.shape[1]
        coefs = numerix.zeros((4, narc, ncrv), numerix.Float)
        angle = numerix.arctan2(crv.cntrl[1, :], crv.cntrl[0, :])
        vectmp = crv.cntrl[0:2, :]
        radius = numerix.sqrt(numerix.add.reduce(vectmp * vectmp))

        for i in xrange(0, ncrv):
            coefs[:, :, i] = numerix.dot(
                rotz(angle[i]),
                numerix.dot(
                    translate((0., 0., crv.cntrl[2, i])),
                    numerix.dot(scale((radius[i], radius[i])), arc.cntrl)))
            coefs[3, :, i] = coefs[3, :, i] * crv.cntrl[3, i]
        Srf.__init__(self, coefs, arc.uknots, crv.uknots)
        T = translate(pnt)
        RX = rotx(-angy)
        RY = roty(angx)
        self.trans(numerix.dot(T, numerix.dot(RY, RX)))
Exemple #2
0
 def __init__(self, crv, vector):
     if not isinstance(crv, Crv.Crv):
         raise NURBSError, 'Parameter crv not derived from Crv class!'
     coefs = numerix.zeros((4, crv.cntrl.shape[1], 2), numerix.Float)
     coefs[:, :, 0] = crv.cntrl
     coefs[:, :, 1] = numerix.dot(translate(vector), crv.cntrl)
     Srf.__init__(self, coefs, crv.uknots, [0., 0., 1., 1.])
Exemple #3
0
 def __init__(self, crv, vector):
     if not isinstance(crv, Crv.Crv):
         raise NURBSError, 'Parameter crv not derived from Crv class!'
     coefs = np.zeros((4,crv.cntrl.shape[1],2), np.float)
     coefs[:,:,0] = crv.cntrl
     coefs[:,:,1] = np.dot(translate(vector), crv.cntrl)
     Srf.__init__(self, coefs, crv.uknots, [0., 0., 1., 1.])
Exemple #4
0
    def __init__(self, crv, pnt = [0., 0., 0.], vector = [1., 0., 0.], theta = 2.*math.pi):
        if not isinstance(crv, Crv.Crv):
            raise NURBSError, 'Parameter crv not derived from Crv class!'
        # Translate and rotate the curve into alignment with the z-axis
        T = translate(-np.asarray(pnt, np.float))
        # Normalize vector
        vector = np.asarray(vector, np.float)
        len = np.sqrt(np.add.reduce(vector*vector))
        if len == 0:
            raise ZeroDivisionError, "Can't normalize a zero-length vector"
        vector = vector/len
        if vector[0] == 0.:
            angx = 0.
        else:
            angx = math.atan2(vector[0], vector[2])
        RY = roty(-angx)
        vectmp = np.ones((4,), np.float)
        vectmp[0:3] = vector
        vectmp = np.dot(RY, vectmp)
        if vectmp[1] == 0.:
            angy = 0.
        else:
            angy = math.atan2(vector[1], vector[2])
        RX = rotx(angy)
        crv.trans(np.dot(RX, np.dot(RY, T)))
        arc = Crv.Arc(1., [0., 0., 0.], 0., theta)

        narc = arc.cntrl.shape[1]
        ncrv = crv.cntrl.shape[1]
        coefs = np.zeros((4, narc, ncrv), np.float)
        angle = np.arctan2(crv.cntrl[1,:], crv.cntrl[0,:])
        vectmp = crv.cntrl[0:2,:]
        radius = np.sqrt(np.add.reduce(vectmp*vectmp))

        for i in xrange(0, ncrv):
            coefs[:,:,i] = np.dot(rotz(angle[i]),
                                       np.dot(translate((0., 0., crv.cntrl[2,i])),
                                                   np.dot(scale((radius[i], radius[i])), arc.cntrl)))
            coefs[3,:,i] = coefs[3,:,i] * crv.cntrl[3,i]
        Srf.__init__(self, coefs, arc.uknots, crv.uknots)
        T = translate(pnt)
        RX = rotx(-angy)
        RY = roty(angx)
        self.trans(np.dot(T, np.dot(RY, RX)))
Exemple #5
0
    def __init__(self, radius=1., center=None, sang=0., eang=2 * math.pi):
        sweep = eang - sang  # sweep angle of arc
        if sweep < 0.:
            sweep = 2. * math.pi + sweep
        if abs(sweep) <= math.pi / 2.:
            narcs = 1  # number of arc segments
            knots = [0., 0., 0., 1., 1., 1.]
        elif abs(sweep) <= math.pi:
            narcs = 2
            knots = [0., 0., 0., 0.5, 0.5, 1., 1., 1.]
        elif abs(sweep) <= 3. * math.pi / 2.:
            narcs = 3
            knots = [
                0., 0., 0., 1. / 3., 1. / 3., 2. / 3., 2. / 3., 1., 1., 1.
            ]
        else:
            narcs = 4
            knots = [0., 0., 0., 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1., 1., 1.]

        dsweep = sweep / (2. * narcs)
        # arc segment sweep angle/2

        # determine middle control point and weight
        wm = math.cos(dsweep)
        x = radius * math.cos(dsweep)
        y = radius * math.sin(dsweep)
        xm = x + y * math.tan(dsweep)

        # arc segment control points
        ctrlpt = np.array(
            [[x, wm * xm, x], [-y, 0., y], [0., 0., 0.], [1., wm, 1.]],
            np.float)
        # build up complete arc from rotated segments
        coefs = np.zeros((4, 2 * narcs + 1),
                         np.float)  # nurb control points of arc
        # rotate to start angle
        coefs[:, 0:3] = np.dot(rotz(sang + dsweep), ctrlpt)
        xx = rotz(2 * dsweep)
        for ms in range(2, 2 * narcs, 2):
            coefs[:, ms:ms + 3] = np.dot(xx, coefs[:, ms - 2:ms + 1])
        if center:
            xx = translate(center)
            coefs = np.dot(xx, coefs)
        super(Arc, self).__init__(coefs, knots)
Exemple #6
0
    def __init__(self, radius = 1.,center = None, sang = 0., eang = 2*math.pi):
        sweep = eang - sang # sweep angle of arc
        if sweep < 0.:
            sweep = 2.*math.pi + sweep
        if abs(sweep) <= math.pi/2.:
            narcs = 1   # number of arc segments
            knots = [0., 0., 0., 1., 1., 1.]
        elif abs(sweep) <= math.pi:
            narcs = 2
            knots = [0., 0., 0., 0.5, 0.5, 1., 1., 1.]
        elif abs(sweep) <= 3.*math.pi/2.:
            narcs = 3
            knots = [0., 0., 0., 1./3., 1./3., 2./3., 2./3., 1., 1., 1.]
        else:
            narcs = 4
            knots = [0., 0., 0., 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1., 1., 1.]

        dsweep = sweep/(2.*narcs);     # arc segment sweep angle/2
        
        # determine middle control point and weight
        wm = math.cos(dsweep)
        x  = radius*math.cos(dsweep)
        y  = radius*math.sin(dsweep)
        xm = x+y*math.tan(dsweep)

        # arc segment control points
        ctrlpt = numerix.array([[x, wm*xm, x], [-y, 0., y], [0., 0., 0.], [1., wm, 1.]], numerix.Float)
        # build up complete arc from rotated segments
        coefs = numerix.zeros((4, 2*narcs+1), numerix.Float)   # nurb control points of arc
        # rotate to start angle
        coefs[:,0:3] = numerix.dot(rotz(sang + dsweep), ctrlpt)
        xx = rotz(2*dsweep)
        for ms in range(2, 2*narcs,2):
            coefs[:,ms:ms+3] = numerix.dot(xx, coefs[:,ms-2:ms+1])
        if center:
            xx = translate(center)
            coefs = numerix.dot(xx, coefs)
        Crv.__init__(self, coefs, knots)
Exemple #7
0
 def __init__(self, radius = .5, center = None):
     UnitCircle.__init__(self)
     if radius != 1.:
         self.trans(scale([radius, radius]))
     if center:
         self.trans(translate(center))
Exemple #8
0
 def __init__(self, radius = .5, center = None):
     super(Circle, self).__init__()
     if radius != 1.:
         self.trans(scale([radius, radius]))
     if center:
         self.trans(translate(center))
Exemple #9
0
 def __init__(self, radius=.5, center=None):
     super(Circle, self).__init__()
     if radius != 1.:
         self.trans(scale([radius, radius]))
     if center:
         self.trans(translate(center))
Exemple #10
0
 def __init__(self, radius=.5, center=None):
     UnitCircle.__init__(self)
     if radius != 1.:
         self.trans(scale([radius, radius]))
     if center:
         self.trans(translate(center))