Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <windows.h>
  3. #include <conio.h>
  4. using namespace std;
  5.  
  6.  
  7. #include <locale>
  8. #include <windows.h>
  9.  
  10. void aboutA();
  11. bool getP(double &x, double &y);
  12. void putP(double x, double y);
  13. int whereP(double x, double y);
  14. void processP(void);
  15. const double EPS = 0.0000001;
  16.  
  17. /**
  18. (x-x1)/(x1-x2) = (y-y2)/(y1-y2)
  19. (x-x1)(y1-y2)-(y-y2)(x1-x2)=0
  20. x*y1-x*y2-x1*y1+x1*y2-(y-y2)(x1-x2)=0
  21.  
  22. x(y1-y2)-x1(y1-y2)-y(x1-x2)+y2(x1-x2)=0
  23. x(y1-y2)+y(x2-x1)+x1(y2-y1)+y2(x1-x2)
  24. (a+b)c == ac + bc
  25. **/
  26.  
  27. int main()
  28. {
  29.     SetConsoleCP(1251);
  30.     SetConsoleOutputCP(1251);
  31.  
  32.     aboutA();
  33.     processP();
  34.     cout<<endl;
  35.     return 0;
  36. }
  37.  
  38. void aboutA()
  39. {
  40.     cout<<"Лабораторная работа №-1"<<endl<<"K-14 Вереновского Назария";
  41. }
  42.  
  43. bool getP(double &x, double &y)
  44. {
  45.     if(cin>>x>>y)
  46.         return true;
  47.     else
  48.         return false;
  49.  
  50. }
  51.  
  52. void putP(double x, double y)
  53. {
  54.     cout<<'('<<x<<", "<<y<<')';
  55. }
  56.  
  57. int whereP(double x, double y)
  58. {
  59.     double x1,x2,x3,x4;
  60.     double y1,y2,y3,y4;
  61.     double a=5;
  62.     double A, A1, A2, A3;
  63.     double B, B1, B2, B3;
  64.     double C, C1, C2, C3;
  65.     double t;
  66.     double V, V1, V2, V3;
  67.  
  68.     x1=a, x2=a, x3=-a, x4=-a;
  69.     y1=0, y2=2*a, y3=2*a, y4=0;
  70.  
  71.     A=(y1-y2);
  72.     B=(x2-x1);
  73.     C=(x1*(y2-y1)+y2*(x1-x2));
  74.  
  75.     if(abs(double(x*A+y*B+C))<EPS && y1-EPS < y && y < y2+EPS)
  76.         return 0;
  77.  
  78.     A=(y2-y3);
  79.     B=(x3-x2);
  80.     C=(x2*(y3-y2)+y3*(x2-x3));
  81.  
  82.     if(abs(x*A+y*B+C)<EPS &&
  83.        x2-EPS < x && x < x3+EPS)
  84.         return 0;
  85.  
  86.     A=(y3-y4);
  87.     B=(x4-x1);
  88.     C=(x3*(y4-y3)+y4*(x3-x4));
  89.  
  90.     if(abs(x*A+y*B+C)<EPS &&
  91.        y4-EPS < y && y < y3+EPS)
  92.         return 0;
  93.  
  94.     A=(y4-y1);
  95.     B=(x1-x2);
  96.     C=(x4*(y1-y4)+y1*(x4-x1));
  97.     if(abs(x*A+y*B+C)<EPS &&
  98.        x1-EPS < x && x < x4+EPS)
  99.         return 0;
  100.  
  101.     A=(y1-y2);
  102.     B=(x2-x1);
  103.     C=(x1*(y2-y1)+y2*(x1-x2));
  104.  
  105.     t=sqrt(A*A+B*B);
  106.     A=A/t;
  107.     B=B/t;
  108.     C=C/t;
  109.  
  110.     if(C>0)
  111.     {
  112.        A=A*(-1.0);
  113.        B=B*(-1.0);
  114.        C=C*(-1.0);
  115.     }
  116.  
  117.     A1=(y3-y4);
  118.     B1=(x4-x1);
  119.     C1=(x3*(y4-y3)+y4*(x3-x4));
  120.  
  121.     t=sqrt(A1*A1+B1*B1);
  122.     A1=A1/t;
  123.     B1=B1/t;
  124.     C1=C1/t;
  125.  
  126.     if(C1>0)
  127.     {
  128.        A1=A1*(-1.0);
  129.        B1=B1*(-1.0);
  130.        C1=C1*(-1.0);
  131.     }
  132.  
  133.     A2=(y2-y3);
  134.     B2=(x3-x2);
  135.     C2=(x2*(y3-y2)+y3*(x2-x3));
  136.  
  137.     t=sqrt(A2*A2+B2*B2);
  138.     A2=A2/t;
  139.     B2=B2/t;
  140.     C2=C2/t;
  141.  
  142.     if(C2>0)
  143.     {
  144.        A2=A2*(-1.0);
  145.        B2=B2*(-1.0);
  146.        C2=C2*(-1.0);
  147.     }
  148.  
  149.     A3=(y4-y1);
  150.     B3=(x1-x2);
  151.     C3=(x4*(y1-y4)+y1*(x4-x1));
  152.  
  153.     t=sqrt(A3*A3+B3*B3);
  154.     A3=A3/t;
  155.     B3=B3/t;
  156.     C3=C3/t;
  157.  
  158.     if(C3>0)
  159.     {
  160.        A3=A3*(-1.0);
  161.        B3=B3*(-1.0);
  162.        C3=C3*(-1.0);
  163.     }
  164.  
  165.     V=A*x+B*y+C;
  166.     V1=A1*x+B1*y+C1;
  167.     V2=A2*x+B2*y+C2;
  168.     V3=A3*x+B3*y+C3;
  169.  
  170.     if((V>0)!=(V1>0) && (V2>0)!=(V3>0))
  171.         return 1;
  172.  
  173.     else
  174.         return -1;
  175. }
  176.  
  177. void processP(void)
  178. {
  179.     double x, y;
  180.     if(getP(x,y))
  181.     {
  182.         putP(x,y);
  183.         int d=whereP(x, y);
  184.         if(d==-1)
  185.             cout<<"IN_C";
  186.         else
  187.             if(d==0)
  188.             cout<<"ON_C";
  189.         else
  190.             cout<<"OUT_C";
  191.     }
  192.  
  193.  
  194.     else
  195.         cout<<"Точка не введена"<<endl;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement