-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup.java
More file actions
57 lines (49 loc) · 1.31 KB
/
Copy pathGroup.java
File metadata and controls
57 lines (49 loc) · 1.31 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
public class Group
{
public Point start;
public int theta; // in degrees
public int length;
public Group()
{
start = new Point();
theta = -1;
length = -1;
}
public Group(int r, int c, int theta, int length)
{
start = new Point(r, c);
this.theta = theta;
this.length = length;
}
public Point getStart()
{
return start;
}
public Point getEnd()
{
Point prev = new Point();
double hypo = 1.0f;
if ((theta / 45) % 2 == 1) hypo = Math.sqrt(2);
prev.r = start.r - (length-1)*(int)Math.round(hypo*Math.sin((theta)*Math.PI/180));
prev.c = start.c + (length-1)*(int)Math.round(hypo*Math.cos((theta)*Math.PI/180));
return prev;
}
public Point getPrevious()
{
Point prev = new Point();
double hypo = 1.0f;
if ((theta / 45) % 2 == 1) hypo = Math.sqrt(2);
prev.r = start.r - (int)Math.round(hypo*Math.sin((theta+180)*Math.PI/180));
prev.c = start.c + (int)Math.round(hypo*Math.cos((theta+180)*Math.PI/180));
return prev;
}
public Point getNext()
{
Point prev = new Point();
double hypo = 1.0f;
if ((theta / 45) % 2 == 1) hypo = Math.sqrt(2);
prev.r = start.r - length*(int)Math.round(hypo*Math.sin((theta)*Math.PI/180));
prev.c = start.c + length*(int)Math.round(hypo*Math.cos((theta)*Math.PI/180));
return prev;
}
}