[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 ...
随机推荐
- .NET周刊【7月第3期 2024-07-21】
国内文章 给博客园的寄语 https://www.cnblogs.com/jingc/p/18307859 作者是一名39岁的大龄C#开发程序员,对博客园的艰难处境深感触动,并购买会员支持.回顾他与博 ...
- ios的idp/iep证书的生成方法,无苹果电脑
在这个多端开发的年代,出现了很多优秀的开发框架,比如hbuilder和uniapp等等.我们可以使用这些框架来开发APP,假如我们要打包ios的app,则需要一个idp/iep证书. 那么这个证书是如 ...
- HDP 源码集
HDP 各个组件的源码(含历史各个版本) 分支 组件 标签 最后发版时间 地址 hadoop 2256 2020-12-21 17:44 https://gitee.com/piaolingzxh/h ...
- [香橙派开发系列]3b系统安装和使用vscode进行远程连接
目录 前言 一.下载镜像和安装系统 二.使用串口助手进行调试 三.查看系统的ip地址 四.使用vscode连接香橙派 最后 前言 之前研究中断的时候一直出现问题,我怀疑是因为zero 3不支持,所以一 ...
- 【Java】Oshi 硬件信息读取库
实现的功能: 用于开发服务器监控面板,获取服务器硬件参数 官方Github仓库地址: https://github.com/oshi/oshi Maven坐标: <!-- https://mvn ...
- Linux磁盘/硬盘测速,dd命令
参考: https://blog.csdn.net/Franciz777/article/details/126779259 ===================================== ...
- 8月5日CSP-S模拟赛赛后总结
8月5日CSP-S模拟赛赛后总结 \[8月5日 \ \ CSP-S模拟赛 \ \ 赛后总结 \\ 2024年8月5日 \\ by \ \ \ uhw177po \] 一.做题情况 第一题比赛 \(10 ...
- Apache SeaTunnel 4月回顾:明星贡献者与技术突破
各位热爱 SeaTunnel 的小伙伴们,SeaTunnel 社区 4 月份月报来啦!这里将记录 SeaTunnel 社区每月的重要更新,欢迎关注! 月度 Merge 之星 感谢以下小伙伴 4 月为 ...
- Java解决递归造成的堆栈溢出问题
在Java中,递归造成的堆栈溢出问题通常是因为递归调用的深度过大,导致调用栈空间不足.解决这类问题的一种常见方法是使用非递归的方式重写算法,即使用迭代替代递归. 1.方法一:非递归的方式重写算法(迭代 ...
- Pintia 天梯地图 dijkstra进阶
7-14 天梯地图 - SMU 2024 spring 天梯赛3(补题) (pintia.cn) dijkstra进阶做法,包含路径记录,以及按权重统计路径条件等; 不过最开始我一直将优先队列开的最大 ...