import math
import numpy as np
class Point(object):
def __init__(self, x1, y1, x2, y2):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
def vector(self):
c = (self.x1 - self.x2, self.y1 - self.y2)
return c
def length(self):
d = math.sqrt(pow((self.x1 - self.x2), 2) + pow((self.y1 - self.y2), 2))
return d
class Calculate(object):
def __init__(self, x, y, m, n):
self.x = x
self.y = y
self.m = m
self.n = n
def Vector_multiplication(self):
self.mu = np.dot(self.x, self.y)
return self.mu
def Vector_model(self):
self.de = self.m * self.n
return self.de
def cal(self):
result = Calculate.Vector_multiplication(self) / Calculate.Vector_model(self)
return result
if __name__ == '__main__':
first_point = Point(1, 2, 3, 2)
two_point = Point(3, 5, 4, 2)
ca = Calculate(first_point.vector(), two_point.vector(), first_point.length(), two_point.length())
print('两向量的夹角', ca.cal())