Advertisement
Mlxa

ALGO Geometry

Dec 3rd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. typedef long double ld;
  8.  
  9. struct pt { /* == vector */
  10.     ld x, y;
  11.     ld pol () { return atan2(x,y); } ld mod () { return sqrt(x*x + y*y); }
  12.     friend pt operator- (const pt& a, const pt& b) { return pt{a.x-b.x, a.y-b.y}; }
  13.     friend pt operator+ (const pt& a, const pt& b) { return pt{a.x+b.x, a.y+b.y}; }
  14.     friend ld operator* (const pt& a, const pt& b) { return  a.x*b.y - a.y*b.x;   } /* vector */
  15.     friend ld operator/ (const pt& a, const pt& b) { return  a.x*a.y + b.y*b.x;   } /* scalar */
  16. };
  17.  
  18. struct line {
  19.     ld a, b, c;
  20.     void norm () { ld z = hypot(a, b); a /= z, b /= z, c /= z; }
  21.     line () {}
  22.     line (ld x, ld y, ld z) : a(x), b(y), c(z) {}
  23.     line (pt I, pt II) {
  24.         pt d = II - I;
  25.         a = d.y, b = - d.x;
  26.         c = - (a*I.x + b*I.y);
  27.         norm();
  28.     }
  29.     line perp (pt p) {
  30.         return line{
  31.             (const ld)(-b),
  32.             (const ld)( a),
  33.             (const ld) (b* p.x - a * p.y)
  34.             };    
  35.     }
  36. };
  37.  
  38. int main () {
  39.     while (1) {
  40.         ld a, b, c, d;
  41.         cin>>a>>b>>c>>d;
  42.         line l(pt{a,b}, pt{c,d});
  43.         cout << l.a << ' ' << l.b << ' ' << l.c << endl;
  44.         l = l.perp(pt{a,b});
  45.         cout << l.a << ' ' << l.b << ' ' << l.c << endl;
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement