Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An axis - aligned rectangle can be represented by the position ( x , y of its upper left corner and its dimensions ( width

An axis-aligned rectangle can be represented by the position (x,y of its upper left corner and its dimensions (width and height). Figure 1 illustrates an axis-aligned rectangle in a Windows coordinate system where the x axis pointing to the right (East) and the y-axis pointing down (South).
rigure 1 : axis-digned reclange
According to the location of a point from an axis-aligned rectangle, the distance can be calculated as follows:
a) Point inside the rectangle: If the point lies within the boundaries of the rectangle, the distance is simply 0.
b) Point outside the rectangle: This requires considering the four edges of the rectangle and calculating the minimum distance between the point and each edge. The final distance is the minimum of these four distances.
Assume you are provided with a text file (data.txt) containing a number of text lines. The first line contains a comma separated list of 4 decimals representing respectively the position and the dimension of a given rectangle. The subsequent lines contain records for some points. Each point has two values x and y. Figure 2 shows a sample of data.txt file.
5.5,-10,20,30
00
6-10
12-15
3010
Figure 2: Sample of data.txt file
I
2. To Do:
Write a Java program that given an input file containing a given axis-aligned rectangle and some points, calculates the distances between the given rectangle and each of those points. The program should display a table which includes information about the given rectangle and the distances of the points that are outside the rectangle. For each point outside the rectangle indicate the edge (North, East, West, South) of the rectangle that has been used to calculate the distance. You program should display the number of points inside the rectangle. See the sample runs.
3. Additional requirements:
You can assume that there are no errors in the input file.
If the minimum distance between a point and two or more edges of a rectangle is equal, then select according to your choice one of these edges and consider it as the edge used to calculate the distance between the point and the rectangle.
A rectangle and a point objects are constructed only once. Then just update the location for each point using Point2D API methods.
Use the Point2D, Line2D and Rectangle2D API (java.awt) methods whenever is applicable.
Hints:
Browse the API Documentation to get familiar with the public interface of the following classes:
Point2D,
Line2D,
Rectangle2D,
String.
Notice that in the java.awt.geom package, the primary class that models a point is Point2D. The Point2D. Double class represents the point's coordinates with double precision. This apply to both segment (Line2D/Line2D. Double) and rectangle (Rectangle2D / Rectangle2D.Double).
No need to know how to calculate the distance between a point P and an arbitrary segment AB. There is a method in the class Line2D that calculates it. Look at it in the API documentation.
Sample runs
image text in transcribed

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

=+j Understand different types of regions in the world.

Answered: 1 week ago

Question

How is a formal contract different from a simple contract?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago