[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 ...
随机推荐
- Bond4配置
Bongding聚合链路工作模式 > bond聚合链路模式共7种:0-6Mode > bond 0 负载均衡 轮询方式往每条链路发送报文,增加带宽和容错能力.容易出现数据包无序到达的问题, ...
- 【Java】使用Druid连接池的监控面板排查慢SQL
默认在后台服务的地址: http://localhost:8078/druid/login.html 账号信息放在配置文件中获取: server: port: 8078 spring: datasou ...
- 【H5】03 文本内容处理
摘自: https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Introduction_to_HTML/HTML_text_fundamentals ...
- pytorch-a2c-ppo-acktr-gail 算法代码
地址: https://github.com/ikostrikov/pytorch-a2c-ppo-acktr-gail
- mybatis升级为mybatis-plus
1.背景 为了快速开发,需要把之前的老项目升级为mybatis-plus 2.步骤 步骤一:导入jar包 <dependency> <groupId>com.baomidou& ...
- 项目管理工具Maven的简单配置示例
Maven是一个强大的项目管理工具,它基于项目对象模型(POM)的概念,通过一小段描述信息来管理项目的构建.报告和文档.以下是一些关于Maven的具体例子,涵盖了项目配置.依赖管理.插件使用等方面: ...
- apollo配置动态更新
简单配置 使用@Value注解的配置会自动刷新配置 复杂对象 @Component("systemConfig") @ConfigurationProperties(prefix ...
- Notes for uc/OS-III User Guide
1. Architecture F2-1(1) The application code consists of project or product files. For convenience, ...
- 一款运行于windows上的linux命令神器-Cmder(已经爱不释手)
一.前言 很多工程师都习惯了使用linux下一些命令,再去用Windows的 cmd 简直难以忍受. 要在windows上运行linux命令,目前比较流行的方式由: GunWin32.Cygwin.W ...
- CF1234D
CF1234D 链接: https://codeforces.com/problemset/problem/1234/D 题目大意: 给你一个字符串s,你需要完成如下q次询问 把 s 的第 p 位改为 ...