派生自 Algorithm/baseDetector

孙天宇
2022-07-12 ce9d187fd294cca192a27f52719094e9df7b1b62
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// Created by Scheaven on 2020/5/31.
//
#ifndef GEOMETRY_UTIL_H
#define GEOMETRY_UTIL_H
 
#include <vector>
#include <map>
#include <string>
#include <list>
#include <fstream>
#include <stdint.h>
#include "stdio.h"
#include <stdlib.h>
#include <math.h>
 
#include <iostream>
#include <cmath>
#include <cstring>
#include "assert.h"
 
const double PI = 3.14159265;
 
typedef struct _Point
{
public:
    float x;
    float y;
    float z;
 
public:
    _Point(float x, float y);
    _Point();
    _Point(double a , double b , double c );
}SPoint;
 
// 多边形区域结构
typedef struct _PInfo
{
    SPoint* point;
    int count;
}RegInfo;
 
float calDistance(SPoint A, SPoint B);
 
 
bool Pt_in_Polygon(SPoint point, RegInfo* polygon);
 
#define MAX_POINT_POLYGON 64
 
struct Polygon {
    SPoint pt[MAX_POINT_POLYGON];
    int     n;
 
    Polygon(int n_ = 0 ) { assert(n_>= 0 && n_ < MAX_POINT_POLYGON); n = n_;}
    virtual ~Polygon() {}
 
    void clear() { n = 0; }
    void add(const SPoint &p) {if(n < MAX_POINT_POLYGON) pt[n++] = p;}
    void push_back(const SPoint &p) {add(p);}
    int size() const { return n;}
    SPoint getCenter() const ;
    const SPoint & operator[] (int index) const { assert(index >= 0 && index < n); return pt[index];}
    SPoint& operator[] (int index) { assert(index >= 0 && index < n); return pt[index]; }
    void pointsOrdered() ;
    float area() const ;
    bool pointIsInPolygon(SPoint p) const ;
};
 
 
void intersectPolygonSHPC(const Polygon * sub,const Polygon* clip,Polygon* res) ;
void intersectPolygonSHPC(const Polygon & sub,const Polygon& clip,Polygon& res) ;
 
 
//struct Point
//{
//    double x;    // x坐标
//    double y;    // y坐标
//    double z;    // z坐标(默认为0,如果需要三维点则给z赋值)
//
//    Point(double a , double b , double c = 0); // 构造函数
//    Point(); // 构造函数
//};
 
struct Line
{
    SPoint s;
    SPoint e;
    bool is_seg;
 
    Line();
    Line(SPoint a, SPoint b, bool _is_seg = true);
};
 
bool PointCmp(const SPoint &a,const SPoint &b,const SPoint &center);
 
SPoint ClockwiseSortPoints(std::vector<SPoint> &vPoints); // 多边形的点按照逆时针排序
 
SPoint add(const SPoint& lhs, const SPoint& rhs);
 
SPoint sub(const SPoint& lhs, const SPoint& rhs);
 
SPoint mul(const SPoint& p, double ratio);
 
SPoint div(const SPoint& p, double ratio);
 
bool equal(const SPoint& lhs, const SPoint& rhs);
 
double length(const SPoint& vec);
 
SPoint normalize(const SPoint& vec);
 
double dotMultiply(const SPoint& op, const SPoint& p1, const SPoint& p2);
 
double dotMultiply(const SPoint& vec1, const SPoint& vec2);
 
SPoint multiply(const SPoint& op, const SPoint& p1, const SPoint& p2);
 
SPoint multiply(const SPoint& vec1, const SPoint& vec2);
 
bool isponl(const SPoint& p, const Line& l);
 
double Cos(const SPoint& vec1, const SPoint& vec2);
 
double Cos(const SPoint& op, const SPoint& p1, const SPoint& p2);
 
bool isSegIntersect(const Line& l1, const Line& l2, SPoint& inter_p);
 
#endif //GEOMETRY_UTIL_H