GithubHelp home page GithubHelp logo

convex-hull's Introduction

Convex Hull

This project is trying to implement convex hull by using Graham's Scan Algorithm.

Convex Hull

Given a group of points, the set of convex hull is the smallest convex polygon that contain all the points. The example and the result of the program show as below:

File name: convex_hull_implementation.py
Command line: python convex_hull_implementation.py 

NOTE: 
  - the green dots are random points and the blue line is the "convex hull" of the points
  - the corner with no green dot is the start points, because for image the origin of coordinates 
    is on the top-left. Is the same as to find the bottommost + leftmost in the Coordinate System.

Graham's Scan Algorithm

Time Complexity: O(nlogn)

The process demo of Graham's scann show as below (from Wikipedia)

Part 1: sort the points

(a) Find the start points: This project find the (smallest x, smallest y) as start points.

(b) Sort the points: This project calculate angle(theta) to sort the points, if points have same angle use distance to sort.

NOTE: any sorting algorithm can apply to this part, this project using merge sort. 
      * time complexity O(nlogn)

Part 2: Algorithm to consider the point in convex set or not

(a) Select last two points(P1, P2) in convex hull and a points(P3).

(b) If (P2[0]-P1[0]) * (P3[1]-P1[1]) - (P2[1]P1[1]) * (P3[0]-P1[0]) <= 0, P2 is not in convex hull.

Code

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

convex-hull's People

Contributors

hank-tsou 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.