function Graph3DPlotter() { const [equation, setEquation] = useState('Math.sin(Math.sqrt(x**2 + y**2))'); const plotGraph = () => { try { const size = 50; const range = 5; const step = (2 * range) / size; const xValues = []; const yValues = []; const zValues = []; for (let i = 0; i < size; i++) { xValues[i] = []; yValues[i] = []; zValues[i] = []; for (let j = 0; j < size; j++) { const x = -range + i * step; const y = -range + j * step; xValues[i][j] = x; yValues[i][j] = y; try { const z = eval(equation.replace(/x/g, `(${x})`).replace(/y/g, `(${y})`)); zValues[i][j] = isFinite(z) ? z : 0; } catch (e) { zValues[i][j] = 0; } } } const data = [{ x: xValues, y: yValues, z: zValues, type: 'surface', colorscale: 'Viridis' }]; const layout = { title: `z = ${equation}`, scene: { xaxis: { title: 'X' }, yaxis: { title: 'Y' }, zaxis: { title: 'Z' } }, autosize: true }; Plotly.newPlot('graph3d-plot', data, layout, { responsive: true }); } catch (error) { alert('Error plotting 3D graph. Please check your equation.'); } }; return (

📊 3D Graph Plotter

Enter an equation in the form z = f(x, y) where z is expressed as a function of x and y.

Example Equations to Try:
Math.sqrt(25 - x**2 - y**2) - Sphere (upper hemisphere, r=5)
Math.sqrt(x**2 + y**2) - Cone (upright)
5 - Math.sqrt(x**2 + y**2) - Inverted Cone
x**2 + y**2 < 9 ? 5 : 0 - Cylinder (r=3, h=5)
x**2 + y**2 - Paraboloid
Math.sin(Math.sqrt(x**2 + y**2)) - Ripple
Math.sin(x) * Math.cos(y) - Wave
x**2 - y**2 - Saddle
setEquation(e.target.value)} placeholder="Math.sqrt(25 - x**2 - y**2)" />
); } // Export to global registry window.Graph3DPlotter = Graph3DPlotter;