import React, { useState } from 'react'; const ParabolaWidget: React.FC = () => { const [a, setA] = useState(1); const [h, setH] = useState(2); const [k, setK] = useState(1); // Viewport const range = 10; const size = 300; const scale = 300 / (range * 2); const center = size / 2; const toPx = (v: number, isY = false) => isY ? center - v * scale : center + v * scale; // Generate Path const generatePath = () => { const step = 0.5; let d = ""; for (let x = -range; x <= range; x += step) { const y = a * Math.pow(x - h, 2) + k; // Clip if way out of bounds to avoid SVG issues if (Math.abs(y) > range * 2) continue; const px = toPx(x); const py = toPx(y, true); d += x === -range ? `M ${px} ${py}` : ` L ${px} ${py}`; } return d; }; return (
Vertex Form
y = {a}(x - {h})² + {k}
setA(parseFloat(e.target.value))} className="w-full h-2 bg-indigo-100 rounded-lg accent-indigo-600"/>
setH(parseFloat(e.target.value))} className="w-full h-2 bg-emerald-100 rounded-lg accent-emerald-600"/>
setK(parseFloat(e.target.value))} className="w-full h-2 bg-rose-100 rounded-lg accent-rose-600"/>
{/* Axes */} {/* Parabola */} {/* Vertex */} V({h}, {k}) {/* Axis of Symmetry */}
); }; export default ParabolaWidget;