Sine wave script gives odd output

Edit:

-- Changed my sin function to
for i = equation[2], equation[3], 0.5 do
	spawn(function()
		local new_node = Instance.new("Part")
		new_node.Size = Vector3.new(1,1,1)
		new_node.Anchored = true
		local x = (i)
		local y = math.sin(i * math.pi/180) * equation[4]
		new_node.Position = Vector3.new(x, y, 0)
		new_node.Parent = equation_graph
	end)
end

I was trying to map out/graph a sin wave with Roblox by using parts as a representation. Linear and quadratic sequences all worked out fine. However, I got an interesting result of sin from this.


The script I used to generate this would be:

for i = equation[2], equation[3], 0.1 do
	spawn(function()
		local new_node = Instance.new("Part")
		new_node.Size = Vector3.new(1,1,1)
		new_node.Anchored = true
		local x = (i)
		local y = (math.sin(math.deg(i))) * equation[4]
		print(x, y)
		new_node.Position = Vector3.new(x, y, 0)
		new_node.Parent = equation_graph
	end)
end

I’ve tried inspecting each of the part’s to see what’s going on with them but I couldn’t conclude anything from it. Anyone else got some suggestions?

What does your “equation” table look like?

I solved it but here’s all the equations I’m mapping out currently:

local equations = {
	equation_solver.solve("linear", 1, 2),
	equation_solver.solve("linear", 7, 15),
	equation_solver.solve("linear", 6, 9),
	equation_solver.solve("quadratic", 7, 9, 12),
	equation_solver.solve("quadratic", 1, 2, 4),
	{"sin", -180, 180, 10},
	{"sin", -180, 180, 3},
	{"sin", -180, 180, 1},
	{"sin", -180, 180, 5},
	{"sin", -180, 180, 100}
}
1 Like

Nevermind, I see you changed the title to “Solved.” Perhaps create a comment with your solution and then mark it as the solution.

Instead of using:

local y = math.sin(math.deg(i))

Use:

local y = math.sin(i * math.pi/180)
1 Like