二维几何基础模板(一)

ACM几何基础篇 1 前言 1.1 生产生活 1.2 ICPC竞赛 2 准备知识 2.1 头文件及函数及常量 2.2 浮点误差 2.2.1 计算误差 2.2.2 判等 2.2.2.1 解决方案 1 误差判别法 2.2.2.2 解决方案 2 化浮为整 2.2.3 负零 2.2.4 反三角函数 2.3 模板总结 3 点与向量 3.2 相关定义 3.1.1 点的定义 3.1.2 向量的定义 3.2... 阅读详情
点和向量都用两个数x,y表示:

一、常定义用 :

struct Point{  
    double x,y;  
    Point(double x=0,double y=0):x(x),y(y){} // 构造函数,方便代码编写  
};  
typedef Point Vector;  //从程序实现上,Vector只是Point的别名  


//向量+向量=向量,点+向量=点
Vector operator + (Vector A,Vector B){
    return Vector(A.x+B.x,A.y+B.y);
}

//点-点=向量
Vector operator - (Vector A,Vector B){
    return Vector(A.x-B.x,A.y-B.y);
}

//向量*数=向量
Vector operator * (Vector A,double p){
    return Vector(A.x*p,A.y*p);
}

//向量/数=向量
Vector operator / (Vector A,double p){
    return Vector(A.x/p,A.y/p);
}


bool operator < (const Point& a,const Point& b){
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}


const double eps=1e-10;
int dcmp(double x){
    if(fabs(x)<eps)
        return 0;
    else
        return x<0?-1:1;
}
bool operator == (const Point& a,const Point& b){
    return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
}

二、基本运算

1.利用点积计算向量长度和夹角的函数
double Dot(Vector A,Vector B){
    return A.x*B.x+A.y*B.y;
}
double Length(Vector A){
    return sqrt((Dot(A,A)));
}

double Angle(Vector A,Vector B){
    return acos(Dot(A,B)/Length(A)/length(B));
}

2.叉积
double Cross(Vector A,Vector B){
    return A.x*B.y-A.y*B.x;
}

double Area2(Point A,Point B,Point C){
    return Corss(B-A,C-A);
}

3.向量旋转
//rad是弧度
Vector Rotate(Vector A,double rad){
    return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}

4.计算向量的单位法线,即转90°
//调用前请确保A不是零向量
Vector Normal(Vector A){
    double L=Length(A);
    return Vector(-A.y/L,A.x/L);
}

三、基于复数的几何计算

//调用前请确保A不是零向量
Vector Normal(Vector A){
    double L=Length(A);
    return Vector(-A.y/L,A.x/L);
}

//用real(p)和imag(p)访问实部和虚部,conj(p)返回共轭复数,即conj(a+bj)=a-bj;
double Dot(Vector A,Vector B){
    return real(conj(A)*B);
}

double Corss(Vector A,Vector B){
    return imag(conj(A)*B);
}

Vector Rotate(Vector A,double rad){
    return A*exp(Point (0,rad));
}

//const double pi=4*atan(1.0);
//const double pi=acos(-1.0);
ACM计算几何篇 1 前言 1.1 计算几何算法 1.2 计算几何题目特点及要领 1.3 预备知识 2 凸包 2.1 定义 2.1.1 凸多边形 2.1.2 凸包 2.2 颜料配色问题 2.2.1 问题描述 2.2.2 问题简化 2.2.3 问题抽象 2.2.4 数学抽象 2.2.4.1 Convex Combination And Affine Combination 2.2.4.2 区别与联系 ... 阅读详情

相关推荐

科研指南:IEEE期刊LaTeX/Word模板下载与使用全解析

本文详细解析了IEEE期刊LaTeX/Word模板的下载与使用技巧,帮助科研人员高效完成论文排版。从官方模板获取入口到LaTeX文档结构配置,再到Word样式管理与常见问题解决方案,全面覆盖投稿准备的关键步骤。特别针对数学公式、参考文献和图片处理等难点提供实用建议,助力学术写作规范化。

weixin_28396629的博客 577

ACM几何问题基础知识讲解(附代码)

看了刘汝佳的《算法竞赛入门经典》之训练指南这本书的几何问题之后,受益匪浅,然后根据我自己平时的几何知识写下这篇关于二维几何基础的文章,希望对大家有用。 首先我们要理解什么是向量,向量就是有大小和方向的量。在平面坐标系中,向量用x,y表示。等于向量起点到终点的位移。以下是它们的常用定义:   struct Point { double x,y; Point(double x=0

代码改变世界,keep coding。 2068

sysbench安装(在线&离线)

sysbench下载、安装、编译和异常处理方法

m0_61066945的博客 8778

叉积

叉积 图中两个向量p1,p2.两个向量a和b的叉积写作a×b(有时也被写成a∧b,避免和字母x混淆) 向量p1,p2的叉积为 我们把(0,0)点当做p0. 有了叉积的基础,我们在判断两条线段的关系p0p1,p1p2,就可以直接添一条有向线段p0p2,再检查p0p1,p1p2和p0p2的时钟旋转关系。为了做到这一点,我们计算出叉积 给出向量的一些模板运算 stru...

A_Pathfinder的博客 586

Uds诊断自动化(CANoe.diva应用)

(7)其他配置选择可以保持默认(一般情况下,DTC以及31服务、下载服务需要另外测试)。(1)打开CANoe.Diva软件,并新建Diva工程。(2)设置工程名和保存位置;在"Specification file"(3)测试案例打开后的界面如下,可以对要进行测试的案例进行勾选,(可查看下角的进度条)后;(3)等待DIva工程的生成;(4)接下来是修改Diva工程选项,如下图点击。,如用例间的时间间隔、复位等待时间等。,即可打开导入的测试工程。,即可生成测试用例。(1)在CANoe中。

LIUJIAAAAA的博客 3461

稳定双共轭梯度法BiCGSTAB流程

稳定双共轭梯度法BiCGSTAB流程

abner361的博客 1161

二维几何小结

struct Point{ double x , y; Point(double x=0,double y=0):x(x),y(y) {}//构造函数,方便代码编写 }; typedef Point Vector ;//从程序实现上,Vector只是Point的别名 //向量+向量=向量,点+向量=点 Vector operator + (Vector A , Vector B){

Clearlemon 654

手把手教你用U盘给海信IP501H刷机:GK6323V100C芯片的4.4.2和9.0固件实战

本文详细介绍了海信IP501H电视盒子基于GK6323V100C芯片的刷机实战指南,涵盖Android 4.4.2强刷和Android 9.0免拆刷机两种方案。从工具准备、短接操作到ADB调试,提供全流程解析和常见问题解决方案,帮助用户安全高效地完成刷机操作。

lemon的博客 1497

计算几何模板(部分)

点的定义 struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} bool operator < (const Point& rhs) const { return x < rhs.x; } }; Point operator + (const Point& A, const Point& B) { return Point(A.x + B.x, A

m0_53387935的博客 337

【麒麟桌面系统】企业微信提示当前副设备的企业微信版本较低

银河麒麟系统中登录企业微信时出现"副设备版本较低"的报错,可通过两种方案解决:1)更新最新版企业微信,需替换软件源并刷新软件商店安装8.0-50-4.1.26.6019kylin5版本;2)安装内测5.0版本企业微信,需下载deb包后使用sudo dpkg命令安装。文章还提供了常见问题解决表和长期维护建议,包括系统更新检查、软件源验证等维护项目及具体操作指南。

信创运维工程师 · 银河麒麟 & 容器实战 | 金融生产环境迁移·等保加固 | 142篇原创·17万+阅读 2309

芒果YOLOv8改进165:损失函数angleLoss:即插即用 | 独家首发原创新颖|公开数据集DOTA高效无损涨点0.5% | 旋转检测

YOLOv8改进:旋转检测Loss损失函数angleLoss:即插即用 | 独家首发原创新颖|公开数据集DOTA高效无损涨点0.5%

包括YOLOv5、YOLOv7、YOLOv8等模型改进 1163

【计算几何/凸包】安德鲁算法(Andrew's Algorithm)详解

安德鲁算法 安德鲁算法(Andrew’s Algorithm)是计算几何当中一种求凸包的算法。 什么是凸包 在一个实数向量空间V中,对于给定集合X,所有包含X的凸集的交集S被称为X的凸包。X的凸包可以用X内所有点(X1,…Xn)的凸组合来构造。 简单来讲,对于一个二维空间的点集,这个点集当中的一些点总可以形成一个凸多边形,而这个凸多边形之内恰好可以包括除了组成凸包这个凸多边以外...

落花水面 1万+

分布式计算Ray框架面试题及参考答案

动态任务图执行引擎是一种能够根据任务之间的依赖关系和运行时的实际情况,动态构建和执行任务图的系统。在 Ray 中,动态任务图执行引擎允许任务在运行时根据数据可用性、计算资源状态等因素,灵活地决定后续任务的执行顺序和方式。对于 AI 应用来说,其往往具有动态性的特点。例如,在深度学习模型的训练过程中,可能需要根据训练的结果动态调整下一轮训练的参数、数据增强方式或者模型结构。动态任务图执行引擎可以很好地支持这些动态需求。它能够根据 AI 应用中各个任务的实时输出和依赖关系,动态地生成和调整任务图。

大模型大数据攻城狮的专栏 1360

几何模板总结(一):二维基础

实数比较 const double eps=1e-8; int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0?-1:1; } 点和向量的定义 struct point {     double x,y;     point(double x=0,double y=0):x(x),y(y){}

bly 705

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

二维几何基础大合集!《计算几何全家桶(一)》(基础运算、点、线、多边形、圆、网格)

整理的算法模板合集: ACM模板 目录基本运算点与直线多边形 基本运算 #include<bits/stdc++.h> using namespace std; const int N = 5007, M = 50007, INF = 0x3f3f3f3f; const double DINF = 12345678910, eps = 1e-10; struct Point{ double x, y; Point(double x = 0, double y = 0):x(x

繁凡さん的博客 8022

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

计算几何 - 二维几何基础 (模板)

这里总结一下二维几何基础知识! 常用定义: //定义点的类型 struct Point { double x, y; Point(double x = 0, double y = 0) : x(x) , y(y) { } //构造函数,方便代码编写 }; typedef Point Vector; //从程序实现上,Vector只是Point的别名 //向量 + 向量

Never say never 1217

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

二维几何——模板汇总:

就是从点类开始。。。 但是都没有正式用题目测试过,也不知道对错。。。 #include<iostream> #include<cstdlib> #include<cstdio> #include<algorithm> #include<cstring> #include<string> #include<cmath&gt...

_Griefs 203

二维几何基础(模板)

#include&amp;amp;lt;bits/stdc++.h&amp;amp;gt; using namespace std; const double eps=1e-10; struct Point{ double x,y; Point(double xx=0,double yy=0):x(xx),y(yy){} }; typedef Point Vector; Vector operator+(Vector A...

Change the world by program. 257

二维几何模板 - 二维几何基础

二维几何模板 struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y){ } }; typedef Point Vector; Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y +

Memory 535

计算几何 || 二维基础模板

/*几何模版*/ #include #include #include #include using namespace std; struct point { double x,y,d; point(double a,double b):x(a),y(b){} point(){} }; typedef point vec; //向量+向量=向量 //点 +向量=点 v

野生 659

计算几何模板

【整理于2016年】 计算几何模板 const double eps = 1e-8; const double pi = acos(-1.0); using namespace std; //采用eps的精度判断大/小于零 int epssgn(double x) { if (fabs(x)&lt;eps) return 0; else return x&lt;0?-1:1; ...

skyword的专栏 400

计算几何算法模板

算法竞赛中,计算几何部分知识总结与算法模板

m0_51171995的博客 603

计算几何模板(一)

这两周一直在做计算几何的题,感觉计算几何题就是读懂题意,并且能有清晰的解题思路,剩下的就是套用模板了,所以模板相当重要!下面整理了一些模板以便以后做题用 说明:下面的eps 都是1e-8; 目录: ㈠ Pick定理: ㈡ 在二维空间中,已知四个点的坐标,求交点的坐标 ㈢ 已知多边形的顶点的坐标,求多边形的面积利用叉积 ㈣ 求三角形面积 ㈤ 判断一个多边形是否是一个凸包 ㈥...

weixin_30920853的博客 235

kuangbin计算几何模板转载

二维几何 // `计算几何模板` const double eps = 1e-8; const double inf = 1e20; const double pi = acos(-1.0); const int maxp = 1010; //`Compares a double to zero` int sgn(double x){ if(fabs(x) < eps)re...

gzr2018的博客 410

《训练指南》大白 二维几何基础 基本公式(模板)

《训练指南》大白 二维几何基础 基本公式(模板) #include using namespace std; struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y){}///构造函数 }; typedef Point Vector ; ///向量+向量=向量,点+向量=点 Vector operat

fans_ac的博客 472

jiedai计算几何模板

ACM计算几何模板 内容包含:二维点类 二维直线线段类 多边形类 凸多边形类(凸包) 半平面交 三维计算几何 杂项等

jiedai的博客 1872
上一篇: hdu 1885 Key Task(bfs+状态压缩)
下一篇: hdu 1133 Buy the Ticket(卡特兰数)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址