//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;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LineReflect.rar (7个子文件)
LineReflect
LineReflect
myglbase.cpp 5KB
myglbase.h 2KB
LineReflect.vcproj 4KB
LineReflect.vcproj.Rorger-PC.Rorger.user 1KB
LineReflect.cpp 3KB
LineReflect.suo 12KB
LineReflect.sln 899B
共 7 条
- 1
资源评论
- 星语20133262015-07-27还好,不是很理想
- ssnmq555552013-03-22不行不能用啊
rorger
- 粉丝: 62
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功