--- /dev/null
+#include <string>
+#include <stdlib.h>
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <math.h>
+#include <vector>
+
+// konstanta PI
+#define PI 3.14159265
+
+// krok laseru (rozliseni)
+#define RESOLUTION 0.331
+
+// presnost (v procentech)
+//#define ACCURACY 3
+
+using namespace std;
+
+// definice datoveho typu Point
+typedef struct {double x,y;} Point;
+
+// vypocet primek
+void detect_line(vector<int> &input_date, vector<Point> &kartez, vector<Point> &lines, double eps) {
+
+ // pomocny bod
+ Point point;
+
+ // uhel polarni souradnice fi
+ double fi;
+
+ // zmerena vzdalenost
+ int r;
+
+ // vypocet kartezskych souradnic
+ for (int i = 0; i < input_date.size()-1; i +=2) {
+ r = (input_date[i+1] <= 19) ? 0 : input_date[i+1];
+ fi = (RESOLUTION * input_date[i] - 45) * PI/180;
+
+ point.x = r * cos(fi);
+ point.y = r * sin(fi);
+
+ point.x = (point.x == -0) ? 0 : point.x;
+ point.y = (point.y == -0) ? 0 : point.y;
+
+ kartez.push_back(point);
+ }
+
+ // hledani primek (usecek) pomoci smeroveho vektoru a obecne rovnice primky
+ // obecna rovnice: ax + by + c = 0
+
+ // parametr c
+ double c;
+
+ // normalovy vektor a posledni bod nalezici primce
+ Point n_vector, end_point;
+
+ // temp
+ bool tmp = true;
+
+ // primka
+ double line;
+
+ for (int i = 0; i < kartez.size()-1; i++) {
+
+ cout << "BOD: "<< kartez[i].x << " " << kartez[i].y << endl;
+
+ if (kartez[i].x == 0 && kartez[i].y == 0) {
+ tmp = true;
+ continue;
+ }
+
+ if (tmp) {
+ cout << "nova primka: ";
+ lines.push_back(kartez[i]);
+
+ end_point = kartez[i+1];
+
+ n_vector.x = -1 * (kartez[i+1].y - kartez[i].y);
+ n_vector.y = 1 * (kartez[i+1].x - kartez[i].x);
+
+ c = -1*n_vector.x*kartez[i].x - n_vector.y*kartez[i].y;
+
+ cout << "nx: " << n_vector.x << " ny: " << n_vector.y << " c: " << c << endl;
+
+ i++;
+ tmp = false;
+ } else {
+ cout << "dalsi bod na primce?: nx: " << n_vector.x << " ny: " << n_vector.y << " c: " << c << endl;
+
+ line = n_vector.x*kartez[i].x + n_vector.y*kartez[i].y + c;
+
+ cout << "odchylka: " << line << endl;
+
+ if (line < (0+eps) && line > (0-eps)) {
+ end_point = kartez[i];
+
+ cout << "ANO: X:" << end_point.x << " Y: " << end_point.y << endl;
+
+ } else {
+ cout << "4" << endl;
+ lines.push_back(end_point);
+
+ cout << "NE: X:" << end_point.x << " Y: " << end_point.y << endl;
+
+ tmp = true;
+ }
+ }
+ cout << endl;
+ }
+}
+
+int main(int argc, char** argv) {
+
+ // kontrola vstupniho argumentu
+ if (argc < 3) {
+ cout << "Chyby vstupni soubor." << endl;
+ return 1;
+ }
+
+ // vector vstupnich dat
+ vector<int> input_date;
+
+ // vector kartezskych souradnic
+ vector<Point> kartez;
+
+ // vector zjistenych primek
+ vector<Point> lines;
+
+ // odchylka bodu od primky
+ double eps = atof(argv[2]);
+
+ // nacteni vstupniho souboru - mapy
+ ifstream infile (argv[1], ios_base::in);
+
+ string line; // radek vstupniho souboru
+ int number; // cislo prectene ze souboru
+ int size_line; // pocet znaku na radku
+
+ while (getline(infile, line, ',')) {
+ if (line != "\n") {
+ stringstream strStream(line);
+ strStream >> number;
+ input_date.push_back(number);
+ }
+ }
+
+ detect_line(input_date, kartez, lines, eps);
+
+ // ulozeni do souboru
+ FILE *file = fopen("output_data","w");
+/*
+ for (int i = 0; i < kartez.size(); i += 1)
+ fprintf(file, "%f, %f\n", kartez[i].x, kartez[i].y);
+*/
+ for (int i = 0; i < lines.size(); i += 1)
+ fprintf(file, "%f, %f\n", lines[i].x, lines[i].y);
+
+ fclose(file);
+
+ return 0;
+}
+