二维点类:
#include "RGB.h"
class CP2
{
public:
CP2(void);
virtual ~CP2(void);
CP2(double x, double y);
CP2(double x, double y, CRGB c);
friend CP2 operator + (const CP2& p1, const CP2& p2);//运算符重载
friend CP2 operator - (const CP2& p1, const CP2& p2);
friend CP2 operator * (const CP2& p, double scalar);
friend CP2 operator * (double scalar, const CP2& p);
friend CP2 operator / (const CP2& p, double scalar);
public:
double x;
double y;
double w;
CRGB c;
};
CP2::CP2(void) {
x = 0.0;
y = 0.0;
w = 1.0;
c = CRGB(0, 0, 0);
}
CP2::CP2(double x, double y) {
this->x = x;
this->y = y;
c = CRGB(0, 0, 0);
}
CP2::~CP2(void) {
}
CP2::CP2(double x, double y, CRGB c)
{
this->x = x;
this->y = y;
this->c = c;
}
CP2 operator + (const CP2& p1, const CP2& p2)//和
{
CP2 p;
p.x = p1.x + p2.x;
p.y = p1.y + p2.y;
return p;
}
CP2 operator - (const CP2& p1, const CP2& p2)//差
{
CP2 p;
p.x = p1.x - p2.x;
p.y = p1.y - p2.y;
return p;
}
CP2 operator * (const CP2& p, double scalar)//点和常量的积
{
return CP2(p.x * scalar, p.y * scalar);
}
CP2 operator * (double scalar, const CP2& p)//点和常量的积
{
return CP2(p.x * scalar, p.y * scalar);
}
CP2 operator / (const CP2& p1, double scalar)//数除
{
if (fabs(scalar) < 1e-4)
scalar = 1.0;
CP2 p;
p.x = p1.x / scalar;
p.y = p1.y / scalar;
return p;
}
三维点类:
#include "P2.h"
class CP3 :
public CP2
{
public:
CP3(void);
virtual ~CP3(void);
CP3(double x, double y, double z);
public:
double z;
};
CP3::CP3(void) {
x = 0.0;
y = 0.0;
z = 0.0;
w = 1.0;
}
CP3::CP3(double x, double y,double z) {
this->x = x;
this->y = y;
this->z = z;
}
CP3::~CP3(void) {
}
带有法向量的三维点类:
#include "P3.h"
#include "Vector3.h"
class CPi3 :
public CP2
{
public:
CPi3(void);
virtual ~CPi3(void);
CPi3(double x, double y, double z);
CPi3(CP3);
void SetXYZ(CP3);
public:
double z;
CVector3 v;
};