예제 #1
0
 def rotateAroundCenter(self, axis_direction, angle):
     """Rotates the object by the given |angle| around an axis
     that passes through its center of mass and has the given
     |direction|."""
     cm = self.centerOfMass()
     t = Transformation.Translation(cm) * \
         Transformation.Rotation(axis_direction, angle) * \
         Transformation.Translation(-cm)
     self.applyTransformation(t)
 def __init__(self, attr, rotation, translation, reference_point):
     VRMLObject.__init__(self, attr)
     if rotation is None:
         rotation = Transformation.Rotation(ez, 0.)
     else:
         rotation = apply(Transformation.Rotation, rotation)
     if translation is None:
         translation = Transformation.Translation(Vector(0., 0., 0.))
     else:
         translation = Transformation.Translation(translation)
     self.transformation = translation * rotation
     self.reference_point = reference_point
예제 #3
0
 def findTransformation(self, conf1, conf2=None):
     """Returns the linear transformation that, when applied to
     the object in configuration |conf1|, minimizes the RMS distance
     to the conformation in |conf2|, and the minimal RMS distance.
     If |conf2| is 'None', returns the transformation from the
     current configuration to |conf1| and the associated RMS distance.
     The algorithm is described in [Article:Kneller1990]."""
     q, cm1, cm2, rms = self.findTransformationAsQuaternion(conf1, conf2)
     return Transformation.Translation(cm2) * \
            q.asRotation() * \
            Transformation.Translation(-cm1), \
            rms
예제 #4
0
    def rotateAroundCenter(self, axis_direction, angle):
        """
        Rotate the object around an axis that passes through its center
        of mass.

        :param axis_direction: the direction of the axis of rotation
        :type axis_direction: Scientific.Geometry.Vector
        :param angle: the rotation angle (in radians)
        :type angle: float
        """
        cm = self.centerOfMass()
        t = Transformation.Translation(cm) * \
            Transformation.Rotation(axis_direction, angle) * \
            Transformation.Translation(-cm)
        self.applyTransformation(t)
예제 #5
0
 def rotateAroundAxis(self, point1, point2, angle):
     """Rotates the object by the given |angle| around the axis
     that passes through |point1| and |point2|"""
     tr1 = Transformation.Translation(-point1)
     tr2 = Transformation.Rotation(point2 - point1, angle)
     tr3 = tr1.inverse()
     self.applyTransformation(tr3 * tr2 * tr1)
예제 #6
0
    def normalizingTransformation(self, repr=None):
        """Returns a linear transformation that shifts the center of mass
        of the object to the coordinate origin and makes its
        principal axes of inertia parallel to the three coordinate
        axes.

        A specific representation can be chosen by setting |repr| to
          Ir    : x y z <--> b c a
          IIr   : x y z <--> c a b
          IIIr  : x y z <--> a b c
          Il    : x y z <--> c b a
          IIl   : x y z <--> a c b
          IIIl  : x y z <--> b a c
        """
        from Scientific.LA import determinant
        cm, inertia = self.centerAndMomentOfInertia()
        ev, diag = inertia.diagonalization()
        if determinant(diag.array) < 0:
            diag.array[0] = -diag.array[0]
        if repr != None:
            seq = Numeric.argsort(ev)
            if repr == 'Ir':
                seq = Numeric.array([seq[1], seq[2], seq[0]])
            elif repr == 'IIr':
                seq = Numeric.array([seq[2], seq[0], seq[1]])
            elif repr == 'Il':
                seq = Numeric.seq[2::-1]
            elif repr == 'IIl':
                seq[1:3] = Numeric.array([seq[2], seq[1]])
            elif repr == 'IIIl':
                seq[0:2] = Numeric.array([seq[1], seq[0]])
            elif repr != 'IIIr':
                print 'unknown representation'
            diag.array = Numeric.take(diag.array, seq)
        return Transformation.Rotation(diag) * Transformation.Translation(-cm)
예제 #7
0
 def findTransformation(self, conf1, conf2=None):
     """
     :param conf1: a configuration object
     :type conf1: :class:~MMTK.ParticleProperties.Configuration
     :param conf2: a configuration object, or None for the
                   current configuration
     :type conf2: :class:~MMTK.ParticleProperties.Configuration or NoneType
     :returns: the linear transformation that, when applied to
               the object in configuration conf1, minimizes the
               RMS distance to the conformation in conf2, and the
               minimal RMS distance.
               If conf2 is None, returns the transformation from the
               current configuration to conf1 and the associated
               RMS distance.
     """
     q, cm1, cm2, rms = self.findTransformationAsQuaternion(conf1, conf2)
     return Transformation.Translation(cm2) * \
            q.asRotation() * \
            Transformation.Translation(-cm1), \
            rms
예제 #8
0
    def rotateAroundAxis(self, point1, point2, angle):
        """
        Rotate the object arond an axis specified by two points

        :param point1: the first point
        :type point1: Scientific.Geometry.Vector
        :param point2: the second point
        :type point2: Scientific.Geometry.Vector
        :param angle: the rotation angle (in radians)
        :type angle: float
        """
        tr1 = Transformation.Translation(-point1)
        tr2 = Transformation.Rotation(point2 - point1, angle)
        tr3 = tr1.inverse()
        self.applyTransformation(tr3 * tr2 * tr1)
예제 #9
0
    def normalizingTransformation(self, repr=None):
        """
        Calculate a linear transformation that shifts the center of mass
        of the object to the coordinate origin and makes its
        principal axes of inertia parallel to the three coordinate
        axes.

        :param repr: the specific representation for axis alignment:
          Ir    : x y z <--> b c a
          IIr   : x y z <--> c a b
          IIIr  : x y z <--> a b c
          Il    : x y z <--> c b a
          IIl   : x y z <--> a c b
          IIIl  : x y z <--> b a c
        :returns: the normalizing transformation
        :rtype: Scientific.Geometry.Transformation.RigidBodyTransformation
        """
        from Scientific.LA import determinant
        cm, inertia = self.centerAndMomentOfInertia()
        ev, diag = inertia.diagonalization()
        if determinant(diag.array) < 0:
            diag.array[0] = -diag.array[0]
        if repr != None:
            seq = N.argsort(ev)
            if repr == 'Ir':
                seq = N.array([seq[1], seq[2], seq[0]])
            elif repr == 'IIr':
                seq = N.array([seq[2], seq[0], seq[1]])
            elif repr == 'Il':
                seq = N.seq[2::-1]
            elif repr == 'IIl':
                seq[1:3] = N.array([seq[2], seq[1]])
            elif repr == 'IIIl':
                seq[0:2] = N.array([seq[1], seq[0]])
            elif repr != 'IIIr':
                print 'unknown representation'
            diag.array = N.take(diag.array, seq)
        return Transformation.Rotation(diag) * Transformation.Translation(-cm)