-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLine.java
More file actions
42 lines (34 loc) · 940 Bytes
/
MyLine.java
File metadata and controls
42 lines (34 loc) · 940 Bytes
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
public class MyLine implements Comparable<MyLine>
{
MyPoint point1;
MyPoint point2;
double slope;
public MyLine(MyPoint local_point1, MyPoint local_point2)
{
point1 = local_point1;
point2 = local_point2;
calculateSlope();
}
public void calculateSlope()
{
slope = (point2.y - point1.y) / (point2.x - point1.x);
}
@Override
public int compareTo(MyLine o)
{
//System.out.println("Measuring from " + slope + " to " + o.slope);
//System.out.println("The answer is " + (int) ((slope - o.slope)*100));
return (int) ((slope*100 - o.slope*100));
}
public Boolean isItClockwise(MyLine o)
{
double point1_x_after = point2.x - point1.x;
double point1_y_after = point2.y - point1.y;
double point2_x_after = o.point2.x - o.point1.x;
double point2_y_after = o.point2.y - o.point1.y;
if(point1_y_after * point2_x_after < point1_x_after * point2_y_after)
return false;
else
return true;
}
}