# publicStanley/HeatMap

### Subversion checkout URL

You can clone with HTTPS or Subversion.

first working version

authored
24 src/Circle.scala
 ... ... @@ -0,0 +1,24 @@ 1 +import com.seisw.util.geom.PolySimple 2 + 3 +class Circle(x1: Double, y1: Double, z1: Int, r1: Double) { 4 + 5 + val z = if(z1 < 1) 1 else if(z1 > 100) 100 else z1 6 + val x = x1 7 + val y = y1 8 + val r = r1 9 + 10 + // Converts circle to a polygon 11 + def toPoly: PolySimple = { 12 + 13 + val count = 50 14 + val result = new PolySimple 15 + val step = 2 * Math.Pi / count 16 + 17 + for(i <- 1 to count){ 18 + val y1 = y + r * Math.cos(step*i) 19 + val x1 = x + r * Math.sin(step*i) 20 + result.add(x1, y1) 21 + } 22 + result 23 + } 24 +}
55 src/Geo.scala
 ... ... @@ -0,0 +1,55 @@ 1 +class Geo(n:Double, e:Double, s:Double, w:Double, points: List[Point]) { 2 + 3 + // Avg. speed in km/h 4 + val speed: Int = 4 5 + // Time limit in hours 6 + val limit: Float = 0.25f 7 + // Distance in kilometers 8 + val dist: Float = speed * limit 9 + 10 + // Sector width in km 11 + val width: Double = length((n+s)/2, w, (n+s)/2, e) + 2*dist 12 + // Sector height in km 13 + val height: Double = length(n, w, s, w) + 2*dist 14 + 15 + // Image width in pixels 16 + val image_width: Int = 1000 17 + // Image height in pixels 18 + val image_height: Int = (width / height * image_width).toInt 19 + 20 + val w_factor = (e - w) / width 21 + val h_factor = (n - s) / height 22 + println((e + w_factor*dist/2) +","+ (n ) +"), new GLatLng("+ (w + w_factor*dist/2) +","+ (s)) 23 + // pixels in km 24 + val factor: Double = image_width / width 25 + 26 + var circles: List[Circle] = points.map{ pkt => 27 + new Circle( distance_to(pkt.lng, e) + dist, distance_to(s, pkt.lat) + dist, pkt.mag, dist) 28 + } 29 + 30 + // Distance to given point in km 31 + def distance_to(lng:Double, lat:Double): Double = { 32 + length(s, e, lng, lat) 33 + } 34 + 35 + // Returns: "x, y, width, height" 36 + def viewbox: String = { 37 + 0 + ", " + 0 + ", " + height + ", " + width 38 + } 39 + 40 + // Returns length in kilometers from and to given points 41 + // Takes two points 42 + private def length(p1_lng: Double, p1_lat: Double, p2_lng: Double, p2_lat: Double): Double = { 43 + val r = 6371 44 + val to_rad = 3.142 / 180 45 + 46 + val d_lat = (p2_lat - p1_lat) * to_rad 47 + val d_lng = (p2_lng - p1_lng) * to_rad 48 + 49 + val a = Math.sin(d_lat / 2) * Math.sin(d_lat / 2) + 50 + Math.cos(p1_lat * to_rad) * Math.cos(p2_lat * to_rad) * 51 + Math.sin(d_lng / 2) * Math.sin(d_lng / 2) 52 + val c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) 53 + r * c 54 + } 55 +}
183 src/HeatMap.scala