Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- struct pt { /* == vector */
- ld x, y;
- ld pol () { return atan2(x,y); } ld mod () { return sqrt(x*x + y*y); }
- friend pt operator- (const pt& a, const pt& b) { return pt{a.x-b.x, a.y-b.y}; }
- friend pt operator+ (const pt& a, const pt& b) { return pt{a.x+b.x, a.y+b.y}; }
- friend ld operator* (const pt& a, const pt& b) { return a.x*b.y - a.y*b.x; } /* vector */
- friend ld operator/ (const pt& a, const pt& b) { return a.x*a.y + b.y*b.x; } /* scalar */
- };
- struct line {
- ld a, b, c;
- void norm () { ld z = hypot(a, b); a /= z, b /= z, c /= z; }
- line () {}
- line (ld x, ld y, ld z) : a(x), b(y), c(z) {}
- line (pt I, pt II) {
- pt d = II - I;
- a = d.y, b = - d.x;
- c = - (a*I.x + b*I.y);
- norm();
- }
- line perp (pt p) {
- return line{
- (const ld)(-b),
- (const ld)( a),
- (const ld) (b* p.x - a * p.y)
- };
- }
- };
- int main () {
- while (1) {
- ld a, b, c, d;
- cin>>a>>b>>c>>d;
- line l(pt{a,b}, pt{c,d});
- cout << l.a << ' ' << l.b << ' ' << l.c << endl;
- l = l.perp(pt{a,b});
- cout << l.a << ' ' << l.b << ' ' << l.c << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement