Is it faster to use linear bezier curves than to use interpolation?

Hey guys, so as you may know the interpolation of two points is modeled as the vector formed from one point to the other (can be extended to 1d) in other words it’s the direction you get when you form a vector and if you have worked with vectors before you know that this also models their magnitude in a way cause getting this new direction vector and divide it by 2 you will get the point that would be “half” of it’s magnitude in a sense. Then you just apply an offset to it, typically the tail of the vector so you end up with

a+(b-a)*t=p(d)

Now im not too fancy with bezier curves but I know for sure that the linear bezier curve, that being given our current definitions of our other variables would be Bézier curve - Wikipedia

(1-t)*a + t*b = p(d)

I put these too into mathpapa and it said they are equivalent. So it made me wonder, does one have any performance differences?

1 Like

Too late to the party but here we go!
Here is my test:

--[[

|WARNING| THESE TESTS RUN IN YOUR REAL ENVIRONMENT. |WARNING|

If your tests alter a DataStore, it will actually alter your DataStore.

This is useful in allowing your tests to move Parts around in the workspace or something,
but with great power comes great responsibility. Don't mess up your stuff!

---------------------------------------------------------------------

Documentation and Change Log:
https://devforum.roblox.com/t/benchmarker-plugin-compare-function-speeds-with-graphs-percentiles-and-more/829912/1

--------------------------------------------------------------------]]

local rand = Random.new()

return {

	ParameterGenerator = function()
		-- This function is called before running your function (outside the timer)
		-- and the return(s) are passed into your function arguments (after the Profiler). This sample
		-- will pass the function a random number, but you can make it pass
		-- arrays, Vector3s, or anything else you want to test your function on.
		return rand:NextUnitVector(), rand:NextUnitVector()
	end;

	Functions = {
		["Sample A"] = function(Profiler, a, b, t) -- You can change "Sample A" to a descriptive name for your function
			for t = 0, 10000000 do
				local x = a+(b-a)*t
			end
		end;

		["Sample B"] = function(Profiler, a, b)
			for t = 0, 10000000 do
				local x = (1-t)*a + t*b
			end
		end;

		-- You can add as many functions as you like!
	};

}


So according to boat bomber’s benchmarking plugin:
a+(b-a)*t is roughly 75% faster than (1-t)*a + t*b !

1 Like