Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MA117 Programming for Scientists: Project 1

2022

MA117 Project 1: Circles on a Plane

1     Formulation of the Problem

This assignment focuses  neither on  mathematical/modelling  issues  nor on  any  advanced techniques  in scientific computing. It will test your ability to write a simple Java code consisting of a few classes and manipulate  simple  data  structures.  Remember that  marks  are  available for  properly  documenting  and structuring your code.

You are given a set of data stored in a text (ASCII) file. Each line in this file stores  3 real numbers that represent:

•  the coordinates () of a point in the plane and

•  a radius  of the circle with the centre at that point.



Hence each line in the file represents a circle in the plane. Your task is to write a code which will analyse this set of circles. The number of lines in the file is 40 ≤   ≤  5000 .  The statistical analysis required in this step is very simple and does not require any sophisticated techniques. The information you want to extract from this set of data is:

1.  The number of circles in the set. When reading the description of circles from the file you will need to ignore those circles which are “singular”, i.e., those for which the radius is equal to zero, within a certain tolerance (described below). However, you will not need to check whether two circles might be identical. Also, you may assume that the data in the file are in a proper format, so you do not need to perform any additional checks to, for example, check for an incorrect number of points per line.

2.  The largest ( max) and the smallest () area of a circle in the file.

3.  The average area of a circle,   =  ∑      (where  is the area of the th non-singular circle in the data file).

4.  The standard deviation of area; i.e., compute                                               

 = √ ∑(  − )2  = √( ∑ ) − 2

5.  The median of the areas; i.e. the value  such that, if the areas are ordered in ascending order, half of them are larger than  , and the other half are smaller. If there is an even number of values in the set, then the median is usually defined as the average of the two elements in the middle. For example, the median of the set {1,7,3,5,3} is 3, and the median of {1,2,6,5} is 3.5.

6.  A single axis-aligned bounding rectangle around the tenth (non-singular) and twentieth (non-singular) circle in the set of data. The rectangle should be reported as 4 values: 1, 1, 2, 2 . The origin (1, 1) is the position of the rectangle’s bottom left corner.  The rectangle’s sides will touch the edges of the circles such that:                                                                                   (2, 2)

 

(1, 1)

 

2     Programming Instructions, classes in your code and hints

The code will be structured in an object-oriented manner. Hence one class, Circle, will describe the circle. To break the description down further, it will use another class, Point, and a real number that defines the radius.

Just as in Project 0, the files provided on the course webpage have some predefined methods which are either complete or have names and parameters. You must keep the names and types of all public objects, methods, parameters and return types as they are in the templates. The files define the three basic classes for your project.


•  Point.java which represents points () ∈  ℝ2;

•  Circle.java to represent a circle using a Point and a radius ;

•  Project1.java in which you will use Circle and Pointto process the data file.

•  student.data contains the data set you are supposed to analyse. This file is rather large so for testing you may want to experiment with your own smaller data set, which may also allow you to test different aspects of your code.

•  You can create such a file easily in any text editor (but not a word processor). Each circle is defined on a single line in this file, and it contains three numbers: coordinates   ,   , and the radius  .

•  All decimal values should be formatted to 9 decimal places (i.e. %.9f)

Finally, there is the file ReadFile.java, which is not explicitly part of Project 1. It is a piece of example code which documents using the Scanner class to read in the data from a file and find the maximum and minimum of that data. You should not submit it.

2.1       The Point class

The Point class will contain:

1.  private variables double X, Y, that store the co-ordinates of the point represented by an instance of this class.

2.  All of the standard methods that we identified in the previous exercises as necessary for usual classes of the similar type. In particular: constructors, setters, getters, converters, and the method equals which allows us to compare two Points.

In  particular,  the  comparison  between  two  points  is  important,  and  different  from  the  usual mathematical notion of equality. Due to the way that floating point numbers are stored in computer memory, we never usually test whether two floating point numbers are equal; just whether they are ‘close’ to within an arbitrarily chosen tolerance. You should have seen examples of this in the week 13 lab notes.

Given two points (1, 1) and (2, 2) we say that they are equal in our model if and only if |1  − 2 | ≤ Δ and  |1 − 2 | ≤ Δ . The  quantity ∆ is  named  GEOMTOL in the  Point  class  and  it  is  defined  as public, final and static. In your computations the value of this variable should be 10−6 .

Moreover, whenever you test for equality that involves two of the geometric objects in this project, you will allow for the tolerance ∆ . For example, to test that the distance between two points () is equal to a certain value  you would evaluate |( , )  −  |  ≤  ∆ .

3.  Implement the  method  distance that  computes the  Euclidean distance  between two  points   = (1, 1) and   =  (2, 2), which is defined as

() =  

4.  You can, and in fact should, also include a tester (as the method main) for the methods as usual. See week 14 lecture notes for more information on this.

2.2       The Circle class

While the methods in the class Point are rather standard, for the class which defines instances for circles you need to do more work.

1.  You should start by defining two private variables: Point A and double r which store the centre and the radius of the circle.

2.  You then have to define all standard method as above in the class Point, i.e., constructors, setters, getters and converters.  Read carefully instructions in the file  Circle.java as they explain the names of each of these methods, along with their expected behaviour.

3.  The method equalsthat compares two circles. Obviously, two circles are equal if they have identical (within the tolerance ∆) centres and radii.

The  core  of this  class  are  methods that  actually  implement functions  needed for the  circles.  In particular, in this exercise you will need the area method: area simply computes and returns the area of the circle.

2.3         The Project1 class

This class will perform the statistical analysis of the data and should produce the results you are asked to perform in the formulation. You must design and implement the core method results and some additional methods which will calculate all the quantities outlined in the formulation above. The results method takes the argument fileName, which contains the name of the file from which the data will be entered. An example how to read the data from the given file is provided in a file ReadData.java, which suggests how you can read data from the start of a file until the end of the file.

Within results, you should not print anything to the screen with  System.out.println. Instead, you should store the results in the predefined public variables at the top of the class:

•  int circleCounter: The number of (non-singular) circles in the file.

•  double [] aabb: The 4 doubles representing 1, 1, 2, 2 of the axis-aligned bounding box.

•  double

•  double

•  double

Smax: The maximum area  .

Smin: The minimum area  .

areaAverage: The average area µ .

•  double areaSD: The standard deviation of the areas.

•  double areaMedian: The median of the areas.

Remember: do not to change the names or types of any of these variables.

Hint: While most of the implementation is straightforward, one task requires a bit more algorithmic thinking. Let  with 0  ≤    <   be an increasing sequence (  + 1  ≥    , ∀) which represents a data set which is sorted. Then the median  =  −1  if  is odd or  =  ( −1  + )  if  is even. Hence you will need to

2                                                                                     2                         2

store areas of entered circles into an array and then sort the array. We will cover this topic in week 16, but you should try and figure this out for yourself first!

 

3     Submission

You should submit the files Project1.java, Circle.javaand Point.java usingTabula. Before you submit, test that all your methods work properly (use the main method within each class) and that the results method computes correct results when tested on a smaller file of your own input data. Make sure to include main () in the class Project1 which should call the results () method and print the results stored in the public variables of an instance of the Project1 method. You should not submit the data file student.data or the example code ReadData.java.

The BOSS automate marking system will use student.data and an unseen set of data to test fully all aspects of your solution.