0% found this document useful (0 votes)
3 views6 pages

New

The document contains a C++ program that processes input data from a file to analyze geometric patterns and angles between points. It defines several structures to hold point coordinates and results, reads input data, computes angles and distances, and outputs results based on certain conditions. The program uses nested loops to evaluate combinations of points and determine the best matches based on calculated angles and distances.

Uploaded by

S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

New

The document contains a C++ program that processes input data from a file to analyze geometric patterns and angles between points. It defines several structures to hold point coordinates and results, reads input data, computes angles and distances, and outputs results based on certain conditions. The program uses nested loops to evaluate combinations of points and determine the best matches based on calculated angles and distances.

Uploaded by

S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <iostream>

#include <cmath>
#include <fstream>
using namespace std;
struct pattern {

int x;
int y;
double dl;

};

struct kucha {
int x;
int y;

};

struct ans {
int x;
int y;
double an;
double dl;

};

int main() {
ifstream fin;
fin.open("inp.txt");
int vet = 0;
int back[1000][3];
int found = 0;
int n = 0;
int m = 0;
double scal = 0;
double dl1 = 0;
double dl2 = 0;
double tt = 0;
fin >> n;

pattern *pat = new pattern[n];


double *angle = new double[n - 2];
for (int i = 0; i < n; i++)
{
fin >> pat[i].x >> pat[i].y;
}
fin >> m;
ans *an = new ans[m];
for (int i = 0; i < m; i++)
{
an[i].x = -100;
an[i].y = -100;
}

kucha *kuch = new kucha[m];


for (int i = 0; i < m; i++) {
fin >> kuch[i].x >> kuch[i].y;
}

bool endd = 1;

for (int i = 0; i < n - 2; i++) {

scal = (pat[i].x - pat[i + 1].x)*(pat[i + 2].x - pat[i + 1].x) +


(pat[i].y - pat[i + 1].y)*(pat[i + 2].y - pat[i + 1].y);
dl1 = abs(sqrt(((pat[i].x - pat[i + 1].x)*(pat[i].x - pat[i + 1].x)) +
((pat[i].y - pat[i + 1].y)*(pat[i].y - pat[i + 1].y))));
dl2 = abs(sqrt(((pat[i + 2].x - pat[i + 1].x)*(pat[i + 2].x - pat[i +
1].x)) + ((pat[i + 2].y - pat[i + 1].y)*(pat[i + 2].y - pat[i + 1].y))));
tt = scal / (dl1*dl2);
angle[i] = acos(tt)* 57.2958;
}
for (int i = 0; i < n - 1; i++)
{
pat[i].dl = abs(sqrt(((pat[i].x - pat[i + 1].x)*(pat[i].x - pat[i +
1].x)) + ((pat[i].y - pat[i + 1].y)*(pat[i].y - pat[i + 1].y))));

}
int ug = 0;
double ddl = 0;
double ddll = ddl;
again:;
bool rd = 1;
int lastsave1 = -1;
int lastsave2 = -1;
int lastsave3 = -1;
int ff = 0;
bool wtf = 0;
int save1 = -1;
int zap = 0;
int save2 = -1;
int save3 = -1;
for (int i = 0; i < m; i++) {
an[i].dl = 100000;
an[i].an = 10000;
}

int se = 0;

/* for (int j = 0; j < m; j++) {


for (int z = 0; z < m; z++) {
for (int t = 0; t < m; t++) {
if (t != j && t != z && z!= j) {
scal = (kuch[j].x - kuch[z].x)*(kuch[t].x -
kuch[z].x) + (kuch[j].y - kuch[z].y)*(kuch[t].y - kuch[z].y);
dl1 = abs(sqrt(((kuch[j].x -
kuch[z].x)*(kuch[j].x - kuch[z].x)) + ((kuch[j].y - kuch[z].y)*(kuch[j].y -
kuch[z].y))));
dl2 = abs(sqrt(((kuch[t].x -
kuch[z].x)*(kuch[t].x - kuch[z].x)) + ((kuch[t].y - kuch[z].y)*(kuch[t].y -
kuch[z].y))));
tt = scal / (dl1*dl2);
if (((abs(angle[se] - acos(tt) * 57.2958)) <
abs(angle[se] - an[j].an)) && (abs(pat[se].dl / pat[se + 1].dl - (dl1 / dl2)) <
abs(pat[se].dl / pat[se + 1].dl - (an[se].dl / an[se+1].dl)))) {
an[se].dl = dl1;
an[se + 1].dl = dl2;
an[se].an = acos(tt) * 57.2958;
an[se].x = kuch[j].x;
an[se].y = kuch[j].y;
an[se + 1].x = kuch[z].x;
an[se + 1].y = kuch[z].y;
an[se + 2].x = kuch[t].x;
an[se + 2].y = kuch[t].y;
cout << j << " " << z << " " << t <<
endl;
se++;

}
}
}
}
}*/

for (int i = 0; i < m; i++) {


for (int j = 0; j < m; j++) {
for (int z = 0; z < m; z++) {
if (z != i && z != j && j != i) {

scal = (kuch[i].x - kuch[j].x)*(kuch[z].x -


kuch[j].x) + (kuch[i].y - kuch[j].y)*(kuch[z].y - kuch[j].y);
dl1 = abs(sqrt(((kuch[i].x - kuch[j].x)*(kuch[i].x -
kuch[j].x)) + ((kuch[i].y - kuch[j].y)*(kuch[i].y - kuch[j].y))));
dl2 = abs(sqrt(((kuch[z].x - kuch[j].x)*(kuch[z].x -
kuch[j].x)) + ((kuch[z].y - kuch[j].y)*(kuch[z].y - kuch[j].y))));
tt = scal / (dl1*dl2);
ddll = ddl;

rd = 1;
for (int rt = 0; rt < n; rt++) {
if ((an[rt].x == kuch[z].x) && (an[rt].y ==
kuch[z].y)) {
rd = 0;
}
}

if (i == 13 && j == 1 && z == 11) {


cout << i << " " << j << " " << z << " " <<
found << endl;
cout << abs((pat[found].dl / pat[found + 1].dl)
- (dl1 / dl2)) << " " << abs((pat[found].dl / pat[found + 1].dl) - (an[found].dl /
an[found + 1].dl)) << endl;
cout << (abs(angle[found] - acos(tt) *
57.2958)) << " " << abs(angle[found] - an[i].an) << endl;
cout << " storoni " << pat[found].dl << " " <<
pat[found + 1].dl << " " << dl1 << " " << dl2 << " ---- " << an[found].dl << " " <<
an[found + 1].dl << endl;
cout << " ugli " << angle[found] << " " <<
acos(tt) * 57.2958 << " " << an[i].an << endl;
cout << abs((pat[found].dl / pat[found + 1].dl)
- (dl1 / dl2)) << endl;
cout << abs(pat[found].dl / pat[found + 1].dl -
(an[found].dl / an[found + 1].dl)) << endl;
wtf = (((abs(angle[found] - acos(tt) *
57.2958)) < abs(angle[found] - an[i].an)) && ((abs(dl1 / dl2 - an[found].dl /
an[found + 1].dl) < 0.0005) || (abs(pat[found].dl / pat[found + 1].dl - (dl1 /
dl2)) < abs(pat[found].dl / pat[found + 1].dl - (an[found].dl / an[found +
1].dl)))));
cout << wtf << endl;
}
/* system("pause");*/
/* if (pat[found].dl / pat[found + 1].dl>1 &&
pat[found].dl / pat[found + 1].dl<15)ddl = pat[found].dl / pat[found + 1].dl * 0.1;
if ((pat[found].dl / pat[found + 1].dl >= 15)&&
(pat[found].dl / pat[found + 1].dl < 70))ddl = (pat[found].dl / pat[found + 1].dl)
* 0.65;
if ((pat[found].dl / pat[found + 1].dl >= 70))ddl =
(pat[found].dl / pat[found + 1].dl) * 0.8;
if ((rd) && ((acos(tt) * 57.2958) >= angle[found] -
ug) && ((acos(tt)*57.2958) <= angle[found] + ug) && (((dl1 / dl2)) <=
(pat[found].dl / pat[found + 1].dl) + ddl) && (((dl1 / dl2)) >= (pat[found].dl /
pat[found + 1].dl) - ddl)) {*/
if (((abs(angle[found] - acos(tt) * 57.2958)) <
abs(angle[found] - an[i].an)) && ((abs(dl1 / dl2 - an[found].dl / an[found +
1].dl)<0.0009)||(abs(pat[found].dl / pat[found + 1].dl - (dl1 / dl2)) <
abs(pat[found].dl / pat[found + 1].dl - (an[found].dl / an[found + 1].dl))))) {
/* cout << i << " " << j << " " << z << " "
<< found << endl;
system("pause");*/
if (found == 0) {
an[found].dl = dl1;
an[found + 1].dl = dl2;
an[found].an = acos(tt) * 57.2958;
an[found].x = kuch[i].x;
an[found].y = kuch[i].y;
an[found + 1].x = kuch[j].x;
an[found + 1].y = kuch[j].y;
an[found + 2].x = kuch[z].x;
an[found + 2].y = kuch[z].y;
}
else
{
an[found].dl = dl1;
an[found + 1].dl = dl2;
an[found].an = acos(tt) * 57.2958;
an[found].x = kuch[z].x;
an[found].y = kuch[z].y;

}
if (found == 0)found = 3; else found++;
if (save1 == -1) {
save1 = i;
save2 = j;
save3 = z;
vet = 0;
}
back[vet][0] = i;
back[vet][1] = j;
back[vet][2] = z;
vet++;

i = j;
j = z;
z = 0;

z--;

goto next;
}
else if (((save2 != -1) && (save3 != -1) && ((z == (m
- 1)) || (i != back[vet-1][1]) || (j != back[vet-1][2])))) {

for (int qq = 0; qq < n; qq++) {


an[qq].x = -100;
an[qq].y = -100;
}
vet--;
if (vet >= 0) {
i = back[vet][0];
j = back[vet][1];
z = back[vet][2];
found = vet;
}
else
{
save1 = -1;
save2 = -1;
save3 = -1;
found = 0;
}

lastsave1 = save1;
lastsave2 = save2;
lastsave3 = save3;

}
next:;

ddl = ddll;
/*for (int qq = 0; qq < n; qq++) {
if ((an[qq].x == -100) && (an[qq].y == -100)) {
endd = false;
}
}
if (endd)goto point; else endd = 1;*/
}
}
}
}
/*for (int i = 0; i < n; i++) {
if (an[i].x == -100) { ddl = ddl + 0.025; ug += 3; goto again; }
}*/

point:;

for (int i = 0; i < n; i++)


{
cout << an[i].x << " " << an[i].y << endl;
}
system("pause");

delete[]pat;
return 0;
}

You might also like