def make_kappa_goniometer(alpha, omega, kappa, phi, direction, scan_axis): import math omega_axis = (1, 0, 0) phi_axis = (1, 0, 0) c = math.cos(alpha * math.pi / 180); s = math.sin(alpha * math.pi / 180); if direction == "+y": kappa_axis = (c, s, 0.0) elif direction == "+z": kappa_axis = (c, 0.0, s) elif direction == "-y": kappa_axis = (c, -s, 0.0) elif direction == "-z": kappa_axis = (c, 0.0, -s) else: raise RuntimeError("Invalid direction") if scan_axis == "phi": scan_axis = 0 else: scan_axis = 2 from scitbx.array_family import flex axes = flex.vec3_double((phi_axis, kappa_axis, omega_axis)) angles = flex.double((phi, kappa, omega)) names = flex.std_string(("PHI", "KAPPA", "OMEGA")) return goniometer_factory.make_multi_axis_goniometer( axes, angles, names, scan_axis)
def Xrotz(theta): """ % Xrotz spatial coordinate transform (Z-axis rotation). % Xrotz(theta) calculates the coordinate transform matrix from A to B % coordinates for spatial motion vectors, where coordinate frame B is % rotated by an angle theta (radians) relative to frame A about their % common Z axis. """ c = math.cos(theta) s = math.sin(theta) return matrix.sqr((c, s, 0, 0, 0, 0, -s, c, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, c, s, 0, 0, 0, 0, -s, c, 0, 0, 0, 0, 0, 0, 1))
def __init__(O, qE): if (qE is None): qE = matrix.col((0,0,0)) O.qE = qE th = abs(qE) if (th == 0): p = matrix.col((1,0,0,0)) else: p0 = math.cos(th) p1, p2, p3 = math.sin(th) / th * qE p = matrix.col((p0,p1,p2,p3)) assert abs(abs(p)-1) < 1.e-12 O.E = joint_lib.RBDA_Eq_4_12(q=p) O.setT()
def __init__(O, qE): if (qE is None): qE = matrix.col((0, 0, 0)) O.qE = qE th = abs(qE) if (th == 0): p = matrix.col((1, 0, 0, 0)) else: p0 = math.cos(th) p1, p2, p3 = math.sin(th) / th * qE p = matrix.col((p0, p1, p2, p3)) assert abs(abs(p) - 1) < 1.e-12 O.E = joint_lib.RBDA_Eq_4_12(q=p) O.setT()
def Xrotz(theta): """ % Xrotz spatial coordinate transform (Z-axis rotation). % Xrotz(theta) calculates the coordinate transform matrix from A to B % coordinates for spatial motion vectors, where coordinate frame B is % rotated by an angle theta (radians) relative to frame A about their % common Z axis. """ c = math.cos(theta) s = math.sin(theta) return matrix.sqr(( c, s, 0, 0, 0, 0, -s, c, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, c, s, 0, 0, 0, 0, -s, c, 0, 0, 0, 0, 0, 0, 1))
def OnScale(self, scale): if (abs(scale) > self.scale_max) : if (scale < 0) : scale = -self.scale_max else : scale = self.scale_max s = self.minimum_covering_sphere r = (1+1.e-6)*s.radius() d = -gltbx.util.object_as_eye_coordinates(self.rotation_center)[2] dr = d + r if (scale > 0 and (dr <= self.min_near or d <= self.min_dist)): pass # near limit elif (scale < 0 and r < d * math.sin(self.field_of_view_y*math.pi/180/2) * self.min_viewport_use_fraction): pass # far limit else: gltbx.util.translate_object(0,0,dr*scale) self.OnRedraw()
def draw_minimum_covering_sphere(self): if (self.minimum_covering_sphere_display_list is None): self.minimum_covering_sphere_display_list=gltbx.gl_managed.display_list() self.minimum_covering_sphere_display_list.compile() s = self.minimum_covering_sphere c = s.center() r = s.radius() gray = 0.3 glColor3f(gray,gray,gray) glBegin(GL_POLYGON) for i in xrange(360): a = i * math.pi / 180 rs = r * math.sin(a) rc = r * math.cos(a) glVertex3f(c[0],c[1]+rs,c[2]+rc) glEnd() self.draw_cross_at(c, color=(1,0,0)) self.minimum_covering_sphere_display_list.end() self.minimum_covering_sphere_display_list.call()
def OnScale(self, scale): if (abs(scale) > self.scale_max): if (scale < 0): scale = -self.scale_max else: scale = self.scale_max s = self.minimum_covering_sphere r = (1 + 1.e-6) * s.radius() d = -gltbx.util.object_as_eye_coordinates(self.rotation_center)[2] dr = d + r if (scale > 0 and (dr <= self.min_near or d <= self.min_dist)): pass # near limit elif (scale < 0 and r < d * math.sin(self.field_of_view_y * math.pi / 180 / 2) * self.min_viewport_use_fraction): pass # far limit else: gltbx.util.translate_object(0, 0, dr * scale) self.OnRedraw()
def draw_minimum_covering_sphere(self): if (self.minimum_covering_sphere_display_list is None): self.minimum_covering_sphere_display_list = gltbx.gl_managed.display_list( ) self.minimum_covering_sphere_display_list.compile() s = self.minimum_covering_sphere c = s.center() r = s.radius() gray = 0.3 glColor3f(gray, gray, gray) glBegin(GL_POLYGON) for i in xrange(360): a = i * math.pi / 180 rs = r * math.sin(a) rc = r * math.cos(a) glVertex3f(c[0], c[1] + rs, c[2] + rc) glEnd() self.draw_cross_at(c, color=(1, 0, 0)) self.minimum_covering_sphere_display_list.end() self.minimum_covering_sphere_display_list.call()
def j0(x): result = math.sin(x)/x return result
def cs(a): return math.cos(a), math.sin(a) c1,s1 = cs(q1)
def cs(a): return math.cos(a), math.sin(a)
def cs(a): return math.cos(a), math.sin(a) c2,s2 = cs(q2)
def j1(x): result = math.sin(x)/(x*x) - math.cos(x)/x return result
def j2(x): result = (3.0/(x*x) -1.0)*(math.sin(x)/x) - 3.0*math.cos(x)/(x*x) return result