昨天写了计算几何学的东西,今天主要是工程化一下,工程借鉴B站up主
【自动驾驶】自动驾驶planning方向中服务器托管网常用的计算几何学知识 01_哔哩哔哩_bilibili
#pragma once
#include
#include
class Point{
public:
Point() = default;
Point(double x_in, double y_in) : x(x_in), y(y_in) {}
Point operator + (const Point& p) const{
return {x + p.x, y + p.y};
}
Point operator - (const Point& p) const{
return {x - p.x, y - p.y};
}
Point operator*(double k)const {
return {x * k, y * k};
}
friend std::ostream &operator
#pragma once
#include "Geometry.h"
#include "utils.h"
double ComputeProjectionLength(const Point& p, const Segment& segement){
const auto& p1p = p - segement.start;
return DotProduct(p1p, segement.unit_direction());
}
Point ComputeProjection(const Point& p, const Segment& segment){
double projection_length = ComputeProjectionLength(p, segment);
return segment.start + segment.unit_direction() * projection_length;
}
#pragma once
#include "Geometry.h"
#include "utils.h"
// Get distance between point p1 and point p2.
double GetDistance(const Point& p1, const Point& p2){
return p1.DistanceTo(p2);
}
// Get distance between point p and a straight line.
double GetDistance(const Poin服务器托管网t& p, const Line& line){
Segment p1p2(line.p1, line.p2);
Segment p1p(line.p1, p);
return std::abs(CrossProduct(p1p2.direction, p1p.direction)) / p1p2.Length();
}
// Get distance between point p and segment(p1,p2).
double GetDistance(const Point& p, const Segment& segment){
Segment p1p(segment.start, p);
Segment p2p(segment.end, p);
const auto c1 = DotProduct(p1p.direction, segment.direction);
const auto c2 = DotProduct(p2p.direction, segment.direction);
if(c1 = 0){
//distance(p,segment)=distacne(p2,p).
return GetDistance(segment.end, p);
}
return std::abs(CrossProduct(segment.direction, p1p.direction)) / segment.Length();
}
#pragma once
#include
#include "Geometry.h"
// Calculates dot product.
double DotProduct(const Point& p1, const Point& p2){
return p1.x * p2.x + p1.y * p2.y;
}
// Calculates cross product.
double CrossProduct(const Point& p1, const Point& p2) {
return p1.x * p2.y - p2.x * p1.y;
}
#include
#include "Geometry.h"
#include "Projection.h"
#include "Distance.h"
int main(){
Point point(3, 4);
Segment segment(Point(0.0, 0.0), Point(10.0, 0.0));
Point projection = ComputeProjection(point, segment);
std::cout
TODO
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
国产数据库圈,为啥那么多水货?” 本文分享自华为云社区《GaussDB(DWS)性能调优系列实战篇七:十八般武艺之GUC参数调优》,作者: 黎明的风。 1. 前言 适用版本:【8.1.1及以上】 GaussDB(DWS)性能调优系列专题文章,介绍了数据库性能调…