Make a new Python script file and call it Quaternion. py. Add the following code to the newly created file:
from _ future_ import annotations
import pygame
import math
import numpy as np
class Quaternion:
def_init_(self, vector=None,
axis: pygame.Vector3 = None,
angle: float $=$ None) :
if vector is not None:
self. $w$ = vector $[0]$
self. $x$ = vector [1]
self. $y=$ vector [2]
self. $z$ = vector [3]
else:
axis = axis.normalize()
sin_angle =
math.sin(math.radians (angle/2.0))
cos_angle =
math.cos(math.radians(angle/2.0))
self.w = cos_angle
self.x = axis.x * sin_angle
self.y = axis.y * sin_angle
self.z = axis.z * sin_angle