-
Notifications
You must be signed in to change notification settings - Fork 0
Sandbox: Lua: Math: Quat
Аниса edited this page Sep 15, 2022
·
1 revision
Quaternions are simplified representation of complex numbers on 4 dimensions (1 real & 3 imaginary dimensions). Quats widely known for representing rotations precisely have special desirable properties compared to other form of representation such as 'Euler', 'Matrix' where you would end up with bottleneck due to Gimbal locks. Beside rotations quats are also pretty useful for generic math.
If you still have no idea how useful they are or where to apply/utilize them in the right way, then make sure to read: https://math.dartmouth.edu/~jvoight/quat-book.pdf
local cQuat1, cQuat2 = math.quat(1, 1, 1, 1), math.quat(2, 2, 2, 2)
local resultant = cQuat1 + cQuat2
local cQuat1, cQuat2 = math.quat(1, 1, 1, 1), math.quat(2, 2, 2, 2)
local resultant = cQuat1 - cQuat2
--Note: Quaternion multiplications aren't commutative!
local cQuat1, cQuat2 = math.quat(1, 1, 1, 1), math.quat(2, 2, 2, 2)
local resultant = cQuat1 * cQuat2
local cQuat1, cQuat2 = math.quat(1, 1, 1, 1), math.quat(2, 2, 2, 2)
local resultant = cQuat1 / cQuat2
local string: type = self:getType()
local quat: cQuat = math.quat(
float: x,
float: y,
float: z,
float: w
)
local bool: result = self:destroy()
local quat: self = self:scale(
float: scale
)
local quat: self = self:setAxisAngle(
float: x,
float: y,
float: z,
float: angle
)
local quat: cQuat = math.quat:fromAxisAngle(
float: x,
float: y,
float: z,
float: angle
)
local float: x, float: y, float: z = self:toEuler()
local quat: cQuat = math.quat:fromEuler(
float: x,
float: y,
float: z
)