Skip to content

Many drawing tools, such as iPad, have a function that when you are drawing a shape by hand, they will guess what it is, and make the best fit one to replace it. For example, if you draw a lopsided circle, it will produce a perfect one for it. In this assignment, i do that using the magic from linear algebra.

Notifications You must be signed in to change notification settings

CSYangHsu/Perfecting-Your-Drawing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Perfecting-Your-Drawing

Many drawing tools, such as iPad, have a function that when you are drawing a shape by hand, they will guess what it is, and make the best fit one to replace it. For example, if you draw a lopsided circle, it will produce a perfect one for it. In this project, i do that using the magic from linear algebra.

Algorithm

The used algorithm is based on the least square method. For example, to fit a circle,
image
we need to find out what c1, c2 and r are so that
image
is minimum for the given data (x1, y1),(x2, y2), . . . ,(xm, ym).

The above problem is nonlinear, which is hard to solve. But we can approximate it by rewriting (1) with
image
for c3 = r^2 − (c1)^2 - (c2)^2  , and making c1, c2, c3 independent variables.

To transform the min f(c1,c2,c3) into matrix form.  Let
image,
The original problem is to solve an over-determinded system, Ax = b.
The problem is also called a least square problem, which can be solved by the normal equation (A^T) A x = (A^T) b.

Table of Contents

implement

Introduce

  • to find best fitting circle:
    uses "numpy.linalg.lstsq" to solve the least square problem.

  • to find best fitting ellipse:
    using least square algorithm with the formula
    " c1 x^2 + c2 xy + c3 y^2 + c4 x + c5 y = 1 ".
    The formula can actually fit all kinds of curves from conic section.

Demo for circle

  • example1:

Example screenshot11

Example screenshot12

  • example2:

Example screenshot11

Example screenshot12

  • example3:

Example screenshot11

Example screenshot12

Demo for ellipse

  • example1:

Example screenshot11

Example screenshot12

  • example2:

Example screenshot11

Example screenshot12

  • example3:

Example screenshot11

Example screenshot12

implement5

Introduce

  • find the minimum enclosing circle for the given points.

Demo

  • example1:

Example screenshot11

Example screenshot12

  • example2:

Example screenshot11

Example screenshot12

  • example3:

Example screenshot11

Example screenshot12

  • example4:

Example screenshot11

Example screenshot12

About

Many drawing tools, such as iPad, have a function that when you are drawing a shape by hand, they will guess what it is, and make the best fit one to replace it. For example, if you draw a lopsided circle, it will produce a perfect one for it. In this assignment, i do that using the magic from linear algebra.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages