Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define double long double
- namespace geom
- {
- // if use the geom use precision and setf(ios::fixed)
- // conts's
- double pi = acos(-1);
- double eps = 1e-9;
- double parallel = 2e18;
- double Z = 0;
- // help's funcs
- bool is_equal(double &a, double &b)
- {
- return fabs(a - b) < eps;
- }
- struct line
- {
- double A, B, C;
- line()
- {
- A = B = C = 0;
- }
- line(double _A, double _B, double _C)
- {
- A = _A, B = _B, C = _C;
- }
- };
- void normalize(line & x)
- {
- double hyp = hypot(x.A, x.B);
- x.A /= hyp;
- x.B /= hyp;
- x.C /= hyp;
- }
- struct pt
- {
- double x, y;
- };
- double get_y(line h, double &x)
- {
- if (is_equal(h.B, Z))
- return Z;
- return (-h.C -h.A * x) / h.B;
- }
- double get_x(line h, double &y)
- {
- if (is_equal(h.A, Z))
- return Z;
- return (-h.C - h.B * y) / h.A;
- }
- double get_value(line h, pt b)
- {
- return h.A * b.x + h.B * b.y + h.C;
- }
- void normalize(pt & a)
- {
- double hyp = hypot(a.x, a.y);
- a.x /= hyp;
- a.y /= hyp;
- }
- double polar(pt a)
- {
- double ret = atan2(a.y, a.x);
- if (ret < 0)
- ret += 2 * pi;
- return ret;
- }
- double operator * (pt a, pt b)
- {
- return a.x * b.y - b.x * a.y;
- }
- double operator ^ (pt a, pt b)
- {
- return a.x * b.x + a.y * b.y;
- }
- pt operator - (pt a, pt b)
- {
- return {a.x - b.x, a.y - b.y};
- }
- pt operator + (pt a, pt b)
- {
- return {a.x + b.x, a.y + b.y};
- }
- pt operator * (pt a, double k)
- {
- return {a.x * k, a.y * k};
- }
- bool operator == (pt a, pt b)
- {
- return is_equal(a.x, b.x) && is_equal(a.y, b.y);
- }
- void operator += (pt &a, pt b)
- {
- a.x += b.x;
- a.y += b.y;
- }
- double ang_between(pt a, pt b)
- {
- return fabs(atan2(a * b, a ^ b));
- }
- double oriented_dist(pt a, line b)
- {
- normalize(b);
- return get_value(b, a);
- }
- double dist(pt a, line b)
- {
- return fabs(oriented_dist(a, b));
- }
- line to_line(pt a, pt b)
- {
- return {a.y - b.y, b.x - a.x, a * b};
- }
- double len(pt a)
- {
- return hypot(a.x, a.y);
- }
- double dist(pt a, pt b)
- {
- return len(a - b);
- }
- struct ray
- {
- pt a, b;
- ray(pt _a, pt _b)
- {
- a = _a, b = _b;
- }
- };
- line to_line(ray b)
- {
- return to_line(b.a, b.b);
- }
- bool on_ray(pt a, ray b)
- {
- pt f = b.b - b.a;
- pt c = a - b.a;
- double z = f * c;
- return is_equal(z, Z);
- }
- pt projection(pt a, line b)
- {
- pt az = {fabs(b.A), fabs(b.B)};
- normalize(az);
- a += az * -oriented_dist(a, b);
- return a;
- }
- /*double dist(pt a, ray b)
- {
- }*/
- // in, out
- istream& operator >> (istream& in, pt &t) { return in >> t.x >> t.y; }
- ostream& operator << (ostream& out, pt t) { return out << t.x << ' ' << t.y; }
- istream& operator >> (istream& in, line &t) { return in >> t.A >> t.B >> t.C; }
- ostream& operator << (ostream& out, line t) { return out << t.A << ' ' << t.B << ' ' << t.C; ; }
- istream& operator >> (istream &in, ray &t) { return in >> t.a >> t.b; }
- ostream& operator << (ostream& out, ray t) { return out << t.a << ' ' << t.b; }
- }
- using namespace geom;
- void solve()
- {
- pt a;
- line c;
- cin >> a >> c;
- cout << projection(a, c);
- }
- signed main()
- {
- ios::sync_with_stdio(0), cin.tie(0);
- cout.setf(ios::fixed), cout.precision(20);
- #ifdef ONLINE_JUDGE
- freopen("distance2.in", "r", stdin);
- freopen("distance2.out", "w", stdout);
- #endif
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement