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.

82 lines
2.3 KiB

#pragma once
#include <cmath>
struct PointF {
public:
float x, y, z;
static const float epsilon;
PointF() : x(0), y(0), z(0) {}
PointF(float px, float py, float pz) : x(px), y(py), z(pz) {}
PointF operator+(const PointF& other) const {
return PointF(x + other.x, y + other.y, z + other.z);
}
PointF operator-(const PointF& other) const {
return PointF(x - other.x, y - other.y, z - other.z);
}
PointF operator-() const {
return PointF(-x, -y, -z);
}
PointF operator*(float scalar) const {
return PointF(x * scalar, y * scalar, z * scalar);
}
PointF operator/(float scalar) const {
if (std::abs(scalar) < epsilon) PointF(x,y,z);
return PointF(x / scalar, y / scalar, z / scalar);
}
float dot(const PointF& other) const {
return x * other.x + y * other.y + z * other.z;
}
PointF cross(const PointF& other) const {
return PointF(
y * other.z - z * other.y,
z * other.x - x * other.z,
x * other.y - y * other.x
);
}
float distanceTo(const PointF& other) const {
return std::sqrt((x - other.x) * (x - other.x) +
(y - other.y) * (y - other.y) +
(z - other.z) * (z - other.z));
}
bool operator==(const PointF& other) const {
return std::abs(x - other.x) < epsilon &&
std::abs(y - other.y) < epsilon &&
std::abs(z - other.z) < epsilon;
}
bool operator<(const PointF& other) const {
if (std::abs(x - other.x) >= epsilon) return x < other.x;
if (std::abs(y - other.y) >= epsilon) return y < other.y;
return z < other.z;
}
};
// const float PointF::epsilon = 1e-6f;
struct IniInPutStruct {
PointF vertex1; // 点1坐标
PointF vertex2; // 点2坐标
PointF vertex3; // 点3坐标
int index1; // 点1索引
int index2; // 点2索引
int index3; // 点3索引
PointF normal; // 面法向
};
struct FinOutPutStruct {
PointF start_p; // 起点坐标
PointF end_p; // 终点坐标
PointF start_v; // 起点法线
PointF end_v; // 终点法线
int type; // 类型
};