-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint3D.cpp
More file actions
50 lines (42 loc) · 858 Bytes
/
Copy pathPoint3D.cpp
File metadata and controls
50 lines (42 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include "Point3D.h"
#include "Vector3D.h"
Point3D::Point3D()
: x(0), y(0), z(0)
{
}
Point3D::Point3D(const Point3D& p)
: x(p.x), y(p.y), z(p.z)
{
}
Point3D::Point3D(float x, float y, float z)
: x(x), y(y), z(z)
{
}
Point3D& Point3D::operator=(const Point3D& p)
{
x = p.x;
y = p.y;
z = p.z;
return *this;
}
Point3D Point3D::operator+(const Vector3D& vec) const
{
return Point3D(x + vec.getX(), y + vec.getY(), z + vec.getZ());
}
Vector3D Point3D::operator-(const Point3D& p) const
{
return Vector3D(x - p.x, y - p.y, z - p.z);
}
std::ostream& operator<<(std::ostream& os, const Point3D& p)
{
os << "Point3D[" << p.x << ";" << p.y << ";" << p.z << "]";
return os;
}
float Point3D::getDistanceTo(const Point3D& p) const
{
float a = p.x - x;
float b = p.y - y;
float c = p.z - z;
return sqrt(a*a + b * b + c * c);
}