-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsub3_cond.cpp
More file actions
138 lines (128 loc) · 2.88 KB
/
sub3_cond.cpp
File metadata and controls
138 lines (128 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <bits/stdc++.h>
#define PI 3.1415
using namespace cv;
using namespace std;
struct point //used for storing points
{
int x;
int y;
float ang;
};
Mat img = imread("Test1.png", 1);
int isValid(point p)
{
point a={p.x-4,p.y-9};
for (int ang = 0; ang >-91; ang-=10)
{
int flag=0;
for (int i = 0; i <10; i+=9)
{
for (int j = 0; j < 20; ++j)
{
int nx=(j-10)*sin((p.ang+ang)*PI/180)+(i-5)*cos((p.ang+ang)*PI/180) +15;
int ny=(j-10)*cos((p.ang+ang)*PI/180)-(i-5)*sin((p.ang+ang)*PI/180) +30;
if(a.x+nx<0||p.y+ny<0||a.x+nx>=img.rows||p.y+ny>=img.cols)
{
flag=1;
break;
}
if(img.at<Vec3b>(a.x+nx,p.y+ny)[0]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[1]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[2]==255)
{
flag=1;
break;
}
}
if (flag==1)
break;
}
if(flag==1)
continue;
for (int j = 0; j <20; j+=19)
{
for (int i = 0; i <10; ++i)
{
int nx=(j-10)*sin((p.ang+ang)*PI/180)+(i-5)*cos((p.ang+ang)*PI/180) +15;
int ny=(j-10)*cos((p.ang+ang)*PI/180)-(i-5)*sin((p.ang+ang)*PI/180) +30;
if(a.x+nx<0||p.y+ny<0||a.x+nx>=img.rows||p.y+ny>=img.cols)
{
flag=1;
break;
}
if(img.at<Vec3b>(a.x+nx,p.y+ny)[0]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[1]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[2]==255)
{
flag=1;
break;
}
}
if(flag==1)
break;
}
if(flag==0)
return (p.ang+ang);
}
for (int ang = 0; ang <91; ang+=10)
{
int flag=0;
for (int i = 0; i <10; i+=9)
{
for (int j = 0; j < 19; ++j)
{
int nx=(j-10)*sin((p.ang+ang)*PI/180)+(i-5)*cos((p.ang+ang)*PI/180) +15;
int ny=(j-10)*cos((p.ang+ang)*PI/180)-(i-5)*sin((p.ang+ang)*PI/180) +30;
if(a.x+nx<0||p.y+ny<0||a.x+nx>=img.rows||p.y+ny>=img.cols)
{
flag=1;
break;
}
if(img.at<Vec3b>(a.x+nx,p.y+ny)[0]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[1]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[2]==255)
{
flag=1;
break;
}
}
if (flag==1)
break;
}
if(flag==1)
continue;
for (int j = 0; j <20; j+=19)
{
for (int i = 0; i < 9; ++i)
{
int nx=(j-10)*sin((p.ang+ang)*PI/180)+(i-5)*cos((p.ang+ang)*PI/180) +15;
int ny=(j-10)*cos((p.ang+ang)*PI/180)-(i-5)*sin((p.ang+ang)*PI/180) +30;
if(a.x+nx<0||p.y+ny<0||a.x+nx>=img.rows||p.y+ny>=img.cols)
{
flag=1;
break;
}
if(img.at<Vec3b>(a.x+nx,p.y+ny)[0]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[1]==255 && img.at<Vec3b>(a.x+nx,p.y+ny)[2]==255)
{
flag=1;
break;
}
}
if(flag==1)
break;
}
if(flag==0)
return (p.ang+ang);
}
return -1;
}
int main()
{
int x,y,ang;
printf("Enter x y: "); scanf("%d %d ",&x,&y);
ang=isValid({x,y,0});
if (ang!=-1)
{
cout << "Point Possible" << endl;
printf("(%d,%d) at %d\n",x,y,ang);
}
else
cout << "Not Possible" << endl;
}