You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
#ifndef VECTOR3_HPP
|
|
#define VECTOR3_HPP
|
|
|
|
#include <cmath>
|
|
#include <iostream>
|
|
|
|
class Vector3 {
|
|
private:
|
|
float x_, y_, z_;
|
|
|
|
public:
|
|
Vector3(float x = 0, float y = 0, float z = 0) : x_(x), y_(y), z_(z) {}
|
|
|
|
// 访问器
|
|
float x() const { return x_; }
|
|
float y() const { return y_; }
|
|
float z() const { return z_; }
|
|
|
|
// 运算符
|
|
Vector3 operator+(const Vector3& v) const;
|
|
Vector3 operator-(const Vector3& v) const;
|
|
Vector3 operator*(float s) const;
|
|
Vector3 operator/(float s) const;
|
|
Vector3 operator-() const;
|
|
|
|
// 向量运算
|
|
float dot(const Vector3& v) const;
|
|
Vector3 cross(const Vector3& v) const;
|
|
float norm() const;
|
|
float normSquared() const;
|
|
Vector3 normalized() const;
|
|
|
|
// 比较
|
|
bool operator==(const Vector3& v) const;
|
|
bool operator!=(const Vector3& v) const;
|
|
|
|
// 输出
|
|
friend std::ostream& operator<<(std::ostream& os, const Vector3& v);
|
|
};
|
|
|
|
// 辅助函数:绕任意轴旋转向量(罗德里格斯旋转公式)
|
|
Vector3 rotateAroundAxis(const Vector3& v, const Vector3& axis, float angle);
|
|
|
|
#endif
|