Enhanced Inscribed Square Finder

Drawing Tools

Mathematical Data

No curve data available

About the Inscribed Square Finder

Mathematical Foundations

Shoelace Formula

We use the Shoelace formula (also known as the surveyor's formula) to calculate the area of the polygon formed by the curve:

A=12i=1n1(xiyi+1+xny1)i=1n1(xi+1yi+x1yn)A = \frac{1}{2}\left|\sum_{i=1}^{n-1} (x_i y_{i+1} + x_n y_1) - \sum_{i=1}^{n-1} (x_{i+1} y_i + x_1 y_n)\right|

Where (xi, yi) are the coordinates of the i-th vertex of the polygon.

Algorithm Implementation

Finding the Inscribed Square

This algorithm uses a Monte Carlo approach, trying random points within the curve to find the largest inscribed square.

function findInscribedSquare(curve) {
  const minX = Math.min(...curve.map(p => p.x));
  const maxX = Math.max(...curve.map(p => p.x));
  const minY = Math.min(...curve.map(p => p.y));
  const maxY = Math.max(...curve.map(p => p.y));

  let bestSquare = [];
  let maxSize = 0;

  for (let i = 0; i < 1000; i++) {
    const center = getRandomPointInside(curve);
    let low = 0;
    let high = Math.min(maxX - minX, maxY - minY);

    while (high - low > 1) {
      const mid = (low + high) / 2;
      const square = [
        { x: center.x - mid / 2, y: center.y - mid / 2 },
        { x: center.x + mid / 2, y: center.y - mid / 2 },
        { x: center.x + mid / 2, y: center.y + mid / 2 },
        { x: center.x - mid / 2, y: center.y + mid / 2 },
      ];

      if (square.every(p => isPointInside(p, curve))) {
        if (mid > maxSize) {
          maxSize = mid;
          bestSquare = square;
        }
        low = mid;
      } else {
        high = mid;
      }
    }
  }

  return bestSquare;
}

This algorithm uses a Monte Carlo approach, trying random points within the curve to find the largest inscribed square.

Finding the Extended Square

This algorithm finds the bounding box of the curve and creates a square that encompasses it entirely.

function findExtendedSquare(curve) {
  const minX = Math.min(...curve.map(p => p.x));
  const maxX = Math.max(...curve.map(p => p.x));
  const minY = Math.min(...curve.map(p => p.y));
  const maxY = Math.max(...curve.map(p => p.y));

  const centerX = (minX + maxX) / 2;
  const centerY = (minY + maxY) / 2;
  const size = Math.max(maxX - minX, maxY - minY);

  return [
    { x: centerX - size / 2, y: centerY - size / 2 },
    { x: centerX + size / 2, y: centerY - size / 2 },
    { x: centerX + size / 2, y: centerY + size / 2 },
    { x: centerX - size / 2, y: centerY + size / 2 },
  ];
}

This algorithm finds the bounding box of the curve and creates a square that encompasses it entirely.

Introduction

Welcome to the Inscribed Square Finder, an interactive tool that explores the fascinating world of geometry and mathematical conjectures.

This application allows you to draw closed curves and discover inscribed squares within them, bringing to life a century-old mathematical problem.

Key Concepts

Closed Curves

A closed curve is a continuous loop in a plane, like a circle or any shape that ends where it begins.

Inscribed Squares

An inscribed square is a square that fits perfectly inside a closed curve, with all four corners touching the curve.

Extended Squares

An extended square is the smallest square that completely encloses the closed curve.

Area Calculation

The area of the curve and squares are calculated using advanced geometric algorithms.

Curve Length

The total distance around the curve, measured in kilopixels.

How to Use

1

Select a drawing tool from the toolbar.

2

Draw a closed curve on the canvas.

3

Click 'Find Inscribed Square' to locate an inscribed square.

4

Click 'Find Extended Square' to find the enclosing square.

5

View the mathematical data for your curve and squares.

6

Use the 'Clear' button to start over with a new curve.

7

Experiment with different shapes and compare results!

Further Exploration

The inscribed square problem opens up many avenues for mathematical exploration:

Investigate how often perfectly circular curves yield inscribed squares.

Explore different algorithms for finding inscribed squares more efficiently.

Study the relationship between the area of the curve and its inscribed square.

Consider how this problem might extend to three dimensions with inscribed cubes.

Happy exploring, and may your mathematical curiosity never cease!

Created by Luis, web developer from Mexico

View source code