Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.78 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define MAP_WIDTH = 600;
  3. #define MAP_HEIGHT = 500;
  4. #define LEFT_LON = 14;
  5. #define RIGHT_LON = 24
  6. #define TOP_LAT = 55;
  7. #define BOTTOM_LAT = 49;
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <math.h>
  12.  
  13. float get_distance(float, float, float, float);
  14. float get_weight(float, float);
  15. float transpose_data(float, float, int, int, float, float, float, float, float, float);
  16. float degree_width(int, float, float);
  17. float degree_height(int, float, float);
  18.  
  19. struct coordinates {
  20.     float longnitude;
  21.     float latitude;
  22. };
  23.  
  24. int main()
  25. {
  26.     double input_data[3][3] = { {14,20.7,50.4},{12, 22.4,52.9}, {4, 17.5, 54.1} }; //sample imput data
  27.    
  28.     //transposition loop
  29.  
  30.  
  31.  
  32.     float deg_width = degree_width(600, 24, 14);
  33.     float deg_height = degree_height(500, 55, 49);
  34.     for (int i = 0; i < 3; i++) {
  35.         transpose_data(input_data[i][1], input_data[i][2], 600, 500, 14, 24, 55, 49, deg_width, deg_height);
  36.     }
  37.    
  38.  
  39.     for (int l=0; l<600; l++) {
  40.         for (int k = 0; k < 500; k++) {
  41.  
  42.             float value;
  43.             float weight_sum = 0;
  44.             float value_sum = 0;
  45.             for (int i = 0; i < 3; i++) {
  46.  
  47.                 float distance = get_distance(l, k, input_data[i][1], input_data[i][2]);
  48.                 if (distance != 0) {
  49.                     float weight = get_weight(distance, 2);
  50.                     weight_sum += weight;
  51.  
  52.                     float single_value = weight*input_data[i][0];
  53.                     value_sum += single_value;
  54.                 }
  55.                 else {
  56.                     value = input_data[i][0];
  57.                     break;
  58.                     //if we stumble upon ZERO distance - immediately break the loop and set the value of same-point station
  59.                 }
  60.                
  61.             } // end of weight summarization
  62.  
  63.             value = value_sum / weight_sum;
  64.  
  65.  
  66.             for (int i = 0; i < 3; i++) {
  67.  
  68.             }
  69.         } //rows
  70.     } // columns
  71.  
  72.  
  73.  
  74.  
  75.     getchar();
  76.     scanf("test");
  77.     return 0;
  78. }
  79. float get_distance(float a1, float b1, float a2, float b2)
  80. {
  81.     float distance = sqrt(pow((a2 - a1), 2) + pow((b2 - b1), 2));
  82.     return(distance);
  83. }
  84.  
  85. float get_weight(float distance, float power_parameter) {
  86.     float weight = 1 / pow(distance, power_parameter);
  87.     return weight;
  88. }
  89.  
  90. float transpose_data(float longnitude, float latitude, int map_width, int map_height,
  91.     float left_longnitude, float right_longnitude, float top_latitude, float bottom_latitude, float degree_width, float degree_height) {
  92.  
  93.     struct coordinates transposed;
  94.     transposed.longnitude = (longnitude - left_longnitude)*degree_width;
  95.     transposed.latitude = (top_latitude - latitude)*degree_height;
  96.  
  97.     return
  98.    
  99. }
  100.  
  101. float degree_width(int map_width, float right_longnitude, float left_longnitude) {
  102.     float deg_width = map_width / (fabs(right_longnitude - left_longnitude));
  103.     return deg_width;
  104. }
  105.  
  106. float degree_height(int map_height, float top_latitude, float bottom_latitude) {
  107.     float deg_height = map_height / (fabs(top_latitude - bottom_latitude));
  108.     return deg_height;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement