DualQuaternion - SLerp for CFrames

Dual Quaternion
by len_ny

Download


What is this?

DualQuaternion is a module that implements a spherically accurate lerp method for CFrames. Internally, Roblox opted for an NLerp (linear interpolate) method for speed in calculations. However, there is another interpolate method that is spherically accurate that Roblox has yet to provide an open API to, SLerp!

Why use this?

Quaternions

This module includes an improved version of sleitnick/quaternion module with more meta operations including:

  • Adding Quaternions
  • Multiplication with Numbers

Dual Quaternions

Provides an easy to use, fully functional, and pain free CFrame → Quaternion interface. With support for converting CFrame’s from & to Quaternions, as well as including uncommon methods such as Normalized, and Screw. Best of all, this module was made for Roblox, and it’s developers, by keeping the package-like interface & strict typing to make development as easy as possible.

Example

local startCF, endCF = ...
local startdq, enddq = DualQuaternion.cframe(startCF), DualQuaternion.cframe(endCF)

local parts = { ... }

local a = 0
while true do
	for i, part in pairs(parts) do
		-- nlerp ❌
		part.CFrame = startcf:Lerp(endcf, a)

		-- slerp ✔️
		part.CFrame = startdq:Lerp(enddq, a):ToCFrame()
	end
	
	task.wait()
end

Credits

7 Likes

Neat module that makes use of some cool math!
I personally don’t have a use case, but I’m curious what you guys might use this for!

There are many use cases for slerp. For example you might be playing in a sci-fi game where you are on a spherical planet and you are trying to make a hovercraft tween from one end of the planet to the other without having that hovercraft pass through the globe.

1 Like