Question

(Geometry: Graham's algorithm for finding a convex hull) Section 22.10.2 introduced Graham's algorithm for finding a convex hull for a set of points. Assume that the Java's coordinate system is used for the points. Implement the algorithm using the following method: /*t Return the points that form a convex hu17 */ public static Arraylist<MyPoint> getConvexHul1(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$; Goverride 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 potnts to stmplify 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:FIGURE CANT COPY

   (Geometry: Graham's algorithm for finding a convex hull) Section 22.10.2 introduced Graham's algorithm for finding a convex hull for a set of points. Assume that the Java's coordinate system is used for the points. Implement the algorithm using the following method:
/*t Return the points that form a convex hu17 */ public static Arraylist<MyPoint> getConvexHul1(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$;
Goverride
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 potnts to stmplify 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:FIGURE CANT COPY
Show more…
Introduction to Java Programming. Comprehensive Version
Introduction to Java Programming. Comprehensive Version
Y. Daniel Liang 10th Edition
Chapter 22, Problem 11 ↓

Instant Answer

verified

Step 1

Step 1: Define the MyPoint class as a static inner class with the necessary fields and methods as described in the problem statement.  Show more…

Show all steps

lock
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
(Geometry: Graham's algorithm for finding a convex hull) Section 22.10.2 introduced Graham's algorithm for finding a convex hull for a set of points. Assume that the Java's coordinate system is used for the points. Implement the algorithm using the following method: /*t Return the points that form a convex hu17 */ public static Arraylist<MyPoint> getConvexHul1(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$; Goverride 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 potnts to stmplify 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:FIGURE CANT COPY
Close icon
Play audio
Feedback
Powered by NumerAI
*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Orientation Test
The orientation test involves determining the relative position of three points to decide whether they form a left turn, a right turn, or are collinear. This test is essential in convex hull algorithms like Graham's, as it helps in deciding whether a point should be included in or excluded from the convex hull by checking if moving from one point to the next maintains a convex (usually left-turn) progression.
Polar Angle Sorting
Polar angle sorting is the process of ordering points based on the angle they make with a reference point, typically measured relative to the horizontal axis. This sorting is crucial in Graham's algorithm, as it arranges the points in the order they appear around the reference, allowing the algorithm to easily check and maintain the convexity of the hull as points are processed.
Java Comparable Interface
The Java Comparable interface is used to define a natural ordering for objects. In the context of implementing Graham's algorithm, it allows points to be sorted by their polar angles relative to a reference point. By overriding the compareTo method, developers ensure that the Array.sort or Collections.sort method can order the points properly, which is a critical step in the algorithm.
Convex Hull
A convex hull is the smallest convex polygon that encloses a set of points in the plane. It can be visualized as the shape formed by a rubber band stretched around the outermost points. In computational geometry, finding the convex hull is a fundamental problem with applications in pattern recognition, image processing, and collision detection.
Graham's Algorithm
Graham's algorithm is an efficient method for computing the convex hull of a finite set of points by sorting the points angularly and then iteratively processing them to remove those that do not contribute to the hull. The algorithm identifies a base or reference point (often the point with the lowest y-value) and sorts the other points by polar angle relative to this point, ensuring an organized traversal to detect and discard concave turns.

*

Recommended Videos

-
write-a-method-that-finds-the-convex-hull-of-a-set-of-points-your-method-is-to-be-implemented-using-the-approximate-hull-finding-method-described-in-lectures-the-bentley-preparata-faust-meth-00285

Write a method that finds the convex hull of a set of points. Your method is to be implemented using the approximate hull finding method described in lectures (the Bentley-Preparata-Faust method). Your method must have the following form: public static Polygon2D getHull(Point2D[] points, int numStrips, boolean draw) { .. } The space between the min-x and max-x points in the input set of points should be split into numStrips strips, with all strips being equal width. Your algorithm should find the min-y and max-y points in each strip and then implement Graham Scan to find the convex hull of the set of all min-y/max-y points. The min-x and min-y points should also be included in the input set to Graham Scan. Your method should also take a Boolean draw parameter. If draw is true, your method should draw the input points, the strips, the min-x and max-x points, the min-y and max-y points in each strip and the final convex hull solution.

Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Join the community

18,000,000+

Students on Numerade


Trusted by students at 8,000+ universities

Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever