コード例 #1
0
ファイル: Srf.py プロジェクト: uceearq/polymode-1
    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)))
コード例 #2
0
ファイル: Srf.py プロジェクト: mtezzele/PyNURBS
    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)))
コード例 #3
0
ファイル: Crv.py プロジェクト: Germanc/supreme
 def __init__(self, radius = .5, center = None):
     UnitCircle.__init__(self)
     if radius != 1.:
         self.trans(scale([radius, radius]))
     if center:
         self.trans(translate(center))
コード例 #4
0
ファイル: Crv.py プロジェクト: mtezzele/PyNURBS
 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))
コード例 #5
0
ファイル: Crv.py プロジェクト: mtezzele/PyNURBS
 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))
コード例 #6
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))