Help With Parametric Equation

Towards the end of this post: RunService | Documentation - Roblox Creator Hub it uses a ‘simple parametric equation’. I have no idea what this is and how it works.

Here is the code used in the code sample from the post:

local RunService = game:GetService("RunService")
 
-- How fast the frame ought to move
local SPEED = 2
 
local frame = script.Parent
frame.AnchorPoint = Vector2.new(.5, .5)
 
-- A simple parametric equation of a circle
-- centered at (0.5, 0.5) with radius (0.5)
local function circle(t)
	return .5 + math.cos(t) * .5,
	       .5 + math.sin(t) * .5
end
 
-- Keep track of the current time
local currentTime = 0
local function onRenderStep(deltaTime)
	-- Update the current time
	currentTime = currentTime + deltaTime * SPEED
	-- ...and our frame's position
	local x, y = circle(currentTime)
	frame.Position = UDim2.new(x, 0, y, 0)
end
 
-- This is just a visual effect, so use the "Last" priority
RunService:BindToRenderStep("FrameCircle", Enum.RenderPriority.Last.Value, onRenderStep)
--RunService.RenderStepped:Connect(onRenderStep) -- Also works, but not recommended

Thank you if you can get to me :grinning:

1 Like

As the name suggests, a parametric equation is just an equation that has an independent parameter, a number that we can play with however we want. In most cases, this parameter is time, and usually denoted as t. In physics, parametric equations are super useful because we always study the behavior of things respect to time. For example, if we had something that calculates the velocity of an object after some constant acceleration after a certain amount of time, which is this bad boy

v=u+at

Where u is our initial velocity (the velocity we started with), and a is our acceleration, and t is the time.

u and a are both constant, they don’t change, they would always be the same. Although t is always changing. Let’s say we wanted to graph how our velocity changes from 0 seconds, meaning since t equals 0, until 5 seconds, meaning t equals 5. Here we have a parameteric equation, t is independant, and we want to calcualte the velocity depending on the current t that we passed. (velocity and acceleration are both vector quantities by the way).

local function calculateVelcoity(t)
    return Vector3.new(0, 0, 0) + Vector3.new(0, 0, 1) * t
end

t is our parameter. Looping from 0 to 5, would show us how the velocity is changing overtime.

for i = 0, 5 do
     print(calculateVeclocity(i))
end

more info

The equation above calculates the position of a cricle overtime, and it is a parametric equation as well, it has a parameter t, which is independent and changes as the game goes on, and we want to calculate the position of the circle as t changes.

2 Likes