This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM \
"https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/1/CGL_1_A"
#define ERROR 0.0000001
#include "../../geometry/line.hpp"
#include "../../template/template.hpp"
using namespace lib;
int main() {
std::cout << std::fixed << std::setprecision(15);
line l;
{
ld x1, y1, x2, y2;
std::cin >> x1 >> y1 >> x2 >> y2;
l.a = {x1, y1};
l.b = {x2, y2};
}
int q;
std::cin >> q;
while (q--) {
ld x, y;
std::cin >> x >> y;
vec p = proj(l, {x, y});
std::cout << p.real() << " " << p.imag() << '\n';
}
}
#line 1 "test/geometry/Projection.test.cpp"
#define PROBLEM \
"https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/1/CGL_1_A"
#define ERROR 0.0000001
#line 2 "geometry/line.hpp"
#line 2 "geometry/base_ld.hpp"
#line 2 "template/template.hpp"
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
namespace lib {
using namespace std;
} // namespace lib
// using namespace lib;
#line 4 "geometry/base_ld.hpp"
namespace lib {
using vec = complex<ld>;
const ld PI = acos(-1);
void ldout(int len = 20) {
cout << fixed << setprecision(len);
}
int sgn(ld a, const ld eps = 1e-7) {
return (a < -eps) ? -1 : (a > eps) ? 1 : 0;
}
bool same_vec(vec a, vec b) {
a -= b;
return sgn(a.real()) == 0 && sgn(a.imag()) == 0;
}
ld dot(const vec &a, const vec &b) {
return (conj(a) * b).real();
}
ld cross(const vec &a, const vec &b) {
return (conj(a) * b).imag();
}
int isp(const vec &a, const vec &b, const vec &c) {
int cross_sgn = sgn(cross(b - a, c - a));
if (cross_sgn == 0) {
if (sgn(dot(b - a, c - a)) < 0) return -2;
if (sgn(dot(a - b, c - b)) < 0) return 2;
}
return cross_sgn;
}
vec rot90(const vec &a) {
return {-a.imag(), a.real()};
}
vec rot(const vec &a, ld rad) {
return a * vec(cosl(rad), sinl(rad));
}
bool comp_for_argument_sort(const vec &lhs, const vec &rhs) {
// if (abs(arg(lhs)-arg(rhs)) < eps) return false; // need ?
return arg(lhs) < arg(rhs);
}
} // namespace lib
#line 4 "geometry/line.hpp"
namespace lib {
struct line {
vec a, b;
};
vec proj(const line &l, const vec &p) {
vec ab = l.b - l.a;
return l.a + ab * (dot(ab, p - l.a) / norm(ab));
}
vec refl(const line &l, const vec &p) {
return proj(l, p) * ld(2) - p;
}
int intersection(const line &a, const line &b) {
if (sgn(cross(a.b - a.a, b.a - b.b)) != 0) {
if (sgn(dot(a.b - a.a, b.a - b.b)) == 0) {
return 1;
}
return 0;
} else if (sgn(cross(a.b - a.a, b.a - a.a)) != 0) {
return 2;
} else {
return 3;
}
}
ld dist(const line &a, const vec &p) {
return abs(cross(p - a.a, a.b - a.a) / abs(a.b - a.a));
}
vec cross_point(const line &a, const line &b) {
assert(intersection(a, b) < 2);
return a.a + (a.b - a.a) * cross(b.a - a.a, b.b - b.a) /
cross(a.b - a.a, b.b - b.a);
}
} // namespace lib
#line 7 "test/geometry/Projection.test.cpp"
using namespace lib;
int main() {
std::cout << std::fixed << std::setprecision(15);
line l;
{
ld x1, y1, x2, y2;
std::cin >> x1 >> y1 >> x2 >> y2;
l.a = {x1, y1};
l.b = {x2, y2};
}
int q;
std::cin >> q;
while (q--) {
ld x, y;
std::cin >> x >> y;
vec p = proj(l, {x, y});
std::cout << p.real() << " " << p.imag() << '\n';
}
}