Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a JJava program consisting of a single file that computes the convex hull of a set of points. Use the frame below Input should

Write a JJava program consisting of a single file that computes the convex hull of a set of points. Use the frame below

Input should be read from the terminal as a series of lines. The first line will contain a single integer n, indicating the number of points in the input set. Following this, the input contains exactly n more lines, each containing two, space-separated real numbers denoting the x and y coordinates of one point in the input set. Output should be written to the terminal as a series of lines. The first line should contain a single integer, denoting the number k of extreme points in the convex hull. Following that should be exactly k more lines, each unique, and each containing two integers, denoting the indices of two extreme points that are connected by an edge of the hull.

The following picture displays a sample of the running outcome.

image text in transcribed

import java.util.Scanner; import java.util.List; import java.util.ArrayList; class Pair { int one; int two; public Pair(int one, int two) { this.one = one; this.two = two; } } public class Hull { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); float[] x = new float[N]; float[] y = new float[N]; for (int i = 0; i  hullSegments = new ArrayList(); // TODO, implement the brute force algorithm System.out.println(hullSegments.size()); for (Pair p : hullSegments) { System.out.printf("%d %d ", p.one, p.two); } } } 
Hul /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk objc [68707] : Class JavaLaunchHelper is implemented 5 1 2 1 6 24 4.7 67 Process finished with exit code 0 From the input, you can see I entered 8 points. Their positions are shown in the following pic- ture. The boundary of the convex hull should be these line segments: (P1, P2), (P1, P6), (P2, P4), (P4, P7) and (P6, P7). P, (2,2) P. (0,1) P. (0,0) P, (1,0) P. (2,0) P, (0.5,-0.5) P. (0,-1) . P, (1,-1)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

What protocols comprise SSL?

Answered: 1 week ago

Question

What is something that makes you feel unstoppable?

Answered: 1 week ago