Graham’s algorithm is used for finding a convex hull for a set of points.Assume Java’s coordinate system is used for the points. Implement the algorithmusing the following method:/** Return the points that form a convex hull */public static ArrayList<MyPoint> getConvexHull(double[][] s)MyPoint is a static inner class defined as follows:private static class MyPoint implements Comparable<MyPoint> {double x, y;MyPoint rightMostLowestPoint; MyPoint(double x, double y) {this.x = x; this.y = y;}public void setRightMostLowestPoint(MyPoint p) {rightMostLowestPoint = p;}@Overridepublic int compareTo(MyPoint o) {// Implement it to compare this point with point o// angularly along the x-axis with rightMostLowestPoint// as the center, as shown in Figure 22.10b. By implementing// the Comparable interface, you can use the Array.sort// method to sort the points to simplify coding.}}Write a test program that prompts the user to enter the set size and the points,and displays the points that form a convex hull. Here is a sample run: How many points are in the set? 6 ↵EnterEnter six points: 1 2.4 2.5 2 1.5 34.5 5.5 6 6 2.4 5.5 9 ↵EnterThe convex hull is(1.5, 34.5) (5.5, 9.0) (6.0, 2.4) (2.5, 2.0) (1.0, 2.4)
Graham’s
Assume Java’s coordinate system is used for the points. Implement the algorithm
using the following method:
/** Return the points that form a convex hull */
public static ArrayList<MyPoint> getConvexHull(double[][] s)
MyPoint is a static inner class defined as follows:
private static class MyPoint implements Comparable<MyPoint> {
double x, y;
MyPoint rightMostLowestPoint;
MyPoint(double x, double y) {
this.x = x; this.y = y;
}
public void setRightMostLowestPoint(MyPoint p) {
rightMostLowestPoint = p;
}
@Override
public int compareTo(MyPoint o) {
// Implement it to compare this point with point o
// angularly along the x-axis with rightMostLowestPoint
// as the center, as shown in Figure 22.10b. By implementing
// the Comparable interface, you can use the Array.sort
// method to sort the points to simplify coding.
}
}
Write a test program that prompts the user to enter the set size and the points,
and displays the points that form a convex hull. Here is a sample run:
How many points are in the set? 6 ↵Enter
Enter six points: 1 2.4 2.5 2 1.5 34.5 5.5 6 6 2.4 5.5 9 ↵Enter
The convex hull is
(1.5, 34.5) (5.5, 9.0) (6.0, 2.4) (2.5, 2.0) (1.0, 2.4)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)