from typing import Sequence
from typing import Tuple
import math


def euler_to_quaternion(euler: Sequence[float]) -> Tuple[float,float,float,float]:
	"""
	Convert XYZ euler angles to WXYZ quaternion, using the same method as MikuMikuDance.
	Massive thanks and credit to "Isometric" for helping me discover the transformation method used in mmd!!!!

	:param euler: 3x float, X Y Z angle in degrees
	:return: 4x float, W X Y Z quaternion
	"""
	# massive thanks and credit to "Isometric" for helping me discover the transformation method used in mmd!!!!
	# angles are in degrees, must convert to radians
	roll, pitch, yaw = euler
	roll = math.radians(roll)
	pitch = math.radians(pitch)
	yaw = math.radians(yaw)
	
	# roll (X), pitch (Y), yaw (Z)
	sx = math.sin(roll * 0.5)
	sy = math.sin(pitch * 0.5)
	sz = math.sin(yaw * 0.5)
	cx = math.cos(roll * 0.5)
	cy = math.cos(pitch * 0.5)
	cz = math.cos(yaw * 0.5)
	
	w = (cz * cy * cx) + (sz * sy * sx)
	x = (cz * cy * sx) + (sz * sy * cx)
	y = (sz * cy * sx) - (cz * sy * cx)
	z = (cz * sy * sx) - (sz * cy * cx)
	
	return w, x, y, z