1、点 SPoint

#pragma once
#ifndef UNIVERSE_SPACE_SPOINT
#define UNIVERSE_SPACE_SPOINT
#include "Smath.h"
class SVector;
class SMatrix;
class SPoint {
public:
	SRGBA color;
	double x;
	double y;
	double z;
public:
	SPoint(double meax = 0, double meay = 0, double meaz = 0) { x = meax; y = meay; z = meaz; };
	~SPoint() { };

	double GetModulus();			//到原点的距离
	SPoint operator = (const SVector& vect);
	SPoint operator = (const SPoint& point);
	bool operator == (const SPoint& point);
	bool operator != (const SPoint& point);
	SPoint operator += (const SVector& vec);
	SPoint operator -= (const SVector& vec);
	SPoint operator *= (const SMatrix& mat);
	friend SPoint operator + (const SPoint& pot, const SVector& vec);//点移动
	friend SPoint operator - (const SPoint& pot, const SVector& vec);//点移动
	friend SPoint operator * (const SPoint& pot, const SVector& vec);//点缩放
	friend SPoint operator * (const SPoint& pot, const SMatrix& mat);
	friend SPoint operator * (const SMatrix& mat, const SPoint& pot);
};

typedef std::vector<SPoint> SPoints;
#endif // !UNIVERSE_SPACE_SPOINT

2、线 SLine

#pragma once
#ifndef UNIVERSE_SPACE_SLINE
#define UNIVERSE_SPACE_SLINE
#include "Smath.h"
#include "SPoint.h"
#include "SVector.h"
class SLine {
public:
	SRGBA color;
	SPoint op;
	SPoint ed;
public:
	SLine(SPoint ptstar = SPoint(), SPoint ptend = SPoint()) { op = ptstar; ed = ptend; };
	SLine(SPoints pts) { op = pts[0]; ed = pts[1]; };
	~SLine() { };

	double GetLength();
	double AngleLine(SLine line);
	double LenLine(SPoint point);
	bool InLine(SPoint point);
	bool InLine(SLine line);
	SLine operator = (const SLine& line);
	bool operator == (const SLine& line);
	bool operator != (const SLine& line);
	SLine operator += (const SVector& vec);
	SLine operator -= (const SVector& vec);
	SLine operator *= (const SMatrix& mat);
	friend SLine operator + (const SLine& line, const SVector& vec);
	friend SLine operator - (const SLine& line, const SVector& vec);
	friend SLine operator * (const SLine& line, const SMatrix& mat);
	friend SLine operator * (const SMatrix& mat, const SLine& line);
};

typedef std::vector<SLine> SLines;
typedef SLines CurveLine;

class SCurveline {
public:
	bool useColor = false;
	SRGBA color;
	CurveLine lines;
public:
	SCurveline() {};
	SCurveline(SLines lines);
	SCurveline(SPoints pts);
	~SCurveline() { lines.clear(); };
	void push_back(SPoint point);


	double GetLength();
	double LenCurveline(SPoint point);
	bool InCurveline(SPoint point);
	bool InCurveline(SLine line);

	SLine& operator[](const int n);
	SCurveline operator = (const SCurveline& curveline);
	bool operator == (const SCurveline& curveline);
	bool operator != (const SCurveline& curveline);
	SCurveline operator += (const SVector& vec);
	SCurveline operator -= (const SVector& vec);
	SCurveline operator *= (const SMatrix& mat);
};
#endif // !UNIVERSE_SPACE_SLINE

3、面 SFace

#pragma once
#ifndef UNIVERSE_SPACE_SFACE
#define UNIVERSE_SPACE_SFACE
#include "Smath.h"
#include "SPoint.h"
#include "SLine.h"
#include "SVector.h"

class SFace {
public:
	SRGBA color;
	SPoint A;
	SPoint B;
	SPoint C;
protected:
	SVector normal;
public:
	SFace(SPoint ptA = SPoint(), SPoint ptB = SPoint(), SPoint ptC = SPoint()) { A = ptA; B = ptB; C = ptC; };
	SFace(SPoints pts) { A = pts[0]; B = pts[1]; C = pts[2]; };
	~SFace() { };

	void SetNormal(SVector nor) { normal = nor; }
	void GetNormal(SVector&nor) { nor = normal; }
	double ABLength();
	double BCLength();
	double CALength();
	double AngleA();
	double AngleB();
	double AngleC();
	double GetArea();
	double LenFace(SPoint point);
	bool InFace(SPoint point);
	bool InFace(SLine line);
	bool InFace(SFace face);
	//bool InFace(SCurveline Curveline);
	SFace operator = (const SFace& face);
	bool operator == (const SFace& face);
	bool operator != (const SFace& face);
	SFace operator += (const SVector& vec);
	SFace operator -= (const SVector& vec);
	SFace operator *= (const SMatrix& mat);
	friend SFace operator + (const SFace& face, const SVector& vec);
	friend SFace operator - (const SFace& face, const SVector& vec);
	friend SFace operator * (const SFace& face, const SMatrix& mat);
	friend SFace operator * (const SMatrix& mat, const SFace& face);
};

typedef std::vector<SFace> SFaces;
typedef SFaces CurveFace;

class SCurveface {

public:
	bool useColor = false;
	SRGBA color;
	CurveFace faces;
public:
	SCurveface() {};
	~SCurveface() { faces.clear(); };
	void push_back(SFace face);


	double GetArea();
	double LenCurve(SPoint point);
	bool InCurveface(SPoint point);


	SFace operator[](const int n);
	SCurveface operator = (const SCurveface& curveface);
	bool operator == (const SCurveface& curveface);
	bool operator != (const SCurveface& curveface);
	SCurveface operator += (const SVector& vec);
	SCurveface operator -= (const SVector& vec);
	SCurveface operator *= (const SMatrix& mat);
};
#endif // !UNIVERSE_SPACE_SFACE

4、体 SCube

#pragma once
#ifndef UNIVERSE_SPACE_SCUBE
#define UNIVERSE_SPACE_SCUBE
#include "Smath.h"
#include "SPoint.h"
#include "SLine.h"
#include "SFace.h"
class SCube
{
public:
	SRGBA color;
	SPoint top[4];
public:
	SCube(SPoint top0 = SPoint(), SPoint top1 = SPoint(), SPoint top2 = SPoint(), SPoint top3 = SPoint());
	~SCube(){};

	double GetVolume();			//体积
	SCube operator = (const SCube& cube);
	bool operator == (const SCube& cube);
	bool operator != (const SCube& cube);
	SCube operator += (const SVector& vec);
	SCube operator -= (const SVector& vec);
	SCube operator *= (const SMatrix& mat);
	friend SCube operator + (const SCube& cube, const SVector& vec);//点移动
	friend SCube operator - (const SCube& cube, const SVector& vec);//点移动
	friend SCube operator * (const SCube& cube, const SMatrix& mat);
	friend SCube operator * (const SMatrix& mat, const SCube& cube);
};
typedef std::vector<SCube> SCubes;

#endif // !UNIVERSE_SPACE_SCUBE

5、说明

我们的世界存在三个维度,自然,为了描述三维世界的点,也就需要三个参量。

在相应的数学理论中,一个三维空间坐标系存在三根轴,三根轴互不干涉,也就是直角坐标系,我将其称之为恒坐标系。三根轴对应了三个向量,所以一个三维坐标系也就是一个3阶方阵,由坐标轴对应的向量组成。

因为点与向量等价,坐标系与矩阵等价,而在3阶矩阵中,秩最大为3,所以在三维坐标系中可以容纳一个最多由n+1 = 4个向量(点)所构成的空间对象,也就是说,三维空间坐标系中存在四种空间对象,点(一个向量),线(二个向量),面(三个向量),体(四个向量)。