//myblbase.cpp
//rorger, 2011
// last modified:2011-04-28
#include "myglbase.h"
#include "math.h"
Point2::Point2()
{
this->x=0;
this->y=0;
}
Point2::Point2(double x, double y)
{
this->x=x;
this->y=y;
}
void Point2::set(Point2& p)
{
this->x=p.x;
this->y=p.y;
}
void Point2::set(double x, double y)
{
this->x=x;
this->y=y;
}
Point2 Point2::operator /(double rhs)
{
Point2 result ;
result.x=x/rhs;
result.y=y/rhs;
return result;
}
Point2 operator +(Point2& lhs,Vector2& rhs)
{
Point2 result ;
result.x = lhs.x+rhs.x;
result.y = lhs.y+rhs.y;
return result;
}
Point2 operator +(Point2& lhs,Point2& rhs)
{
Point2 result ;
result.x = lhs.x+rhs.x;
result.y = lhs.y+rhs.y;
return result;
}
Point2 operator - (Point2& lhs,Vector2& rhs)
{
return lhs + ((-1)*rhs);
}
Vector2 operator - (Point2& lhs,Point2& rhs)
{
Vector2 result ;
result.x = lhs.x-rhs.x;
result.y = lhs.y-rhs.y;
return result;
}
Point2 operator* (Point2& lhs,double rhs)
{
Point2 result ;
result.x=lhs.x * rhs ;
result.y = lhs.y * rhs ;
return result;
}
Point2 operator* (double lhs,Point2& rhs)
{
return rhs* lhs;
}
ostream& operator << (ostream& outputStream,Point2&rhs)
{
outputStream<<"("<<rhs.x<<","<<rhs.y<<")";
return outputStream ;
}
//implementation for class Vector2
Vector2::Vector2()
{
this->x=0;
this->y=0;
}
Vector2::Vector2(double x, double y)
{
this->x=x;
this->y=y;
}
void Vector2::set(Vector2&p)
{
this->x=p.x;
this->y=p.y;
}
void Vector2::set(double x, double y)
{
this->x= x ;
this->y=y ;
}
Vector2 Vector2::operator /(double rhs)
{
Vector2 result ;
result.x = this->x / rhs ;
result.y = this->y / rhs ;
return result;
}
Vector2 operator +(Vector2&lhs,Vector2&rhs)
{
Vector2 result ;
result.x = lhs.x + rhs.x ;
result.y = lhs.y + rhs.y ;
return result;
}
Vector2 operator - (Vector2&lhs,Vector2& rhs)
{
Vector2 result ;
result.x = lhs.x - rhs.x ;
result.y = lhs.y - rhs.y ;
return result;
}
double operator *(Vector2&lhs,Vector2& rhs)
{
double result ;
result = lhs.x * rhs.x + lhs.y * rhs.y ;
return result;
}
Vector2 operator *(Vector2&lhs,double rhs)
{
Vector2 result ;
result.x = lhs.x*rhs ;
result.y = lhs.y*rhs ;
return result;
}
Vector2 operator *(double lhs,Vector2& rhs)
{
return rhs*lhs;
}
double Vector2::GetLength()
{
return sqrt(this->x*this->x+this->y*this->y);
}
void Vector2::Normalized()
{
double length = GetLength();
this->x = x / length ;
this->y = y / length ;
}
Vector2 Vector2::GetNormalVector()
{
Vector2 result ;
result.x = -1*this->y;
result.y = this->x ;
return result ;
}
ostream& operator << (ostream& outputStream,Vector2&rhs)
{
outputStream<<"("<<rhs.x<<","<<rhs.y<<")";
return outputStream ;
}
//implementation for Vector3
Vector3::Vector3()
{
this->x= this->y=this->z=0;
}
void Vector3::set(Vector3&p)
{
this->x = p.x ;
this->y =p.y ;
this->z =p.z;
}
void Vector3::set(double x, double y, double z)
{
this->x=x;
this->y=y;
this->z=z;
}
double Vector3::GetLength()
{
return sqrt(this->x*this->x+this->y*this->y+this->z*this->z);
}
void Vector3::Normalized()
{
double length=GetLength();
this->x=x/length;
this->y=y/length;
this->z=z/length;
}
Vector3 Vector3::GetNormalVector()
{
throw "NotImplemented Implementation.";
}
Vector3 operator +(Vector3&lhs,Vector3&rhs)
{
Vector3 result ;
result.x = lhs.x + rhs.x ;
result.y = lhs.y + rhs.y ;
result.z = lhs.z + rhs.z ;
return result;
}
Vector3 operator - (Vector3&lhs,Vector3& rhs)
{
Vector3 result ;
result.x = lhs.x - rhs.x ;
result.y = lhs.y - rhs.y ;
result.z = lhs.z - rhs.z ;
return result;
}
double operator *(Vector3&lhs,Vector3& rhs)
{
double result ;
result = lhs.x * rhs.x +lhs.y * rhs.y + lhs.z * rhs.z ;
return result;
}
Vector3 operator *(Vector3&lhs,double rhs)
{
Vector3 result ;
result.x = lhs.x * rhs ;
result.y = lhs.y * rhs ;
result.z = lhs.z * rhs ;
return result;
}
Vector3 Vector3::operator /(double rhs)
{
Vector3 result ;
result.x = this->x / rhs ;
result.y = this->y / rhs ;
result.z = this->z / rhs ;
return result ;
}
ostream& operator << (ostream& outputStream,Vector3& rhs)
{
cout <<"("<< rhs.x<<","<<rhs.y<<","<<rhs.z<<")";
return outputStream;
}
//implementation for Point3
Point3::Point3()
{
this->x = this->y = this->z = 0 ;
}
void Point3::set(Point3& p)
{
this->x = p.x ;
this->y = p.y ;
this->z = p.z ;
}
void Point3::set(double x, double y, double z)
{
this->x = x ;
this->y = y ;
this->z = z ;
}
Point3 Point3::operator /(double rhs)
{
Point3 result ;
result.x = this->x / rhs;
result.y = this->y / rhs ;
result.z = this->z / rhs ;
return result ;
}
Point3 operator +(Point3& lhs,Vector3& rhs)
{
Point3 result ;
result.x = lhs.x + rhs.x ;
result.y = lhs.y + rhs.y ;
result.z = lhs.z + rhs.z ;
return result ;
}
Vector3 operator - (Point3& lhs,Point3& rhs)
{
Vector3 result ;
result.x = lhs.x - rhs.x ;
result.y = lhs.y - rhs.y ;
result.z = lhs.z - rhs.z ;
return result ;
}
Point3 operator* (Point3& lhs,double rhs)
{
Point3 result ;
result.x = lhs.x * rhs ;
result.y = lhs.y * rhs;
result.z = lhs.z * rhs ;
return result ;
}
ostream& operator << (ostream& outputStream,Point3& rhs)
{
cout <<"("<< rhs.x<<","<<rhs.y<<","<<rhs.z<<")";
return outputStream;
}

rorger
- 粉丝: 62
- 资源: 18
最新资源
- 直齿轮裂纹对摩擦时变啮合刚度的影响:基于Matlab程序的研究分析,直齿轮裂纹与摩擦影响下时变啮合刚度仿真分析算法matlab实现,直齿轮裂纹,摩擦时变啮合刚度matlab程序 ,直齿轮裂纹; 啮合刚
- 3步集成DeepSeek搜索API:从RESTful调用到结果优化全流程.pdf
- 5分钟搞定DeepSeekAPI密钥申请与OpenAISDK无缝迁移指南.pdf
- 5分钟快速入门:DeepSeek私有化部署与GPU资源分配指南.pdf
- 5分钟快速上手:DeepSeekAPI调用全流程详解.pdf
- 10倍效率提升!DeepSeek多Token预测功能的代码级优化.pdf
- 10分钟掌握DeepSeekAPI调用:从注册到第一个请求的完整流程解析.pdf
- 10分钟掌握DeepSeekAPI核心调用:从密钥获取到Python、Node.js实战示例.pdf
- 13个场景化案例:用DeepSeekAPI实现代码生成与文本改写.pdf
- 10个DeepSeekAPI必知技巧:从鉴权到流式处理的开发全指南.pdf
- 128Ktokens长上下文处理:DeepSeek-R1打破行业限制的技术突破.pdf
- 64K上下文长度压测:DeepSeek-V3模型Token消耗优化全解析.pdf
- 128k超长文本处理:DeepSeekV3技术白皮书核心能力解密.pdf
- API成本直降95%!DeepSeek缓存机制与批量请求实战.pdf
- API安全攻防战:DeepSeek接口鉴权漏洞扫描与OAuth2.0加固方案.pdf
- 2025年人工智能变革元年-DeepSeek引领AI算法与应用新时代
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


