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:
1 | function grp(part) |
2 | local finalF = Vector 3. 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 = Vector 3. new(finalF.X, finalF.Y, finalF.Z) |
4 | 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:
01 | local calcy = function (x, z) |
02 | return (x^ 2 )+(z^ 2 ); |
03 | end |
04 |
05 | local graph = function (x, y, z) |
06 | local point = Instance.new( "Part" , game.Workspace); |
07 | point.Size = Vector 3. new( 1 , 1 , 1 ); |
08 | point.CFrame = CFrame.new(x, y, z); |
09 | end |
10 |
11 | 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:
1 | local 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 = Vector 3. new( 1 , 1 , 1 ); |
5 | point.CFrame = CFrame.new(x, y, z); |
6 | end |
7 | end |
The other option would be to do this:
01 | local points = { } ; |
02 |
03 | -- normal body, but insert all instanced parts into table of points, then destroy any points out of bounds |
04 |
05 | graph( 1 , math.clamp(calcy( 1 , 2 ), - 72 , 72 ), 2 ); |
06 | for a, x in pairs (points) do |
07 | if ((x.Position.Y > 71 ) or (x.Position.Y < - 71 )) then |
08 | x:Destroy(); |
09 | end |
10 | end |