Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define MAP_WIDTH = 600;
- #define MAP_HEIGHT = 500;
- #define LEFT_LON = 14;
- #define RIGHT_LON = 24
- #define TOP_LAT = 55;
- #define BOTTOM_LAT = 49;
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- float get_distance(float, float, float, float);
- float get_weight(float, float);
- float transpose_data(float, float, int, int, float, float, float, float, float, float);
- float degree_width(int, float, float);
- float degree_height(int, float, float);
- struct coordinates {
- float longnitude;
- float latitude;
- };
- int main()
- {
- double input_data[3][3] = { {14,20.7,50.4},{12, 22.4,52.9}, {4, 17.5, 54.1} }; //sample imput data
- //transposition loop
- float deg_width = degree_width(600, 24, 14);
- float deg_height = degree_height(500, 55, 49);
- for (int i = 0; i < 3; i++) {
- transpose_data(input_data[i][1], input_data[i][2], 600, 500, 14, 24, 55, 49, deg_width, deg_height);
- }
- for (int l=0; l<600; l++) {
- for (int k = 0; k < 500; k++) {
- float value;
- float weight_sum = 0;
- float value_sum = 0;
- for (int i = 0; i < 3; i++) {
- float distance = get_distance(l, k, input_data[i][1], input_data[i][2]);
- if (distance != 0) {
- float weight = get_weight(distance, 2);
- weight_sum += weight;
- float single_value = weight*input_data[i][0];
- value_sum += single_value;
- }
- else {
- value = input_data[i][0];
- break;
- //if we stumble upon ZERO distance - immediately break the loop and set the value of same-point station
- }
- } // end of weight summarization
- value = value_sum / weight_sum;
- for (int i = 0; i < 3; i++) {
- }
- } //rows
- } // columns
- getchar();
- scanf("test");
- return 0;
- }
- float get_distance(float a1, float b1, float a2, float b2)
- {
- float distance = sqrt(pow((a2 - a1), 2) + pow((b2 - b1), 2));
- return(distance);
- }
- float get_weight(float distance, float power_parameter) {
- float weight = 1 / pow(distance, power_parameter);
- return weight;
- }
- float transpose_data(float longnitude, float latitude, int map_width, int map_height,
- float left_longnitude, float right_longnitude, float top_latitude, float bottom_latitude, float degree_width, float degree_height) {
- struct coordinates transposed;
- transposed.longnitude = (longnitude - left_longnitude)*degree_width;
- transposed.latitude = (top_latitude - latitude)*degree_height;
- return
- }
- float degree_width(int map_width, float right_longnitude, float left_longnitude) {
- float deg_width = map_width / (fabs(right_longnitude - left_longnitude));
- return deg_width;
- }
- float degree_height(int map_height, float top_latitude, float bottom_latitude) {
- float deg_height = map_height / (fabs(top_latitude - bottom_latitude));
- return deg_height;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement