Return to Snippet

Revision: 41035
at February 11, 2011 03:45 by adkatrit


Initial Code
def dotproduct(a,b):
	return sum([a[i]*b[i] for i in range(len(a))])

from math import acos

#Calculates the size of a vector
def veclength(a):
	return sum([a[i] for i in range(len(a))])**.5

#Calculates the angle between two vector
def ange(a,b):
	dp=dotproduct(a,b)
	la=veclength(a)
	lb=veclength(b)
	costheta=dp/(la*lb)
	return acos(costheta)

Initial URL


Initial Description


Initial Title
calculate angle between two vectors

Initial Tags


Initial Language
Python