//
|
// 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 ¢er);
|
|
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
|