[namespace hdk] 向量 direct_vector
我忏悔我有罪我心情又不好了不知道干什么所以又不小心封了个东西啊啊啊啊啊啊啊啊
功能
已重载 [] 运算符(左值)
已重载 = 运算符(可使用向量或 std:::vector)
已重载 + += - -= -(负号) *(点乘) *=(点乘) 运算符
已重载 == 运算符(已使用 template,operator<1>(&A) 时狭义比较(默认),否则仅比较长度)
已重载 < > <= >= (\(eps\) 意义下比较长度大小)运算符
已重载构造函数
已定义 const double pi (\(\pi\))
全局函数
anglealpha(double) 弧度制转角度值
arcalpha(double) 角度值转弧度制
以下均采用弧度制
double alpha() 返回该向量夹角
double get(int) 获取某一维的值
std::vector get_all() 将自身作为 std::vector 返回
double length() 返回向量长度
bool length_eq(&A) 比较长度是否相等(\(eps\) 意义下)
lower_degree(int) 降低向量维度后返回
upper_degree(int) 升高向量维度后返回
print(char devide=[space],char end=[\n]) 输出向量,使用 devide 做分隔符,end 做结束符
set_vector(std::vector) 使用 vector 赋值
set_basevector(double alpha) 将该向量赋值为夹角为 alpha 的单位向量
set_basevector() 夹角不变,将该向量变成单位向量
vectoralpha(&A) 求向量夹角
vectoralpha_cos(&A) 求向量夹角的余弦
*_get(int) 返回指定维度的指针
已定义 xl 作为类名称
clear()
定义
direct_vector<3> b({1,1,1});
direct_vector<3> a;
xl<2> p();
代码
#include<bits/stdc++.h>
using namespace std;
namespace hdk{
#define xl direct_vector
const long double pi=acos(-1);
const long double eps=1e-5;
inline double arcalpha(double _anglealpha){
return _anglealpha*pi/180;
}
inline double anglealpha(double _arcalpha){
return _arcalpha*180/pi;
}
template<int degree>
class direct_vector{
private:
double d[degree+1];
public:
direct_vector<degree>(vector<double> x={}){
for(int i=1;i<=degree;++i){
if(i>(int)x.size()) d[i]=0;
else d[i]=x[i-1];
}
}
inline double *_get(int d_id){
return &d[d_id];
}
inline void clear(){
for(int i=1;i<=degree;++i){
d[i]=0;
}
}
template<bool alphatype=1>
inline void set_basevector(double alpha){
if(degree!=2) exit(3);
if(alphatype==2){
alpha=arcalpha(alpha);
}
d[1]=cos(alpha);
d[2]=sin(alpha);
}
inline double get(int d_id){return (abs(d[d_id])<=eps?0:d[d_id]);}
inline void set_vector(vector<double>a){
if(a.size()<degree) exit(3);
for(int i=1;i<=degree;++i){
d[i]=a[i-1];
}
}
void operator =(const vector<double> &A){
if(A.size()<degree) exit(3);
for(int i=1;i<=degree;++i){
d[i]=A[i-1];
}
}
void operator =(const direct_vector<degree> &A){
for(int i=1;i<=degree;++i){
d[i]=A.d[i];
}
}
direct_vector<degree> operator +(const direct_vector<degree> &A)const{
direct_vector<degree> ans;
for(int i=1;i<=degree;++i){
ans.d[i]=d[i]+A.d[i];
}
return ans;
}
void operator +=(const direct_vector<degree> &A){
*this=*this+A;
}
direct_vector<degree> operator -()const{
direct_vector<degree> ans;
for(int i=1;i<=degree;++i){
ans.d[i]=-d[i];
}
return ans;
}
direct_vector<degree> operator -(const direct_vector<degree> &A)const{
return *this+-A;
}
void operator -=(const direct_vector<degree> &A){
*this=*this+-A;
}
double operator *(const direct_vector<degree> &A)const{
double ans=0;
for(int i=1;i<=degree;++i){
ans+=d[i]*A.d[i];
}
return ans;
}
inline vector<double> get_all(){
vector<double> v;
for(int i=1;i<=degree;++i){
v.push_back(d[i]);
}
return v;
}
inline void print(char devide=' ',char end='\n'){
for(int i=1;i<=degree;++i){
cout<<(abs(d[i])<eps?0:d[i])<<devide;
}
cout<<end;
}
double& operator [](int x){
return d[x];
}
inline double length(){
double ans=0;
for(int i=1;i<=degree;++i){
ans+=d[i]*d[i];
}
return sqrt(ans);
}
inline void set_basevector(){
double len=length();
for(int i=1;i<=degree;++i){
d[i]/=len;
}
}
direct_vector<degree> operator *(double x)const{
direct_vector<degree> ans;
for(int i=1;i<=degree;++i){
ans.d[i]=x*d[i];
}
return ans;
}
void operator *=(double x){
*this=*this*x;
}
template<int equaltype=1>
bool operator ==(direct_vector<degree> A){
if(equaltype==1){
for(int i=1;i<=degree;++i){
if(abs(d[i]-A.d[i])>eps) return false;
}
return true;
}
else{
if(abs(length()-A.length())<=eps) return true;
return false;
}
}
bool operator !=(direct_vector<degree> A){
return not(*this==A);
}
bool operator <(direct_vector<degree> A){
return length()<A.length();
}
bool operator >(direct_vector<degree> A){
return not((*this.operator==<2>(A)) or (*this<A));
}
bool operator <=(direct_vector<degree> A){
return not(*this>A);
}
bool operator >=(direct_vector<degree> A){
return not(*this<A);
}
template<int todegree>
direct_vector<todegree> upper_degree(){
direct_vector<todegree> ans;
for(int i=1;i<=degree;++i){
*ans._get(i)=d[i];
}
return ans;
}
template<int todegree>
direct_vector<todegree> lower_degree(){
direct_vector<todegree> ans;
for(int i=1;i<=todegree;++i){
*ans._get(i)=d[i];
}
return ans;
}
double alpha(){
direct_vector<degree> res;
res=*this;
res.set_basevector();
return acos(res[1]);
}
double vectoralpha_cos(direct_vector<degree> A){
double ans=abs(*this*A)/(length()*A.length());
return ans;
}
double vectoralpha(direct_vector<degree> A){
double res=acos(vectoralpha_cos(A));
if(abs(res)<=eps){
return 0;
}
else{
return res;
}
}
bool length_eq(direct_vector<degree> A){
return *this.operator==<2>(A);
}
};
}
using namespace hdk;
[namespace hdk] 向量 direct_vector的更多相关文章
- springcloud必知功能使用教程
springcloud Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.消息总线.负载均衡.断路 ...
- NOI2001|POJ1182食物链[种类并查集 向量]
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65430 Accepted: 19283 Description ...
- 【BZOJ-3243】向量内积 随机化 + 矩阵
3243: [Noi2013]向量内积 Time Limit: 10 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 1249 Solved: ...
- 学习笔记之vector向量容器
今天复习到vector向量容器,里面包括vector向量容器的一些优点以及具体的使用方法及代码,分享给大家. Vector向量容器不但能够像数组一样对元素进行随机访问,还可以在尾部插入元素,是一种简单 ...
- AC日记——向量点积计算 openjudge 1.6 09
09:向量点积计算 总时间限制: 1000ms 内存限制: 65536kB 描述 在线性代数.计算几何中,向量点积是一种十分重要的运算. 给定两个n维向量a=(a1,a2,...,an)和b=(b ...
- poj1984 带权并查集(向量处理)
Navigation Nightmare Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 5939 Accepted: 2 ...
- 【BZOJ-2299】向量 裴蜀定理 + 最大公约数
2299: [HAOI2011]向量 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1118 Solved: 488[Submit][Status] ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- C#——Dictionary<TKey, TValue> 计算向量的余弦值
说明:三角函数的余弦值Cos我想,每个学计算机的理工人都知道,但是真的明白它的用途,我也是刚明白.每个人在初中或者高中的时候,都有这么个疑惑,学三角函数干什么用的?很直白的答案就是考试用的.而且当时的 ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
随机推荐
- 学习笔记--Java中this关键字
Java中this关键字 关于Java语言中的this关键字 this 是一个关键字,翻译为:这个 this 是一个引用,一个变量,this变量中保存的内存地址指向自身 每一个对象都有自己的this, ...
- Django model 层之Making Query总结
Django model 层之Making Query总结 by:授客 QQ:1033553122 实践环境 Python版本:python-3.4.0.amd64 下载地址:https://www. ...
- Windows版本免费PyMol的安装
技术背景 在前面一篇博客中,我们介绍过在Linux平台下安装和使用免费版本的PyMol.其实同样的这个免费版在Windows平台上(这里以win11为例)也是支持的. 安装流程 这个免费版本的PyMo ...
- CMake学习(一)
CMake学习(一) 1.简介 CMake是一个强大的软件构建系统,可以用简单的语句来描述所有平台的安装(编译过程) 可以编译源代码.制作程序库.产生适配器(wrapper).还可以用任意的顺序建构执 ...
- RHCA rh442 003 系统资源 查看硬件 tuned调优
监控工具 zabbix 监控具体业务,列如数据库.触发式事件(断网 硬盘坏一个) 普罗米修斯 给容器做监控 管理人员,如何知道几千台服务器哪些出了问题,这得需要zabbix 系统硬件资源 cpu [r ...
- 【JavaScript】无框架翻页处理
这个业务太复杂了 输入框的东西要用接口查出来,居然不是用户手动输入 然后我就要做一个翻页的查询列表: <div form id="troublePartSearch" sty ...
- 【SqlServer】01 概念及笔记
视频地址: https://www.bilibili.com/video/BV1qW411y7Bq 一.什么是数据库? 狭义定义: 数据仓库 广义定义: 对数据进行存储和操作的软件,和数据本身合并称为 ...
- 如何在X86_64系统上运行arm架构的docker容器——(异构/不同架构)CPU下的容器启动
近期使用华为的人工智能集群,其中不仅要求异构加速端需要使用昇腾的硬件,更是要求CPU是arm架构的,因此就导致在本地x86电脑上难以对云端的arm版本的镜像进行软件安装和打包操作,为此我们需要在x86 ...
- 再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(5) —— 第一个用于解决2048游戏的Reinforcement learning方法——《Temporal Difference Learning of N-Tuple Networks for the Game 2048》
<2048>游戏在线试玩地址: https://play2048.co/ 如何解决<2048>游戏源于外网的一个讨论帖子,而这个帖子则是讨论如何解决该游戏的最早开始,可谓是&q ...
- 【模板】最近公共祖先:LCA算法
LCA最近公共祖先 \[\begin{align} 要求 \ 给出一个树和他的根节点\text{root} \quad给出Q个询问 回答\text {LCA}(a,b) \end{align} \] ...