You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include "point.h"
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
#include <limits>
|
|
#include "geocompute.h"
|
|
using namespace std;
|
|
|
|
struct Point2D {
|
|
double x, y;
|
|
};
|
|
|
|
struct Line2D {
|
|
Point2D p1, p2;
|
|
};
|
|
|
|
struct Rectangle2D {
|
|
Point2D vertices[4];
|
|
double area() const {
|
|
double width = std::sqrt(std::pow(vertices[1].x - vertices[0].x, 2) + std::pow(vertices[1].y - vertices[0].y, 2));
|
|
double height = std::sqrt(std::pow(vertices[2].x - vertices[1].x, 2) + std::pow(vertices[2].y - vertices[1].y, 2));
|
|
return width * height;
|
|
}
|
|
};
|
|
|
|
class TopologicalAnalysis
|
|
{
|
|
public:
|
|
TopologicalAnalysis(void);
|
|
~TopologicalAnalysis(void);
|
|
|
|
bool isPointInLine(double* point, double* startPoint, double* endPoint,float tolerance=0.001);
|
|
|
|
// 判断点是否在线上
|
|
int isPointInPolyLine(double* point, vector<double>& lineX,vector<double>& lineY,float tolerance=0.001);
|
|
bool isPointInLine(CPoint1 point, CPoint1 startPoint, CPoint1 endPoint);
|
|
|
|
//根据两点求出垂线过第三点的直线的交点
|
|
bool GetPointToLineVerticalCross(double* linePt1,double* linePt2,double* pt,double* crossPt);
|
|
|
|
//判断点是否在多边形内,交点法
|
|
bool isPointInPolygon(CPoint1 point, vector<CPoint1> polygon);
|
|
|
|
//判断两条直线段是否相交
|
|
bool isLineIntersect(CPoint1 line1Start, CPoint1 line1End, CPoint1 line2Start, CPoint1 line2End);
|
|
|
|
// 计算两点的欧式距离, 未实现
|
|
double getDistance(CPoint1 point1, CPoint1 point2);
|
|
|
|
//计算一组CPoint1的最大X
|
|
double getMaxX(vector<CPoint1> points);
|
|
|
|
//获取多边形外包矩形
|
|
bool GetBoundingBoxVertices(const vector<double>& polygonX,const vector<double>& polygonY,vector<double>& rectangleX,vector<double>& rectangleY);
|
|
|
|
//计算直线与多边形的交点
|
|
void linePolygonIntersections(const Point2D& linePt1,const Point2D& linePt2,const vector<double>& polygonX,const std::vector<double>& polygonY,std::vector<Point2D>& result);
|
|
|
|
|
|
private:
|
|
// 判断两条线段是否相交
|
|
int isLineIntersecting(const Line2D& l1, const Line2D& l2, Point2D& intersection);
|
|
};
|
|
|
|
|