def __init__(self,startvect,endvect,cylind,Mode="NORMAL"): if Mode=="NORMAL": from gsl import fcmp # We need to ensure that startvect and endvect # both point to positions on the cylinder. Ra=cylind.shortestDistance(startvect,return_PerpLineSeg=True) Rb=cylind.shortestDistance(endvect,return_PerpLineSeg=True) if not (fcmp(Ra.length(),cylind.radius,1e-13)==0 and fcmp(Rb.length(),cylind.radius,1e-13)==0): print "Endpoints are not on the cylinder" raise Exception self.cylind=cylind LineSeg.__init__(self,startvect,endvect) # The cylind_startvect and cylind_endvect are vectors described in a # coordinate system where x points along Ra, z points along the cylinder # axis and the origin is at cylind.startvect zcylindstart_vect=Ra.endvect.subtract(self.cylind.startvect)# points from the z position on the cylinder of helix start to cylindstart zcylindend_vect=Rb.endvect.subtract(self.cylind.startvect) # points from the z position on the cylinder of helix end to cylindstart if zcylindstart_vect.unitvector() == None: zcylindstart=0 else: zcylindstart=zcylindstart_vect.magnitude*((zcylindstart_vect.unitvector()).dot(self.cylind.vector.unitvector())) if zcylindend_vect.unitvector() == None: zcylindend=0 else: zcylindend=zcylindend_vect.magnitude()*((zcylindend_vect.unitvector()).dot((self.cylind.vector()).unitvector())) crossProd=(Ra.vector()).cross(Rb.vector()).dot((self.cylind.vector()).unitvector()) dotProd=(Ra.vector()).dot(Rb.vector()) phi=atan2(crossProd,dotProd) #if phi<0.0: # phi=phi+2*pi if phi==0.0 or phi==fabs(2*pi): print "phi:",phi raise Exception self.cylind_startvect=Vector((Ra.length,0,zcylindstart),vtype="CYLINDRICAL") self.cylind_endvect=Vector((Rb.length,phi,zcylindend),vtype="CYLINDRICAL") self.M=(self.cylind_endvect.z-self.cylind_startvect.z)/float(self.cylind_endvect.phi-self.cylind_startvect.phi) self.forward_transform=find_vector_zx_rotation_transform(self.cylind.vector,Ra.vector.negate()) import numpy.linalg self.inverse_transform=numpy.linalg.inv(self.forward_transform) print "Phi END:",phi elif Mode=="CYLINDER_COORDS": # startvect and endvect are in coordinates referenced from cylind # print "I have not dealt with this yet" raise Exception else: #Unknown Mode print "Unknown Mode" raise Exception
def fleq(x,y,epsilon=1e-13): from gsl import fcmp "Returns true if x is less than or equal to y" val=fcmp(x,y,epsilon) if val <=0: return True else: return False
def fgeq(x,y,epsilon=1e-13): from gsl import fcmp "Returns true if x is greater than or equal to y" val=fcmp(x,y,epsilon) if val>=0: return True else: return False