From e6caf49e27eb017fee29e1d89e526def75f93d56 Mon Sep 17 00:00:00 2001 From: yony Date: Wed, 29 May 2024 11:33:15 +0800 Subject: [PATCH] =?UTF-8?q?point=E5=AE=9A=E4=B9=89=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Path.h | 9 +++- include/Point.h | 111 ++++++------------------------------------------ src/Point.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 98 deletions(-) create mode 100644 src/Point.cpp diff --git a/include/Path.h b/include/Path.h index fd6b821..1df8528 100644 --- a/include/Path.h +++ b/include/Path.h @@ -9,7 +9,14 @@ #include #include using namespace std; - +P dirP(P &A) +{ + P B; + B.x = A.dx; + B.y = A.dy; + B.z = A.dz; + return B; +} // 简单的路径信息,路径规划的直接结果 struct Path { diff --git a/include/Point.h b/include/Point.h index 731136f..fc540af 100644 --- a/include/Point.h +++ b/include/Point.h @@ -13,106 +13,23 @@ struct P int type; // 0卡箍 1未确定分支点 2已确定分支点 3连接器 int ref; // 指向其代表的相应数据类型标号 - bool operator<(P B) const - { - if (!Equal(x, B.x)) - return x < B.x; - if (!Equal(y, B.y)) - return y < B.y; - if (!Equal(z, B.z)) - return z < B.z; - return false; - } - bool operator==(P B) const - { - return Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z); - } - bool operator!=(P B) const - { - return !(Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z)); - } + bool operator<(P B) const; + bool operator==(P B) const; + bool operator!=(P B) const; - void set(int i, double v) - { - if (i == 0) - x = v; - else if (i == 1) - y = v; - else if (i == 2) - z = v; - } - const double get(int i) - { - if (i == 0) - return x; - else if (i == 1) - return y; - else if (i == 2) - return z; + void set(int i, double v); + const double get(int i); - return 0; - } + void reverse(); - void reverse() - { - dx = -dx; - dy = -dy; - dz = -dz; - } - - P(double x1, double y1, double z1) - { - x = x1; - y = y1; - z = z1; - dx = 0; - dy = dz = 0; - isend = 0; - type = ref = 0; - } - P() - { - x = y = z = 0; - dx = 0; - dy = dz = 0; - isend = 0; - type = ref = 0; - } - P operator-(P B) const - { - return P(x - B.x, y - B.y, z - B.z); - } - P operator+(P B) const - { - return P(x + B.x, y + B.y, z + B.z); - } - P operator*(double p) const - { - return P(x * p, y * p, z * p); - } - P operator/(double p) const - { - return P(x / p, y / p, z / p); - } - void print(string s) - { - cout << s << setprecision(10) << " : " << x << " " << y << " " << z << endl; - return; - } + P(double x1, double y1, double z1); + P(); + P operator-(P B) const; + P operator+(P B) const; + P operator*(double p) const; + P operator/(double p) const; + void print(string s); // 设置方向 - void setDir(const P &dir) - { - dx = dir.x; - dy = dir.y; - dz = dir.z; - } + void setDir(const P &dir); }; -P dirP(P &A) -{ - P B; - B.x = A.dx; - B.y = A.dy; - B.z = A.dz; - return B; -} \ No newline at end of file diff --git a/src/Point.cpp b/src/Point.cpp new file mode 100644 index 0000000..3605467 --- /dev/null +++ b/src/Point.cpp @@ -0,0 +1,97 @@ +#include "Point.h" + + +bool P::operator<(P B) const +{ + if (!Equal(x, B.x)) + return x < B.x; + if (!Equal(y, B.y)) + return y < B.y; + if (!Equal(z, B.z)) + return z < B.z; + return false; +} +bool P::operator==(P B) const +{ + return Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z); +} +bool P::operator!=(P B) const +{ + return !(Equal(x, B.x) && Equal(y, B.y) && Equal(z, B.z)); +} + +void P::set(int i, double v) +{ + if (i == 0) + x = v; + else if (i == 1) + y = v; + else if (i == 2) + z = v; +} +const double P::get(int i) +{ + if (i == 0) + return x; + else if (i == 1) + return y; + else if (i == 2) + return z; + + return 0; +} + +void P::reverse() +{ + dx = -dx; + dy = -dy; + dz = -dz; +} + +P::P(double x1, double y1, double z1) +{ + x = x1; + y = y1; + z = z1; + dx = 0; + dy = dz = 0; + isend = 0; + type = ref = 0; +} +P::P() +{ + x = y = z = 0; + dx = 0; + dy = dz = 0; + isend = 0; + type = ref = 0; +} +P P::operator-(P B) const +{ + return P(x - B.x, y - B.y, z - B.z); +} +P P::operator+(P B) const +{ + return P(x + B.x, y + B.y, z + B.z); +} +P P::operator*(double p) const +{ + return P(x * p, y * p, z * p); +} +P P::operator/(double p) const +{ + return P(x / p, y / p, z / p); +} +void P::print(string s) +{ + cout << s << setprecision(10) << " : " << x << " " << y << " " << z << endl; + return; +} + +// 设置方向 +void P::setDir(const P &dir) +{ + dx = dir.x; + dy = dir.y; + dz = dir.z; +}