Ejemplo n.º 1
0
    def screwMotion(self):
	l = self.vector.length()
	if l == 0.:
	    return VectorModule.Vector(0.,0.,0.), \
                   VectorModule.Vector(0.,0.,1.), 0., 0.
	else:
	    return VectorModule.Vector(0.,0.,0.), self.vector/l, 0., l
Ejemplo n.º 2
0
    def screwMotion(self):
	import LinearAlgebra
	axis, angle = self.rotation().axisAndAngle()
	d = self.vector*axis
	x = d*axis-self.vector
	r0 = Numeric.dot(LinearAlgebra.generalized_inverse(
	                    self.tensor.array-Numeric.identity(3)), x.array)
	return VectorModule.Vector(r0), axis, angle, d
Ejemplo n.º 3
0
    def __mul__(self, other):
	if isTensor(other):
	    a = self.array[self.rank*(slice(None),)+(Numeric.NewAxis,)]
	    b = other.array[other.rank*(slice(None),)+(Numeric.NewAxis,)]
	    return Tensor(Numeric.innerproduct(a, b), 1)
	elif VectorModule.isVector(other):
	    return other.__rmul__(self)
	else:
	    return Tensor(self.array*other, 1)
Ejemplo n.º 4
0
 def __call__(self, *points):
     if len(points) == 1:
         points = tuple(points[0])
     value = apply(Interpolation.InterpolatingFunction.__call__,
                   (self, ) + points)
     if self.rank == 0:
         return value
     elif self.rank == 1:
         return VectorModule.Vector(value)
     else:
         return TensorModule.Tensor(value)
Ejemplo n.º 5
0
def vector_Similarity(sentence):
    mydb = database()
    mycursor = mydb.cursor(buffered=True)

    #checking if the sentence is available in database
    query = "SELECT Sid FROM Sentences WHERE sentence =%s LIMIT 1"
    mycursor.execute(query, (sentence, ))

    #getting the count of returned rows
    count = mycursor.rowcount

    if count > 0:
        #if sentence is available
        myresult = mycursor.fetchall()
        #id of the searched sentence
        sentence_id = int(myresult[0][0])
    else:
        # else sending the sentence for vector formation
        result = create_vector.delay(sentence)
        while (result.ready() == False):
            pass
        #id of the searched sentence
        sentence_id = int(result.get())

    #getting the vector of query sentence
    Vector1 = get_vector(sentence_id)
    #getting the sentence id of all the sentences.
    query = "SELECT Sid,Did FROM Sentences where Did IS NOT Null"
    mycursor.execute(query)
    documents = []
    for (Sid, Tid) in mycursor:
        Sid = int(Sid)
        if Sid != sentence_id:
            # getting the vector of a Sentence
            Vector2 = get_vector(Sid)
            if (len(Vector2) == 512):
                #calling the C function for finding the angle between the query vector and different sentence
                angle = VectorModule.Product(Vector1, Vector2)
                documents.append((Tid, angle))
            else:
                print(Sid)

    #sorting the list of ids based on the angle between them
    documents = sorted(documents, key=lambda x: -x[1])

    #retreiving the tool ids, angles
    if len(documents) > 0:
        all_doc_ids, all_angles = list(zip(*documents))
        all_doc_ids = [i for i in all_doc_ids if i is not None]
    else:
        all_doc_ids = []

    return Doc_details(all_doc_ids)
Ejemplo n.º 6
0
    def asVector(self):
        "Returns an equivalent vector object (only for rank 1)."
	if self.rank == 1:
	    return VectorModule.Vector(self.array)
	else:
	    raise ValueError, 'rank > 1'
Ejemplo n.º 7
0
    def screwMotion(self):
	axis, angle = self.axisAndAngle()
	return VectorModule.Vector(0., 0., 0.), axis, angle, 0.
Ejemplo n.º 8
0
    def translation(self):
	return Translation(VectorModule.Vector(0.,0.,0.))
Ejemplo n.º 9
0
    def screwMotion(self):
	import LinearAlgebra
	axis, angle = self.rotation().axisAndAngle()
	d = self.vector*axis
	x = d*axis-self.vector
	r0 = Numeric.dot(LinearAlgebra.generalized_inverse(
	                    self.tensor.array-Numeric.identity(3)), x.array)
	return VectorModule.Vector(r0), axis, angle, d

# Utility functions

def angleFromSineAndCosine(y, x):
    return atan2(y, x)

def mod_angle(angle, mod):
    return (angle + mod/2.) % mod - mod/2


# Test code

if __name__ == '__main__':

    t = Translation(VectorModule.Vector(1,0,0))
    r = Rotation(VectorModule.ex+VectorModule.ey, Numeric.pi)
    q = r.asQuaternion()
    angles = r.threeAngles(VectorModule.Vector(1., 0., 0.),
                           VectorModule.Vector(0., 1., 0.),
                           VectorModule.Vector(0., 0., 1.))
    print angles