-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcod.txt
More file actions
168 lines (141 loc) · 5.62 KB
/
cod.txt
File metadata and controls
168 lines (141 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import static java.lang.Double.max;
import static java.lang.Math.min;
import static java.lang.StrictMath.cos;
import static java.lang.StrictMath.sin;
class Point
{
double x,y;
};
class Polygon1
{
Point vertices[]=new Point[50];
int number_of_vertices;
double cost;
};
public class scenario {
//rotate a polygon by angle degrees around a point p
Polygon1 rotate_by_angle(double angle, Polygon1 p)
{
float s = (float) sin(angle);
float c = (float) cos(angle);
for(int i=0; i<p.number_of_vertices; i++)
{
p.vertices[i].x= p.vertices[i].x*cos(angle)+ p.vertices[i].y*sin(angle);
p.vertices[i].y=- p.vertices[i].x*sin(angle)+ p.vertices[i].y*cos(angle);
}
return p;
}
Polygon1 translate_polygon(float nx, float ny, Polygon1 p)
{
for(int i=0; i<p.number_of_vertices; i++)
{
p.vertices[i].x=p.vertices[i].x+nx;
p.vertices[i].y=p.vertices[i].y+ny;
}
return p;
}
// Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
boolean onSegment(Point p, Point q, Point r)
{
if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) &&
q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y))
return true;
return false;
}
// To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
int orientation(Point p, Point q, Point r)
{
// See http://www.geeksforgeeks.org/orientation-3-ordered-points/
// for details of below formula.
double val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
if (val == 0) return 0; // colinear
return (val > 0)? 1: 2; // clock or counterclock wise
}
boolean doIntersect(Point p1, Point q1, Point p2, Point q2)
{
// Find the four orientations needed for general and
// special cases
int o1 = orientation(p1, q1, p2);
int o2 = orientation(p1, q1, q2);
int o3 = orientation(p2, q2, p1);
int o4 = orientation(p2, q2, q1);
// General case
if (o1 != o2 && o3 != o4)
return true;
// Special Cases
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
// p1, q1 and p2 are colinear and q2 lies on segment p1q1
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
return false; // Doesn't fall in any of the above cases
}
public static void main(String[] args)
{
try {
String room;
String furniture;
File file = new File("E:\\Year2Coursework\\scenario2\\src\\input.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
stringBuffer.append("\n");
}
fileReader.close();
System.out.println("Contents of file:");
System.out.println(stringBuffer.toString());
String[] lines = stringBuffer.toString().split("\\n");
int i=0;
for(String s: lines){
Polygon1 p=new Polygon1();
int nr_of_vert=0;
String parts_room[]=s.split("#");
room=parts_room[0];
System.out.println("Room = " + room);
String vertices_room[]=room.split(",");
for(String f:vertices_room)
{
double nr=0;
if(f.charAt(1)=='(')
{
String[] overlook_parant=f.split("\\(");
nr=Double.valueOf(overlook_parant[1]);
p.vertices[nr_of_vert].x=nr;
}
if(f.charAt(f.length()-1)==')')
{
String[] overlook_parant=f.split("\\)");
nr=Double.valueOf(overlook_parant[0]);
p.vertices[nr_of_vert++].y=nr;
}
System.out.println("Vertice x: "+ nr);
}
p.number_of_vertices=nr_of_vert-1;
furniture=parts_room[1];
System.out.println("Furniture = " + furniture);
for(Point a:p.vertices)
{
System.out.println(a.x +" "+ a.y);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}