zoukankan      html  css  js  c++  java
  • UVA 11178 Morley's Theorem (计算直线交点 + 向量旋转)

    这题是刘汝佳老师书里的例题。P259

    想了解二维几何基础的可以

    #include <bits/stdc++.h>
    #define LL long long
    #define mem(i, j) memset(i, j, sizeof(i))
    #define rep(i, j, k) for(int i = j; i <= k; i++)
    #define dep(i, j, k) for(int i = k; i >= j; i--)
    #define pb push_back
    #define make make_pair
    #define INF INT_MAX
    #define inf LLONG_MAX
    #define PI acos(-1)
    using namespace std;
    
    const int N = 1e6 + 5;
    
    struct Point {
        double x, y;
        Point(double x = 0, double y = 0) : x(x), y(y) { } /// 构造函数
    };
    
    typedef Point Vector;
    /// 向量+向量=向量, 点+向量=向量
    Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
    ///点-点=向量
    Vector operator - (Point A, Point B) { return Vector(A.x - B.x, A.y - B.y); }
    ///向量*数=向量
    Vector operator * (Vector A, double p) { return Vector(A.x * p, A.y * p); }
    ///向量/数=向量
    Vector operator / (Vector A, double p) { return Vector(A.x / p, A.y / p); }
    
    const double eps = 1e-10;
    int dcmp(double x) {
        if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
    }
    
    bool operator == (const Point& a, const Point &b) {
        return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
    }
    
    double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
    double Length(Vector A) { return sqrt(Dot(A, A)); }
    double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
    double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
    Vector Rotate(Vector A, double rad) {
        return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad));
    }
    
    Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
        Vector u = P - Q;
        double t = Cross(w, u) / Cross(v, w);
        return P + v * t;
    }
    
    Point getD(Point A, Point B, Point C) {
        Vector V1 = C - B;
        double a1 = Angle(A - B, V1);
        V1 = Rotate(V1, a1 / 3.0);
    
        Vector V2 = B - C;
        double a2 = Angle(A - C, V2);
        V2 = Rotate(V2, -a2 / 3.0);
    
        return GetLineIntersection(B, V1, C, V2);
    }
    
    int main() {
        int _; scanf("%d", &_);
        while(_--) {
            Point A, B, C, D, E, F;
            scanf("%lf %lf", &A.x, &A.y);
            scanf("%lf %lf", &B.x, &B.y);
            scanf("%lf %lf", &C.x, &C.y);
            D = getD(A, B, C);
            E = getD(B, C, A);
            F = getD(C, A, B);
            printf("%.6f %.6f %.6f %.6f %.6f %.6f
    ", D.x, D.y, E.x, E.y, F.x, F.y);
        }
        return 0;
    }
    View Code
    一步一步,永不停息
  • 相关阅读:
    EasyNetQ使用(八)【对延迟消息插件的支持,自动订阅者】
    EasyNetQ使用(七)【发布者确认 ,用Future Publish发布预定中事件 】
    EasyNetQ使用(六)【多态发布和订阅,消息版本控制】
    EasyNetQ使用(五)【基于主题的路由,控制队列名称】
    EasyNetQ使用(四)【Request与Response,Send与Receive】
    可伸缩系统的架构经验
    Stack Exchange 的架构
    Quora使用到的技术
    Digg工程师讲述Digg背后的技术
    由12306.cn谈谈网站性能技术
  • 原文地址:https://www.cnblogs.com/Willems/p/12321646.html
Copyright © 2011-2022 走看看