Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #define EPS 1e-13
- using std::pair;
- using std::numeric_limits;
- using std::make_pair;
- typedef struct pt{
- long double x, y, z;
- pt(long double tx = 0., long double ty = 0., long double tz = 0.) {
- x = tx;
- y = ty;
- z = tz;
- }
- } myvector;
- myvector operator *(myvector a, long double m){
- return pt(a.x * m, a.y * m, a.z * m);
- }
- myvector operator /(myvector a, long double m){
- return pt(a.x / m, a.y / m, a.z / m);
- }
- myvector operator +(myvector a, myvector b){
- return pt(a.x + b.x, a.y + b.y, a.z + b.z);
- }
- myvector operator -(myvector a, myvector b){
- return pt(a.x - b.x, a.y - b.y, a.z - b.z);
- }
- myvector operator %(myvector a, myvector b){
- return pt(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
- }
- bool operator ==(myvector a, myvector b){
- return ((fabs(b.x - a.x) < EPS) && (fabs(b.y - a.y) < EPS) && (fabs(b.z - a.z) < EPS));
- }
- long double vsqllen(myvector v){
- return v.x * v.x + v.y * v.y + v.z * v.z;
- }
- long double vlen(myvector v){
- return sqrt(vsqllen(v));
- }
- myvector norm(myvector v){
- long double l = vlen(v);
- return v / l;
- }
- typedef struct pl {
- long double a, b, c, d;
- myvector normal;
- pl(myvector ta = pt(0., 0., 0.), myvector tb = pt(0., 0., 0.), myvector tc = pt(0., 0., 0.)) {
- a = -tb.y * ta.z + tc.y * ta.z + ta.y * tb.z - tc.y * tb.z - ta.y * tc.z + tb.y * tc.z;
- b = tb.x * ta.z - tc.x * ta.z - ta.x * tb.z + tc.x * tb.z + ta.x * tc.z - tb.x * tc.z;
- c = -tb.x * ta.y + tc.x * ta.y + ta.x * tb.y - tc.x * tb.y - ta.x * tc.y + tb.x * tc.y;
- d = tc.x * tb.y * ta.z - tb.x * tc.y * ta.z - tc.x * ta.y * tb.z + ta.x * tc.y * tb.z + tb.x * ta.y * tc.z - ta.x * tb.y * tc.z;
- normal = pt(a, b, c);
- }
- } myplane;
- typedef struct ln {
- myvector a, b;
- ln(myvector ta = pt(0., 0., 0.), myvector tb = pt(0., 0., 0.)) {
- a = ta;
- b = tb;
- }
- } myline;
- typedef struct cr {
- myvector center;
- long double radius;
- cr(myvector a = pt(0., 0., 0.), myvector b = pt(0., 0., 0.), myvector c = pt(0., 0., 0.)) {
- myvector ta = a - c;
- myvector tb = b - c;
- radius = (vlen(ta) * vlen(tb) * vlen(ta - tb)) / (2. * vlen(ta % tb));
- center = ((((tb * vsqllen(ta)) - (ta * vsqllen(tb))) % (ta % tb)) / (2. * vsqllen(ta % tb))) + c;
- }
- } circle;
- myline intersection(myplane a, myplane b) {
- myline res = ln(pt(0., 0., 0.), pt(0., 0., 0.));
- res.b = a.normal % b.normal;
- res.a = ((a.normal * b.d - b.normal * a.d) % res.b) / pow(vlen(res.b), 2);
- return res;
- }
- pair<myvector, myvector> intersection(const myline l, const circle c) {
- long double Mnan = numeric_limits<long double>::quiet_NaN();
- long double A = vsqllen(l.b);
- long double B = -2. * (l.b.x * (c.center.x + l.a.x) - l.b.y * (c.center.y + l.a.y) - l.b.z * (c.center.z + l.a.z));
- long double C = vsqllen(myvector(c.center) - myvector(l.a)) - pow(c.radius, 2);
- long double D = B * B - 4 * A * C;
- if (D < EPS) return make_pair(pt(Mnan, Mnan, Mnan), pt(Mnan, Mnan, Mnan));
- if (fabs(A) < EPS) {
- if (fabs(B) < EPS) {
- if (fabs(C) < EPS) return make_pair(l.a, l.a);
- return make_pair(pt(Mnan, Mnan, Mnan), pt(Mnan, Mnan, Mnan));
- }
- return make_pair(pt(l.a) + pt(l.b) * (-C / B), pt(l.a) + pt(l.b) * (-C / B));
- }
- return make_pair(myvector(l.a) + myvector(l.b) * ((-B + sqrt(D)) / (2. * A)),
- pt(l.a) + myvector(l.b) * ((-B - sqrt(D)) / (2. * A)));
- }
- bool paralel_plane(myplane p1, myplane p2, circle cr1, circle cr2) {
- if ((fabs(p1.a - p2.a) < EPS) && fabs(p1.b - p2.b) < EPS && fabs(p1.c - p2.c) < EPS){
- if (fabs(p1.d - p2.d) < EPS){
- printf("%d\n", vlen(cr2.center - cr1.center) - cr1.radius - cr2.radius < EPS ? 1 : 0);
- }
- else{
- printf("%d\n", 0);
- }
- return true;
- }
- return false;
- }
- bool inpect(myvector a, myplane p, circle c) {
- if ((fabs(p.a * a.x + p.b * a.y + p.c * a.z + p.d) < EPS) && (vlen(a - c.center) - c.radius < EPS)) {
- printf("%d\n", 1);
- return true;
- }
- return false;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- long double x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6;
- scanf("%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf", &x1, &y1, &z1, &x2, &y2, &z2, &x3, &y3, &z3, &x4, &y4, &z4, &x5, &y5, &z5, &x6, &y6, &z6);
- myvector a1(x1, y1, z1);
- myvector b1(x2, y2, z2);
- myvector c1(x3, y3, z3);
- myvector a2(x4, y4, z4);
- myvector b2(x5, y5, z5);
- myvector c2(x6, y6, z6);
- myplane p1 = pl(b1, a1, c1);
- myplane p2 = pl(a2, b2, c2);
- circle cr1(a1, b1, c1);
- circle cr2(a2, b2, c2);
- if (paralel_plane(p1, p2, cr1, cr2))
- return 0;
- myline inter = intersection(p1, p2);
- pair<myvector, myvector> ip1 = intersection(inter, cr1), ip2 = intersection(inter, cr2);
- if (inpect(ip1.first, p2, cr2) || inpect(ip1.second, p2, cr2) ||
- inpect(ip2.first, p1, cr1) || inpect(ip2.second, p1, cr1)) return 0;
- printf("%d\n", 0);
- fclose(stdin);
- fclose(stdout);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement