Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- #include <locale>
- #include <windows.h>
- void aboutA();
- bool getP(double &x, double &y);
- void putP(double x, double y);
- int whereP(double x, double y);
- void processP(void);
- const double EPS = 0.0000001;
- /**
- (x-x1)/(x1-x2) = (y-y2)/(y1-y2)
- (x-x1)(y1-y2)-(y-y2)(x1-x2)=0
- x*y1-x*y2-x1*y1+x1*y2-(y-y2)(x1-x2)=0
- x(y1-y2)-x1(y1-y2)-y(x1-x2)+y2(x1-x2)=0
- x(y1-y2)+y(x2-x1)+x1(y2-y1)+y2(x1-x2)
- (a+b)c == ac + bc
- **/
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- aboutA();
- processP();
- cout<<endl;
- return 0;
- }
- void aboutA()
- {
- cout<<"Лабораторная работа №-1"<<endl<<"K-14 Вереновского Назария";
- }
- bool getP(double &x, double &y)
- {
- if(cin>>x>>y)
- return true;
- else
- return false;
- }
- void putP(double x, double y)
- {
- cout<<'('<<x<<", "<<y<<')';
- }
- int whereP(double x, double y)
- {
- double x1,x2,x3,x4;
- double y1,y2,y3,y4;
- double a=5;
- double A, A1, A2, A3;
- double B, B1, B2, B3;
- double C, C1, C2, C3;
- double t;
- double V, V1, V2, V3;
- x1=a, x2=a, x3=-a, x4=-a;
- y1=0, y2=2*a, y3=2*a, y4=0;
- A=(y1-y2);
- B=(x2-x1);
- C=(x1*(y2-y1)+y2*(x1-x2));
- if(abs(double(x*A+y*B+C))<EPS && y1-EPS < y && y < y2+EPS)
- return 0;
- A=(y2-y3);
- B=(x3-x2);
- C=(x2*(y3-y2)+y3*(x2-x3));
- if(abs(x*A+y*B+C)<EPS &&
- x2-EPS < x && x < x3+EPS)
- return 0;
- A=(y3-y4);
- B=(x4-x1);
- C=(x3*(y4-y3)+y4*(x3-x4));
- if(abs(x*A+y*B+C)<EPS &&
- y4-EPS < y && y < y3+EPS)
- return 0;
- A=(y4-y1);
- B=(x1-x2);
- C=(x4*(y1-y4)+y1*(x4-x1));
- if(abs(x*A+y*B+C)<EPS &&
- x1-EPS < x && x < x4+EPS)
- return 0;
- A=(y1-y2);
- B=(x2-x1);
- C=(x1*(y2-y1)+y2*(x1-x2));
- t=sqrt(A*A+B*B);
- A=A/t;
- B=B/t;
- C=C/t;
- if(C>0)
- {
- A=A*(-1.0);
- B=B*(-1.0);
- C=C*(-1.0);
- }
- A1=(y3-y4);
- B1=(x4-x1);
- C1=(x3*(y4-y3)+y4*(x3-x4));
- t=sqrt(A1*A1+B1*B1);
- A1=A1/t;
- B1=B1/t;
- C1=C1/t;
- if(C1>0)
- {
- A1=A1*(-1.0);
- B1=B1*(-1.0);
- C1=C1*(-1.0);
- }
- A2=(y2-y3);
- B2=(x3-x2);
- C2=(x2*(y3-y2)+y3*(x2-x3));
- t=sqrt(A2*A2+B2*B2);
- A2=A2/t;
- B2=B2/t;
- C2=C2/t;
- if(C2>0)
- {
- A2=A2*(-1.0);
- B2=B2*(-1.0);
- C2=C2*(-1.0);
- }
- A3=(y4-y1);
- B3=(x1-x2);
- C3=(x4*(y1-y4)+y1*(x4-x1));
- t=sqrt(A3*A3+B3*B3);
- A3=A3/t;
- B3=B3/t;
- C3=C3/t;
- if(C3>0)
- {
- A3=A3*(-1.0);
- B3=B3*(-1.0);
- C3=C3*(-1.0);
- }
- V=A*x+B*y+C;
- V1=A1*x+B1*y+C1;
- V2=A2*x+B2*y+C2;
- V3=A3*x+B3*y+C3;
- if((V>0)!=(V1>0) && (V2>0)!=(V3>0))
- return 1;
- else
- return -1;
- }
- void processP(void)
- {
- double x, y;
- if(getP(x,y))
- {
- putP(x,y);
- int d=whereP(x, y);
- if(d==-1)
- cout<<"IN_C";
- else
- if(d==0)
- cout<<"ON_C";
- else
- cout<<"OUT_C";
- }
- else
- cout<<"Точка не введена"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement