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.
105 lines
1.5 KiB
105 lines
1.5 KiB
9 months ago
|
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
|
||
|
#include "Point.h"
|
||
|
|
||
|
const double eps = 1e-6;
|
||
|
|
||
|
bool Equal(double a, double b)
|
||
|
{
|
||
|
return ((fabs(a - b) < eps) ? true : false);
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
9 months ago
|
// 设置方向
|
||
9 months ago
|
void P::setDir(const P &dir)
|
||
|
{
|
||
|
dx = dir.x;
|
||
|
dy = dir.y;
|
||
|
dz = dir.z;
|
||
|
}
|