MFC中点类的实现

二维点类:

#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;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值