GitXplorerGitXplorer
b

GrahamScan

public
38 stars
15 forks
0 issues

Commits

List of commits on branch master.
Verified
d26a2e6ad6c5a90a09f09780f572bfe0e4f1ad71

Update README.md

bbkiers committed 4 years ago
Verified
c3c47ccbc7d0ae4088c279e2e7cb7ab882b9e333

Merge pull request #3 from NamesAreAPain/patch-1

bbkiers committed 6 years ago
Verified
748c1a934eaa397350aaa3e0942604b0c84cc02a

Update build.xml to allow for jar compilation

NNamesAreAPain committed 7 years ago
Verified
2c4208adcec1b90a87dc149568f512ecf091a4a3

Merge pull request #2 from bkiers/feature/license-in-readme

bbkiers committed 7 years ago
Unverified
e288a053e9193958bc33e207ae8fd6a26dcb77b6

Added license file and mention in README

bbkiers committed 7 years ago
Unverified
9bd7901dea5cc315632d9fad004889b03bc83c3a

Update README.md

bbkiers committed 12 years ago

README

The README file for this repository.

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