-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputeAngle.java
More file actions
34 lines (28 loc) · 916 Bytes
/
Copy pathcomputeAngle.java
File metadata and controls
34 lines (28 loc) · 916 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
//declarations
int above = 0;
int below = 0;
double inverseSlope = -1/slope;
//for each pixel, check if above or below slope perpendicular
for (int i = 0; i < connectedPixels.length; ++i) {
for (int j = 0; j < connectedPixels[0].length; ++j) {
int x = j - col;
int y = row - i;
if ( y >= inverseSlope*x && connectedPixels[i][j] == true && i != row && j != col) {
++above;
} else if ( y < inverseSlope*x && connectedPixels[i][j] == true && i != row && j != col) {
++below;
}
}
}
//calculate initial angle
double angle = Math.atan(slope);
//refine angle
if ((angle > 0 && below>above) || (angle < 0 && below < above) ) {
angle += Math.PI;
} else if (slope == Double.POSITIVE_INFINITY && above>below) {
angle = Math.PI/2;
} else if (slope == Double.POSITIVE_INFINITY && above<below) {
angle = -Math.PI/2;
}
return angle;
}