import math class Vector3D: def __init__(self, x, y, z): self.x:float = x self.y:float = y self.z:float = z def __sub__(self, other): return Vector3D(self.x - other.x, self.y - other.y, self.z - other.z) def __abs__(self) -> float: return (self.x ** 2 + self.y ** 2 + self.z ** 2) ** 0.5 # 计算两向量间夹角 def angle_to(self, other): return math.acos( abs(self.x * other.x + self.y * other.y + self.z * other.z) / abs(self) / abs(other) )