-
Notifications
You must be signed in to change notification settings - Fork 0
/
SprioGenerator.java
58 lines (40 loc) · 1.7 KB
/
SprioGenerator.java
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
import java.util.Map;
import java.util.TreeMap;
public class SprioGenerator
{
public static void main(String[] args){
// Declaring the parameters for calling SpiroPoint function
double scale = 0.0001;
int nRev = 17;
int R = 8;
int r = 1;
int a = 4;
// Declaring the center around which the spirograph is to be created
TreeMap<String, java.lang.Double> SGM123 = new TreeMap<String, java.lang.Double>();
SGM123.put("latitude", 34.021160099);
SGM123.put("longitude", -118.2891709 );
// As the loop traverses, it prints the longitude,latitude values of the points which together form a SpiroGraph.
for (double t = 0; t < Math.PI * nRev; t += 0.1) {
Map<String, java.lang.Double> point = SpiroPoint(scale, R, r, a, t, SGM123);
System.out.println(point.get("longitude") + "," + point.get("latitude"));
}
}
/**
* Function to compute Spirograph Points
* @param scale scaling parameter to scale the graph
* @param R Large Circle Radius
* @param r Small Circle Radius
* @param a Height
* @param t Angle
* @param center
* @return TreeMap with latitude and longitude values.
*/
public static Map<String, java.lang.Double> SpiroPoint(double scale, int R, int r, int a, double t, TreeMap<String, java.lang.Double> center) {
double lat = center.get("latitude") + scale * ((R+r) * Math.cos(((double) r/R)*t) - a * Math.cos((1+((double) r/R))*t));
double lng = center.get("longitude") + scale * ((R+r) * Math.sin(((double) r/R)*t) - a * Math.sin((1+((double) r/R))*t));
Map<String, java.lang.Double> spiroPoint = new TreeMap<String, java.lang.Double>();
spiroPoint.put("latitude", lat);
spiroPoint.put("longitude", lng);
return spiroPoint;
}
}