Hello.
I made my own graphing system using blocks and my own equations. I've also made my own custom 3D axes that range from -71 to 71 on all axes. The only problem is that when I try to graph something, the graph goes out of the y-axis range. I have used math.clamp(partPosY, -71, 71)
to fix it, but no luck.
Here are some screenshots (Couldn't convert them to links for some reason...):
My custom 3D axes: https://gyazo.com/442f35edcd3d02a8f0660eeffdb539bf
Graph went out of range on the y-axis (min:71, max:71) https://gyazo.com/5772e2b944d13b58a48d803bd4d324c6
Is there a way to accomplish this? Here is my code snipplet:
function grp(part) local finalF = Vector3.new(part.Position.X, (part.Position.X^3*part.Position.Z+part.Position.Z^3*part.Position.X)/2000, part.Position.Z) part.BodyPosition.Position = Vector3.new(finalF.X, finalF.Y, finalF.Z) end
In an ironic twist of fate, I did something similar to generate smooth terrain from an array of 2d points just the other day :p
plug:
https://www.roblox.com/games/1121503247/lol-kek
Try separating your functions:
local calcy = function(x, z) return (x^2)+(z^2); end local graph = function(x, y, z) local point = Instance.new("Part", game.Workspace); point.Size = Vector3.new(1, 1, 1); point.CFrame = CFrame.new(x, y, z); end graph(1, math.clamp(calcy(1, 2), -71, 71), 2);
If the name of the game is to only graph points within a certain limit, there are two good ways of doing it.
The best way would be to alter the graph()
function as such:
local graph = function(x, y, z, min, max) if((y >= min) and (y <= max))then local point = Instance.new("Part", game.Workspace); point.Size = Vector3.new(1, 1, 1); point.CFrame = CFrame.new(x, y, z); end end
The other option would be to do this:
local points = {}; -- normal body, but insert all instanced parts into table of points, then destroy any points out of bounds graph(1, math.clamp(calcy(1, 2), -72, 72), 2); for a, x in pairs(points) do if((x.Position.Y > 71) or (x.Position.Y < -71))then x:Destroy(); end end