Code Monkey home page Code Monkey logo

grahamscan's Introduction

Graham Scan

A Java implementation of the Graham Scan algorithm to find the convex hull of a set of points.

How to use it

The implementation is pretty straight forward: everything resides in a single class (GrahamScan). Simply copy the class in your project, and invoke either GrahamScan#getConvexHull(int[], int[]):

// x coordinates
int[] xs = {3, 5, -1, 8, -6, 23, 4};

// y coordinates
int[] ys = {9, 2, -4, 3, 90, 3, -11};

// find the convex hull
List<java.awt.Point> convexHull = GrahamScan.getConvexHull(xs, ys);

for(java.awt.Point p : convexHull) {
    System.out.println(p);
}

or the method GrahamScan#getConvexHull(List<java.awt.Point>):

// the same points as the previous example
List<java.awt.Point> points = Arrays.asList(
        new java.awt.Point(3, 9),
        new java.awt.Point(5, 2),
        new java.awt.Point(-1, -4),
        new java.awt.Point(8, 3),
        new java.awt.Point(-6, 90),
        new java.awt.Point(23, 3),
        new java.awt.Point(4, -11)
);

// find the convex hull
List<java.awt.Point> convexHull = GrahamScan.getConvexHull(points);

for(java.awt.Point p : convexHull) {
    System.out.println(p);
}

both of which will print the following:

java.awt.Point[x=4,y=-11]
java.awt.Point[x=23,y=3]
java.awt.Point[x=-6,y=90]
java.awt.Point[x=-1,y=-4]
java.awt.Point[x=4,y=-11]

And/or have a look at the unit tests.

License

MIT

grahamscan's People

Contributors

bartkiers avatar bkiers avatar namesareapain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

grahamscan's Issues

Add License

Would you be able to add a License to the project, so others can use it? As it seems, you want everyone to just use the cide as they want, so how about licensing it under the MIT-License https://opensource.org/licenses/MIT ? That would be great!

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.