wangzhengquan
2020-08-24 e7e07f42b336bb7b5c488eb3bcc6397c0a2a03f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef __USG_GRAPH_H__
#define __USG_GRAPH_H__
 
#include "usg_common.h"
 
struct Point { 
//public:
    double x;
    double y; 
 
    //Point(const double _x =0, const double _y =0) : x(_x), y(_y) {}
};
 
//平面向量
struct Vector2
{
    double x;
    double y;
    
};
 
 
class Edge {
public:
    const Point a, b;
    /**
     * 是否相交
    */
    bool isCorss(const Point& p) const;
};
 
 
 
 
class Figure {
    //const string  name;
    std::vector<Edge> edges;
 
public:
    Figure();
    //Figure(const std::initializer_list<Edge> & _edges);
    Figure(const std::vector<Edge> & _edges);
    Figure & operator=(Figure && f);       // move assignment
    bool contains(const Point& p) const;
     
};
 
 
 
 
 // 返回两个向量夹角的cos值, cos小于0即两个向量的夹角大于90度
static inline double getVector2Angle(const Vector2 & a, const Vector2 & b) {
    double doc_product =  a.x * b.x + a.y * b.y;
    double ma = sqrt(a.x * a.x + a.y * a.y);
    double mb = sqrt(b.x * b.x + b.y * b.y);
    double cos = doc_product / (ma * mb);
    return cos;
}
 
// 计算a指向b的向量
static inline Vector2 getVecor2(const Point &a, const Point &b) {
    return {b.x - a.x, b.y - a.y};
}
 
#endif