-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertAndDraw.java
More file actions
125 lines (111 loc) · 3.46 KB
/
ConvertAndDraw.java
File metadata and controls
125 lines (111 loc) · 3.46 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
package com.purdue.LawsonNavigator;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.*; // For JPanel, etc.
import java.awt.*; // For Graphics, etc.
import java.awt.geom.*; // For Ellipse2D, etc.
import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
class ConvertAndDraw {
public static void main (String args[]){
System.out.printf("%d\n", xGPStoArray(-86.91722517212231));
System.out.printf("%d\n", yGPStoArray(40.4281221357864));
System.out.printf("%.20f\n", xArraytoGPS(1));
System.out.printf("%.20f\n",yArraytoGPS(5));
int startingX = 13;
int startingY = 10;
int []directionArray = {0, 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3};
int floor = 1;
lineDrawer(startingX, startingY, directionArray, floor);
}
public static int xGPStoArray(double x){
double x1 = -86.91724196076393;
double x2 = -86.91678866744041;
int xA = 27;
double xT = Math.abs(x1 - x2) / xA;
double xG = (x - x1) / xT;
return (int)Math.round(xG);
}
public static int yGPStoArray(double y){
double y1 = 40.42818497851696;
double y2 = 40.427418297204184;
int yA = 61;
double yT = Math.abs(y1 - y2) / yA;
double yG = Math.abs((y - y1) / yT);
return (int)Math.round(yG);
}
public static double xArraytoGPS(int x){
double x1 = -86.91724196076393;
double x2 = -86.91678866744041;
int xA = 27;
double xX = (double)x;
double xT = Math.abs(x1 - x2) / xA;
xX = x1 + (xT * xX);
return xX;
}
public static double yArraytoGPS(int y){
double y1 = 40.42818497851696;
double y2 = 40.427418297204184;
int yA = 61;
double yY = (double)y;
double yT = Math.abs(y1 - y2) / yA;
yY = y1 - (yT * yY);
return yY;
}
public static void lineDrawer(int startingX, int startingY, int directionArray[], int floor){
// Direction!!!!!!!
// 0
// 3 Current 1
// 2
//Floor : 0, 1, 2, 3;
int []dirY = {-1, 0, 1, 0};
int []dirX = {0, 1, 0, -1};
FileInputStream fis;
int x = 0, y = 0;
int xA = 27; // Image x, and y size
int yA = 69; // This is 69 cuz there was a title on the image and we ignored that part for griding part.
Graphics g = null;
BufferedImage image = null;
String fileName = "lwsn-" + floor + ".bmp";
try {
File originalImage = new File(fileName);
fis = new FileInputStream(originalImage);
image = ImageIO.read(fis);
x = image.getWidth();
y = image.getHeight();
} catch (Exception e) {
e.printStackTrace();
}
BufferedImage bi = new BufferedImage(x,y,BufferedImage.TYPE_INT_RGB);
bi = image;
g = bi.getGraphics();
x = x / xA; // One cell X size on the image
y = y / yA; // One cell Y size on the image
startingX = x * startingX;
startingY = y * startingY;
System.out.printf("%d, %d\n", x, y);
System.out.printf("%d, %d\n", startingX, startingY);
for (int i = 0; i < directionArray.length; i ++){
if (i == 0){
g.setColor( Color.BLUE );
} else if (i == directionArray.length - 1){
g.setColor( Color.GREEN );
} else{
g.setColor( Color.RED );
}
g.fillOval( startingX, startingY, 5, 5);
startingX = dirX[directionArray[i]] * x + startingX;
startingY = dirY[directionArray[i]] * y + startingY;
}
String outFileName = "out-" + floor + ".bmp";
try {
ImageIO.write(bi, "bmp",new File(outFileName));
} catch(Exception E){
System.err.println("Error writing output file");
E.printStackTrace();
}
System.out.println("At the end of lineDrawer");
}
}