/**
* Project 2 - Term II 2002
*
* @author Mark Wallington (m.wallington@warwick.ac.uk)
* student no: 0620929
*/
/*************************************************************
*
* This file is a template which should be modified to be
* fully functional
*
* Follow the instructions below. The names of methods typed
* explicitly in this class must be kept as defined.
*
*************************************************************/
public class Project2 {
// The names of these instance variables should not be modified
// Enter comments which explain what results they store.
final static int HistogramSize=10;
public int segmentCounter=0;
public int passOriginCounter;
public double maxlength=0.0;
public double minlength=0.0;
public double maxangle=0.0;
public double minangle=0.0;
public double [] distribution = new double[HistogramSize];
// define a private variable that stores number of
// intersecting pairs
private int intersectCounter=0;
public Project2() {
// constructor for the class, does not need any modifications
}
/*****************************************************************
*
* Results - this is the core methods which should perform
* all tasks required in the formulation of the project
*
* @param String FileName - the name of the input file
*
*****************************************************************
*/
public void Results(String FileName){
// you have to implement the method here
// it should read the data and then perform all tasks necessary
// for computing (and storing in the instance variables) information
// about the data set (as required by the formulation of the project)
/*--------------------------------------------------
* A suggested simple and straightforward
* structure of the code here
* 1/ read data from the file
* say MaInput F1 = new MaInput(FileName);
* in the loop compute
* segmentCounter, passOriginCounter
* maxlength, minlength, maxangle = -1.0,
* minangle, distribution[]
* 2/ close the input (e.g. by using F1=null)
* 3/ knowing number of segments to be entered
* define an array of segments (of that given size)
* 4/ read the file again into this array
* 5/ go through the pairs in the array and check
* whether they intersect. Be careful not to count
* intersections twice
*
*-----------------------------------------------------
*/
MaInput F1 = new MaInput("test.data");
double Ax=0.0, Ay=0.0, Bx=0.0, By=0.0;
while (!F1.atEOF()) {
Ax = F1.readDouble();
Ay = F1.readDouble();
Bx = F1.readDouble();
By = F1.readDouble();
if ( Math.abs(Ax - Bx) >= Point.GEOMTOL && Math.abs(Ay - By) >= Point.GEOMTOL) {
segmentCounter++;
LineSegment L = new LineSegment(Ax, Ay, Bx, By);
if (L.passOrigin()) passOriginCounter++;
if (L.segmentLength() - maxlength >= Point.GEOMTOL)
maxlength = L.segmentLength();
if (L.segmentLength() - minlength <= Point.GEOMTOL)
minlength = L.segmentLength();
if (L.segmentAngle() - maxangle >= Point.GEOMTOL)
maxangle = L.segmentAngle();
if (L.segmentAngle() - minangle <= Point.GEOMTOL)
minangle = L.segmentAngle();
if (L.segmentAngle() >= 0.0 && L.segmentAngle() <= 18.0) distribution[0]++;
if (L.segmentAngle() > 18.0 && L.segmentAngle() <= 36.0) distribution[1]++;
if (L.segmentAngle() > 36.0 && L.segmentAngle() <= 54.0) distribution[2]++;
if (L.segmentAngle() > 54.0 && L.segmentAngle() <= 72.0) distribution[3]++;
if (L.segmentAngle() > 72.0 && L.segmentAngle() <= 90.0) distribution[4]++;
if (L.segmentAngle() > 90.0 && L.segmentAngle() <= 108.0) distribution[5]++;
if (L.segmentAngle() > 108.0 && L.segmentAngle() <= 126.0) distribution[6]++;
if (L.segmentAngle() > 126.0 && L.segmentAngle() <= 144.0) distribution[7]++;
if (L.segmentAngle() > 144.0 && L.segmentAngle() <= 162.0) distribution[8]++;
if (L.segmentAngle() > 162.0 && L.segmentAngle() <= 180.0) distribution[9]++;
}
}
for ( int a=0; a<=9; a++)
distribution[a] = distribution[a]/segmentCounter;
LineSegment [] segments = new LineSegment [segmentCounter];
F1 = null;
F1 = new MaInput("test.data");
while (!F1.atEOF()) {
for ( int i=0; i<segmentCounter; i++ ) {
Ax = F1.readDouble();
Ay = F1.readDouble();
Bx = F1.readDouble();
By = F1.readDouble();
if ( Math.abs(Ax - Bx) > Point.GEOMTOL && Math.abs(Ay - By) > Point.GEOMTOL)
segments[i] = new LineSegment( Ax, Ay, Bx, By);
}
}
for ( int n=0; n<segmentCounter; n++) {
for ( int m=n+1; m<segmentCounter; m++) {
if (segments[n].intersectSegment(segments[m])) intersectCounter++;
}
}
F1 = null;
}
/*****************************************************************
*
* getNumberIntersectingSegments() - getter that allows the user
* to obtain the number of
* intersecting pairs that are stored in a
* private variable of this class
*
* @param none
*
*****************************************************************
*/
public int getNumberIntersectingSegments(){
return intersectCounter;
}
public static void main(String args[]) {
// You should enter your own tester of the methods in this
// class here
Project2 tester = new Project2();
tester.Results("test.data");
//int t = tester.getNumberIntersectingSegments();
System.out.println("Information about the segments:");
System.out.println(" Number of segments: " +tester.segmentCounter);
/*System.out.println(" Number of lines passing through zero: " +passOriginCounter);
System.out.println(" Number of intersecting segments: " +t);
System.out.println(" Max length: " +MaF.dF(maxlength, 6, 2));
System.out.println(" Min length: " +MaF.dF(minlength, 6, 2));
System.out.println(" Max angle: " +MaF.dF(maxangle, 6, 2));
System.out.println(" Min angle: " +MaF.dF(minangle, 6, 2));
System.out.println(" Angle (in deg) distribution:");
System.out.println(" [0.0, 18.0] : " +MaF.dF(distribution[0], 5, 3));
System.out.println(" [18.0, 36.0] : " +MaF.dF(distribution[1], 5, 3));
System.out.println(" [36.0, 54.0] : " +MaF.dF(distribution[2], 5, 3));
System.out.println(" [54.0, 72.0] : " +MaF.dF(distribution[3], 5, 3));
System.out.println(" [72.0, 90.0] : " +MaF.dF(distribution[4], 5, 3));
System.out.println(" [90.0, 108.0] : " +MaF.dF(distribution[5], 5, 3));
System.out.println(" [108.0, 126.0] : " +MaF.dF(distribution[6], 5, 3));
System.out.println(" [126.0, 144.0] : " +MaF.dF(distribution[7], 5, 3));
System.out.println(" [144.0, 162.0] : " +MaF.dF(distribution[8], 5, 3));
System.out.println(" [162.0, 180.0] : " +MaF.dF(distribution[9], 5, 3)); */
}
}
I have now adjusted the code to the above following some advice from elsewhere, but I get the following error message on running the program:
Help would be much appreciated, thanks.