Giter Site home page Giter Site logo

dynamic-line-fitter's Introduction

Dynamic Line Fitter

Overview

The Dynamic Line Fitter application allows users to interactively add points on a blank canvas. As points are added, a line is dynamically fitted through all points based on their average position and slope. The application also includes controls to clear the board or delete the last point added.

Features

  • Add Points: Click on the canvas to add points.
  • Dynamic Line Fitting: A line is automatically adjusted to fit all points based on their average position and slope.
  • Clear Board: Button to remove all points and reset the canvas.
  • Delete Last Point: Button to remove the most recently added point.

How It Works

Mathematical Formula for Line Fitting

  1. Calculate Averages:

    • Compute the average of the x-coordinates x_c and the average of the y-coordinates y_c of all points:
    $$x_c = \frac{1}{n} \sum_{i=1}^{n} x_i$$ $$y_c = \frac{1}{n} \sum_{i=1}^{n} y_i$$
  2. Calculate Individual Slopes:

    • For each point, compute the slope (m_i) based on the average position:
    $$m_i = \frac{y_c - y_i}{x_c - x_i}$$

    where x_i and y_i are the coordinates of the i-th point.

  3. Average Slope:

    • Calculate the average slope m from the individual slopes:
    $$m = \frac{1}{n} \sum_{i=1}^{n} m_i$$
  4. Calculate Line Endpoints:

    • Determine the coordinates for the start and end of the line based on the canvas width and the average slope:
      • For the left side of the canvas:
    $$x_1 = 0$$ $$y_1 = m \cdot (x_1 - x_c) + y_c$$
    • For the right side of the canvas:
    $$x_2 = window.innerWidth$$ $$y_2 = m \cdot (x_2 - x_c) + y_c$$

Note

The mathematical approach used in this project for line fitting is a custom method developed for this specific application. Interestingly, this approach yields results that are equivalent to those produced by the least squares regression method, which is commonly used to determine the best-fitting line by minimizing the overall error between the line and all data points. Therefore, while this method is designed to fit lines dynamically based on user interaction, it effectively aligns with the principles of regression analysis.

dynamic-line-fitter's People

Contributors

ferhadmislim avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.