Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- using namespace std;
- const long double inf = 2e18;
- struct point {
- long double x, y;
- long double len() {
- return sqrt(x * x + y * y);
- }
- void build(long double a, long double b) {
- x = a;
- y = b;
- }
- };
- struct line {
- long double a, b, c, k, m;
- long double getY(long double x) {
- if (b == 0) {
- return inf;
- }
- return -(c + a * x) / b;
- }
- long double getX(long double y) {
- if (a == 0) {
- return inf;
- }
- return -(c + b * y) / a;
- }
- void buildPoints(point x, point y) {
- a = x.y - y.y;
- b = y.x - x.x;
- c = x.x * y.y - y.x * x.y;
- if (b == 0) {
- m = inf + x.x;
- k = inf;
- } else {
- m = -c / b;
- k = -a / b;
- }
- }
- void build(long double A, long double B, long double C) {
- a = A;
- b = B;
- c = C;
- if (b == 0) {
- m = inf;
- k = inf;
- } else {
- m = -c / b;
- k = -a / b;
- }
- }
- long double distance(point p) {
- return abs(a * p.x + b * p.y + c) / sqrt(a * a + b * b);
- }
- };
- struct circle {
- point center;
- long double radius;
- pair<long double, long double> getY(long double x) {
- pair<long double, long double> res = {inf, inf};
- long double a = 1, b, c, d;
- b = -2 * center.y;
- c = center.y * center.y - radius * radius + (x - center.x) * (x - center.x);
- d = b * b - 4.0 * a * c;
- if (d == 0) {
- res.first = -b / 2.0;
- }
- if (d > 0) {
- res.first = (-b + sqrt(d)) / 2.0 / a;
- res.first = (-b - sqrt(d)) / 2.0 / a;
- }
- return res;
- }
- };
- point operator*(long double k, point a) {
- point res;
- res.x = a.x * k;
- res.y = a.y * k;
- return res;
- }
- long double operator*(point a, point b) {
- return a.x * b.x + a.y * b.y;
- }
- long double operator^(point a, point b) {
- return a.x * b.y - a.y * b.x;
- }
- point operator-(point a, point b) {
- point res;
- res.x = a.x - b.x;
- res.y = a.y - b.y;
- return res;
- }
- point operator+(point a, point b) {
- point res;
- res.x = a.x + b.x;
- res.y = a.y + b.y;
- return res;
- }
- int main() {
- circle o;
- line l;
- point ans1, ans2, p;
- long double x, y, z, D, a, b, c, d;
- scanf("%Lf %Lf %Lf %Lf %Lf %Lf", &o.center.x, &o.center.y, &o.radius, &x, &y, &z);
- l.build(x, y, z);
- a = l.a * l.a + l.b * l.b;
- b = 2.0 * (l.a * l.c - o.center.x * l.b * l.b + l.a * l.b * o.center.y);
- c = o.center.x * o.center.x * l.b * l.b + l.c * l.c + 2 * l.c * l.b * o.center.y + o.center.y * o.center.y * l.b * l.b - l.b * l.b * o.radius * o.radius;
- d = b * b - 4.0 * a * c;
- if (l.distance(o.center) > o.radius) {
- printf("0");
- } else {
- if (l.distance(o.center) == o.radius) {
- ans1.x = -b / 2.0 / a;
- if (!l.b) {
- ans1.y = o.getY(ans1.x).first;
- } else {
- ans1.y = l.getY(ans1.x);
- }
- printf("1\n");
- printf("%Lf %Lf", ans1.x, ans1.y);
- } else {
- ans1.x = (-b + sqrt(d)) / 2.0 / a;
- ans2.x = (-b - sqrt(d)) / 2.0 / a;
- if (!l.b) {
- ans1.y = o.getY(ans1.x).first;
- ans2.y = o.getY(ans1.x).second;
- } else {
- ans1.y = l.getY(ans1.x);
- ans2.y = l.getY(ans2.x);
- }
- printf("2\n");
- printf("%Lf %Lf\n", ans1.x, ans1.y);
- printf("%Lf %Lf\n", ans2.x, ans2.y);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement