vector3d 模版表示一个 3D 向量
3D 点和 3D 向量是3D图形学里最基础的东西
里面有一些方法是需要一点 3D 图形学基础的,但是也非常简单喽
【运算符重载】
首先是一些运算符的重载
注意一点的是加法和减法运算符实现的是对向量的平移
乘法和除法运算符分别是对当前每一个分量乘以和除以 other 的每一个分量
而判断大于等于的条件是要向量每一个分量都大于 other
vector3d<T>& operator=(const vector3d<T>& other) { X = other.X; Y = other.Y; Z = other.Z; return *this; }
vector3d<T> operator+(const vector3d<T>& other) const { return vector3d<T>(X + other.X, Y + other.Y, Z + other.Z); }
vector3d<T>& operator+=(const vector3d<T>& other) { X+=other.X; Y+=other.Y; Z+=other.Z; return *this; }
vector3d<T> operator-(const vector3d<T>& other) const { return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z); }
vector3d<T>& operator-=(const vector3d<T>& other) { X-=other.X; Y-=other.Y; Z-=other.Z; return *this; }
vector3d<T> operator*(const vector3d<T>& other) const { return vector3d<T>(X * other.X, Y * other.Y, Z * other.Z); }
vector3d<T>& operator*=(const vector3d<T>& other) { X*=other.X; Y*=other.Y; Z*=other.Z; return *this; }
vector3d<T> operator*(const T v) const { return vector3d<T>(X * v, Y * v, Z * v); }
vector3d<T>& operator*=(const T v) { X*=v; Y*=v; Z*=v; return *this; }
vector3d<T> operator/(const vector3d<T>& other) const { return vector3d<T>(X / other.X, Y / other.Y, Z / other.Z); }
vector3d<T>& operator/=(const vector3d<T>& other) { X/=other.X; Y/=other.Y; Z/=other.Z; return *this; }
vector3d<T> operator/(const T v) const { T i=(T)1.0/v; return vector3d<T>(X * i, Y * i, Z * i); }
vector3d<T>& operator/=(const T v) { T i=(T)1