Ir al contenido
Español
Ajuste de formas viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

Una figura de libro de texto sobre ajuste de formas en una cuadrícula de centímetros. El contorno dibujado a mano queda en gris; la forma ajustada se dibuja encima con el color de acento y un relleno suave. La elipse y el círculo tienen la misma área, el mismo centro y los mismos segundos momentos que el boceto cerrado; el triángulo es el mayor dentro de la envolvente convexa del boceto, escalado a la misma área. En Auto gana el más cercano entre triángulo y elipse, según la distancia RMS del boceto al contorno. Los vértices del triángulo se llaman A, B y C, los semiejes de la elipse a y b, y el radio del círculo r. La fila bajo la cuadrícula da el área y siguen cuatro medidas con el error RMS.

Úsalo para

  • Teach what fitting means: a model shape that is as close as possible to imperfect data, with its error shown next to it.
  • Geometry exercises where learners sketch a triangle or an ellipse and read its angles, axes or area without measuring by hand.

Busca otra opción cuando

  • For drawing precise shapes for a design, use a shape tool with handles: the fit always follows the sketch.

Uso

import React, { useState } from 'react'
import { ContourPress } from './ContourPress.jsx'

// Points are centimetres on the 24 × 11 cm grid, origin top left
const sketch = [[12.5, 2], [19, 9], [5.5, 8.8]]

export function GeometryExercise() {
  const [points, setPoints] = useState(sketch)
  const [fit, setFit] = useState(null)
  return (
    <ContourPress
      value={points}
      onChange={(next, details) => {
        setPoints(next)
        setFit(details.fit)
      }}
      labels={{ title: 'Fit a triangle to a sketch' }}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
valueArray<[x: number, y: number]>—Controlled sketch: the outline's points in centimetres on the 24 × 11 grid, origin top left. The outline is closed from the last point back to the first.
defaultValueArray<[x: number, y: number]>[]Starting sketch when uncontrolled.
onChange(points, { reason, fit }) => void—Called when a sketch is finished or cleared. reason is 'draw', 'keyboard' or 'clear'; fit is null or { type, area, error } plus sides, angles and perimeter (triangle), semiAxes, rotation and eccentricity (ellipse) or radius and circumference (circle), all in centimetres and degrees.
mode'auto' | 'triangle' | 'ellipse' | 'circle'—Controlled fit mode. 'auto' keeps whichever of the triangle and the ellipse lies closer to the sketch.
defaultMode'auto' | 'triangle' | 'ellipse' | 'circle''auto'Starting fit mode when uncontrolled.
onModeChange(mode) => void—Called when a fit mode is chosen.
holdMsnumber400How long the pointer must rest while drawing before the fit is previewed (160–1500 ms). Lifting fits in any case.
labelsobject—Replaces any built-in text: title, sketch, fitted, grid ('{unit}'), unit, canvas, help, empty, keys, mode, modeAuto, modeTriangle, modeEllipse, modeCircle, clear, readoutTriangle, readoutEllipse, readoutCircle, readoutEmpty, readoutSmall, sides, angles, perimeter, semiAxes, rotation, eccentricity, radius, diameter, circumference, error, pointAdded ('{n}', '{x}', '{y}'), pointRemoved ('{n}'), fittedText ('{shape}', '{area}', '{error}') and cleared.
localestring'en'Language tag for the decimal readouts.
classNamestring—Extra class on the card, for example to set its width (30rem by default, never wider than its container).

Accesibilidad

  • The grid is an application region with its instructions as its description. With the keyboard, arrows move a cross-hair by 0.5 cm (Shift: 2 cm), Space adds a point, Enter closes the outline and fits it, Backspace removes the last point and Escape drops the points. A hint with these keys shows while the grid has keyboard focus.
  • The fit mode is a radio group: Tab reaches the chosen mode, arrows move and select. Clear is a button, marked unavailable while the grid is empty.
  • A polite live region announces each added point and each fit with its area and error. The measurements are a description list under the grid.
  • Drawing uses pointer capture and touch-action none on the grid only; a cancelled gesture or a lost window focus drops the stroke and keeps the previous sketch. A tap changes nothing.

Movimiento

While the pointer rests for holdMs a dashed preview of the fit appears; lifting fills it in, and a new fit fades in over --ds-duration-base. With reduced motion every change lands at once.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

ContourPress.jsxcontour-press.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Formularios
Cuadrícula de disponibilidad viene con Pro. La vista previa aparece al desbloquearlo.
Operaciones booleanas viene con Pro. La vista previa aparece al desbloquearlo.
Selector en cascada viene con Pro. La vista previa aparece al desbloquearlo.