import React, { useState } from 'react'; const LinearSolutionsWidget: React.FC = () => { // Model: ax + b = cx + d const [a, setA] = useState(2); const [b, setB] = useState(4); const [c, setC] = useState(2); const [d, setD] = useState(8); const isParallel = a === c; const isCoincident = isParallel && b === d; // Calculate solution if not parallel // ax + b = cx + d => (a-c)x = d-b => x = (d-b)/(a-c) const intersectionX = isParallel ? 0 : (d - b) / (a - c); const intersectionY = a * intersectionX + b; // Visualization range const range = 10; const scale = 20; // 1 unit = 20px const center = 150; // px const toPx = (val: number, isY = false) => { if (isY) return center - val * scale; return center + val * scale; }; const getLinePath = (slope: number, intercept: number) => { const x1 = -range; const y1 = slope * x1 + intercept; const x2 = range; const y2 = slope * x2 + intercept; return `M ${toPx(x1)} ${toPx(y1, true)} L ${toPx(x2)} ${toPx(y2, true)}`; }; return (
Left Side (Line 1)
Right Side (Line 2)
Algebraic Check: