def mouseReleaseEvent(self, event): button = event.button() self.setCursor(Qt.arrowCursor) if button == Qt.LeftButton: try: dx = event.x() - self.click1x dy = event.y() - self.click1y except AttributeError: return if dx != 0 or dy != 0: normal = Vector(self.axis) move = Vector(-dx*self.plane[:,0]+dy*self.plane[:,1]) axis = normal.cross(move) / \ N.minimum.reduce(N.fabs(self.plotbox_size)) rot = Rotation(axis.normal(), axis.length()) self.axis = rot(normal).array self.plane[:,0] = rot(Vector(self.plane[:,0])).array self.plane[:,1] = rot(Vector(self.plane[:,1])).array elif button == Qt.MidButton: try: dx = event.x() - self.click2x dy = event.y() - self.click2y except AttributeError: return if dx != 0 or dy != 0: self.translate = self.translate + N.array([dx, dy]) else: try: dy = event.y() - self.click3y except AttributeError: return if dy != 0: ratio = -dy/self.plotbox_size[1] self.scale = self.scale * (1.+ratio) self.update()
def randomRotation(max_angle=N.pi): """ :param max_angle: the upper limit for the rotation angle :type max_angle: float :returns: a random rotation with a uniform axis distribution and angles drawn from a uniform distribution between -max_angle and max_angle. :rtype: Scientific.Geometry.Transformations.Rotation """ return Rotation(randomDirection(), uniform(-max_angle, max_angle))
def cartesianCoordinateSymmetryTransformations(cell, space_group): """ :param cell: a unit cell :type cell: CDTK.Crystal.UnitCell or MMTK.Universe :param space_group: a space group :type space_group: CDTK.SpaceGroups.SpaceGroup :returns: a list of transformation objects representing the symmetry operations of the space group in the Cartesian coordinates of the unit cell :rtype: list of Scientific.Geometry.Transformation.Transformation """ transformations = [] to_fract = Shear(cell.cartesianToFractionalMatrix()) from_fract = Shear(cell.fractionalToCartesianMatrix()) for rot, trans_num, trans_den in space_group.transformations: trans = Vector((1. * trans_num) / trans_den) tr_fract = Translation(trans) * Rotation(rot) transformations.append(from_fract * tr_fract * to_fract) return transformations
def releasehandler1(self, event): self.configure(cursor='top_left_arrow') self.update_idletasks() try: dx = event.x - self.click1x dy = event.y - self.click1y except AttributeError: return if dx != 0 or dy != 0: normal = Vector(self.axis) move = Vector(-dx*self.plane[:,0]+dy*self.plane[:,1]) axis = normal.cross(move) / \ Numeric.minimum.reduce(Numeric.fabs(self.plotbox_size)) rot = Rotation(axis.normal(), axis.length()) self.axis = rot(normal).array self.plane[:,0] = rot(Vector(self.plane[:,0])).array self.plane[:,1] = rot(Vector(self.plane[:,1])).array self.clear(1) self.redraw()
def test_projections(self): universe = MMTK.InfiniteUniverse() universe.m1 = MMTK.Molecule('water', position=MMTK.Vector(0., 0., 0.)) universe.m2 = MMTK.Molecule('water', position=MMTK.Vector(1., 0., 0.)) rbs = [universe.m1, MMTK.Collection([universe.m2.H1, universe.m2.H2])] s = RigidMotionSubspace(universe, rbs) self.checkOrthonormality(s) self.assertEqual(len(s), 11) basis = s.getBasis() self.assertEqual(len(basis), 11) complement = s.complement() complement_basis = complement.getBasis() self.assertEqual(len(complement_basis), universe.degreesOfFreedom() - 11) for rb in rbs: for t in [ Translation(MMTK.Vector(0.1, -0.2, 1.5)), Rotation(MMTK.Vector(0.3, 1.2, -2.3), 0.001) ]: d = rb.displacementUnderTransformation(t) self.assert_((s.projectionOf(d) - d).norm() < 1.e-7) self.assert_(s.projectionComplementOf(d).norm() < 1.e-7)
def main(): usage = "SA:MP Art generator v0.3 by DialUp\nUsage: %prog [options]" parser = OptionParser(usage=usage) parser.add_option( "-i", default=None, action="store", type="string", dest="input_image", help="input image for conversion, for example, C:\\test\\1.png") parser.add_option( "-o", default=None, action="store", type="string", dest="output_file", help="output file with PAWN code, for example, output.inc") # do a full report generation by default: parser.set_defaults(mode=0) # partial generation is done if some flags are specified: parser.add_option( "-m", default=0, action="store", type="int", dest="mode", help="result size: 0 = very big, 1 = big, 2 = medium, 3 = small") parser.add_option( "-s", default="-760.0 1900.0 60.0", action="store", type="string", dest="position", help="picture centre position, for example, \"-760.0 1900.0 60.0\"") parser.add_option( "-r", default="0 0 0", action="store", type="string", dest="rotation", help="rotation of the result picture, for example, \"0.0 0.0 90.0\"") parser.add_option( "-c", default=1, action="store", type="int", dest="crop", help= "0 = don't modify picture, 1 = crop, 2 = resize (to prevent half-filled objects)" ) parser.add_option("-t", default=0, action="store", type="int", dest="type", help="0 = CreateObject, 1 = CreateDynamicObject") parser.add_option("-d", default=300, action="store", type="int", dest="distance", help="draw distance") (options, args) = parser.parse_args() if options.input_image == None or options.output_file == None: parser.error("input picture file and output file should be specified") global M_WP, M_HP, M_WS, M_HS, M_OID, TYPE, DISTANCE if options.distance != None: DISTANCE = options.distance if options.mode == 1: M_WS = M_WS_1 M_HS = M_HS_1 M_OID = M_OID_1 print "mode 1" if options.mode == 2: M_WS = M_WS_2 M_HS = M_HS_2 M_OID = M_OID_2 print "mode 2" if options.mode == 3: M_WS = M_WS_3 M_HS = M_HS_3 M_OID = M_OID_3 print "mode 3" if options.type == 1: TYPE = 1 pos_vec = [float(x) for x in options.position.split()] pos_rot = [float(x) for x in options.rotation.split()] if (len(pos_vec) != 3 or len(pos_rot) != 3): parser.error("bad position or rotation parameters! use -help") global angle, start_pos if options.crop >= 0 and options.crop < 3: global CROP CROP = options.crop angle = Vector(pos_rot[0], pos_rot[1], pos_rot[2]) start_pos = Vector(pos_vec[0], pos_vec[1], pos_vec[2]) dash = LoadImageFromFile(options.input_image) dash = Resize15(dash) xsize, ysize = dash.size blockx = int(float(xsize) / M_WP + 0.999) blocky = int(float(ysize) / M_HP + 0.999) dash_blocks = [] for x in xrange(0, blockx): for y in xrange(0, blocky): curblock = GetCrop15(dash, x, y) dash_blocks.append(curblock) Rot_z = Rotation(Vector(0, 0, 1), angle[2] * pi / 180.0) Rot_y = Rotation(Vector(0, 1, 0), angle[1] * pi / 180.0) Rot_x = Rotation(Vector(1, 0, 0), angle[0] * pi / 180.0) up_vector = Rot_z(Rot_y(Rot_x(Vector(0, 0, 1)))).normal() right_vector = Rot_z(Rot_y(Rot_x(Vector(0, 1, 0)))).normal() start_x = blockx / 2 start_y = blocky / 2 res_blocks = [] for block in dash_blocks: cur_x = block[1][0] cur_y = block[1][1] temp = (block[0], ((cur_x - start_x) * M_WS * right_vector + (cur_y - start_y) * (-M_HS) * up_vector, angle)) res_blocks.append(temp) out = open(options.output_file, 'w') out.write("//This art was made with DialUp's SAMP art tool\n") out.write("//Send your suggestions or questions to [email protected]\n") out.write("#if defined __SART__\n") out.write("#else\n") out.write("new __oid__;\nnew __temp_string__[2048];\n") out.write("new Float:__sX__, Float:__sY__,Float:__sZ__;\n") out.write("#endif\n") out.write("#define __SART__\n") out.write("__oid__ = 0;\n__sX__ = %02f; __sY__ = %02f; __sZ__ = %02f;\n" % (start_pos[0], start_pos[1], start_pos[2])) for block in res_blocks: ParseObject(out, block) out.close() print "Done! Now add the result include file into your gamemode!"
def randomRotationMatrix(): axis = Vector(randomArray((3, ))) angle = 2. * N.pi * random.random() return Rotation(axis, angle).tensor.array
from Scientific.Geometry import Vector ##.Transformation import * from Scientific.Geometry.Transformation import Rotation from random import random # Q = mat3(0.36, 0.48, -0.8, -0.8, 0.6, 0, 0.48, 0.64, 0.60) axis_q, angle_q = axis_and_angle(Q) print "Axis_q: %9.6f%9.6f%9.6f" % tuple(axis_q), print "Angle_q: %10.5f" % (angle_q*R2D) # for iii in range(1e6): axis_i = list(vec3([random(), random(), random()]).normalize()) angle_i = 3*random() rme = mat3().rotation(angle_i, vec3(axis_i)) axis_1, angle_1 = axis_and_angle(rme) v = Vector(axis_i) r = Rotation(v, angle_i) axis_2, angle_2 = r.axisAndAngle() axis_d = (axis_1 - vec3(tuple(axis_2))).length() angle_d = abs(angle_1 - angle_2) if (angle_d > 1e-13) or (axis_d > 1e-13): print "Angle_d: %.3e" % (angle_d*R2D), print " Axis_length_diff: %.3e" % axis_d print "Axis_i: %9.6f%9.6f%9.6f" % tuple(axis_i), print "Angle_i: %10.5f" % (angle_i*R2D) print "Axis_1: %9.6f%9.6f%9.6f" % tuple(axis_1), print "Angle_1: %10.5f" % (angle_1*R2D) print "Axis_2: %9.6f%9.6f%9.6f" % tuple(axis_2), print "Angle_2: %10.5f" % (angle_2*R2D)
def randomRotation(max_angle=N.pi): """Returns a Rotation object describing a random rotation with a uniform axis distribution and angles drawn from a uniform distribution between -|max_angle| and |max_angle|.""" return Rotation(randomDirection(), uniform(-max_angle, max_angle))
from Scientific.Geometry import Vector ##.Transformation import * from Scientific.Geometry.Transformation import Rotation from random import random # Q = mat3(0.36, 0.48, -0.8, -0.8, 0.6, 0, 0.48, 0.64, 0.60) axis_q, angle_q = axis_and_angle(Q) print "Axis_q: %9.6f%9.6f%9.6f" % tuple(axis_q), print "Angle_q: %10.5f" % (angle_q * R2D) # for iii in range(1e6): axis_i = list(vec3([random(), random(), random()]).normalize()) angle_i = 3 * random() rme = mat3().rotation(angle_i, vec3(axis_i)) axis_1, angle_1 = axis_and_angle(rme) v = Vector(axis_i) r = Rotation(v, angle_i) axis_2, angle_2 = r.axisAndAngle() axis_d = (axis_1 - vec3(tuple(axis_2))).length() angle_d = abs(angle_1 - angle_2) if (angle_d > 1e-13) or (axis_d > 1e-13): print "Angle_d: %.3e" % (angle_d * R2D), print " Axis_length_diff: %.3e" % axis_d print "Axis_i: %9.6f%9.6f%9.6f" % tuple(axis_i), print "Angle_i: %10.5f" % (angle_i * R2D) print "Axis_1: %9.6f%9.6f%9.6f" % tuple(axis_1), print "Angle_1: %10.5f" % (angle_1 * R2D) print "Axis_2: %9.6f%9.6f%9.6f" % tuple(axis_2), print "Angle_2: %10.5f" % (angle_2 * R2D)