-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.cpp
53 lines (42 loc) · 923 Bytes
/
Point.cpp
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
51
52
53
#include "Point.hh"
#include "math.h"
// Default constructor: initializes the point to (0, 0).
Point::Point() {
x_coord = 0;
y_coord = 0;
z_coord = 0;
}
// Initializes the point to (x, y).
Point::Point(double x, double y, double z) {
x_coord = x;
y_coord = y;
z_coord = z;
}
// Destructor - Point allocates no dynamic resources.
Point::~Point() {
// no-op
}
// Mutators:
void Point::setX(double val) {
x_coord = val;
}
void Point::setY(double val) {
y_coord = val;
}
void Point::setZ(double val) {
z_coord = val;
}
// Accessors:
double Point::GetX() const{
return x_coord;
}
double Point::GetY() const{
return y_coord;
}
double Point::GetZ() const{
return z_coord;
}
double Point::Distance(const Point& Cpoint) const
{
return sqrt((Cpoint.GetX()-x_coord)*(Cpoint.GetX()-x_coord) + (Cpoint.GetY()-y_coord)*(Cpoint.GetY()-y_coord) + (Cpoint.GetZ()-z_coord)*(Cpoint.GetZ()-z_coord));
}