Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you force my 3D graphing system to graph between -71 and 71?

Asked by 7 years ago
Edited 7 years ago

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

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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
0
Woops, didn't even address clamping the maximum value; editing. KidTech101 376 — 7y
0
It works when it limits between -71 and 71, but this happens: https://gyazo.com/4a2f6516582199a3ff57334e13c54713. The only way to fix that problem is by dividing the whole equation by a big number. But that's going to be a problem for other graphing equations too. :( NoBootAvailable 50 — 7y
0
Oh, that's fair. I'll edit the answer with a solution. KidTech101 376 — 7y
Ad

Answer this question