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:

1function grp(part)
2    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)
3    part.BodyPosition.Position = Vector3.new(finalF.X, finalF.Y, finalF.Z)
4end

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:

01local calcy = function(x, z)
02    return (x^2)+(z^2);
03end
04 
05local graph = function(x, y, z)
06    local point = Instance.new("Part", game.Workspace);
07    point.Size = Vector3.new(1, 1, 1);
08    point.CFrame = CFrame.new(x, y, z);
09end
10 
11graph(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:

1local graph = function(x, y, z, min, max)
2    if((y >= min) and (y <= max))then
3        local point = Instance.new("Part", game.Workspace);
4        point.Size = Vector3.new(1, 1, 1);
5        point.CFrame = CFrame.new(x, y, z);
6    end
7end

The other option would be to do this:

01local points = {};
02 
03-- normal body, but insert all instanced parts into table of points, then destroy any points out of bounds
04 
05graph(1, math.clamp(calcy(1, 2), -72, 72), 2);
06for a, x in pairs(points) do
07    if((x.Position.Y > 71) or (x.Position.Y < -71))then
08        x:Destroy();
09    end
10end
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