point3d.cc 2.05 KB
Newer Older
1
2
3
4
5
6
7
/*
 * File:   point3d.cc
 * Author: Jordan P. Lefebvre, lefebvre.jordan@gmail.com
 *
 * Created on August 9, 2012, 5:47 PM
 */

8
#include "radixmath/point3d.hh"
9
10
11
#include <cmath>
#include <sstream>

12
namespace radix {
13
14
15
16

/**
 * Default Constructor
 */
17
18
19
20
Point3D::Point3D()
    : x(0)
    , y(0)
    , z(0) {}
21
22
23
24
25

/**
 * Constructor
 * @param a
 */
26
27
28
29
Point3D::Point3D(const Real a)
    : x(a)
    , y(a)
    , z(a) {}
30
31
32
33
34
35
36

/**
 * Constructor
 * @param a
 * @param b
 * @param c
 */
37
38
39
40
Point3D::Point3D(const Real a, const Real b, const Real c)
    : x(a)
    , y(b)
    , z(c) {}
41
42
43
44
45

/**
 * Copy constructor
 * @param p
 */
46
47
48
49
Point3D::Point3D(const Point3D &p)
    : x(p.x)
    , y(p.y)
    , z(p.z) {}
50
51
52
53

/**
 * Destructor
 */
54
Point3D::~Point3D() {}
55

56
57
Point3D &Point3D::operator=(const Point3D &rhs) {
  if (this == &rhs) return (*this);
58

59
60
61
  x = rhs.x;
  y = rhs.y;
  z = rhs.z;
62

63
  return (*this);
64
65
66
67
68
69
}

/**
 * @function distance
 * @brief distance between two points
 */
70
71
72
Real Point3D::distance(const Point3D &p) const {
  return (std::sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) +
                    (z - p.z) * (z - p.z)));
73
74
75
76
77
78
}

/**
 * @function operator*
 * @brief multiplication by a matrix on the left
 */
79
80
81
82
83
84
85
Point3D operator*(const Matrix &mat, const Point3D &p) {
  return (Point3D(mat.matrix[0][0] * p.x + mat.matrix[0][1] * p.y +
                      mat.matrix[0][2] * p.z + mat.matrix[0][3],
                  mat.matrix[1][0] * p.x + mat.matrix[1][1] * p.y +
                      mat.matrix[1][2] * p.z + mat.matrix[1][3],
                  mat.matrix[2][0] * p.x + mat.matrix[2][1] * p.y +
                      mat.matrix[2][2] * p.z + mat.matrix[2][3]));
86
}
87
88
89
90
91
std::string Point3D::toString() const {
  std::stringstream stream;
  stream.precision(13);
  stream << "[" << x << ", " << y << ", " << z << "]";
  return stream.str();
92
}
93
94
95
96
97
98

/**
 * @function operation-
 * @param p Point3D
 * @return
 */
99
100
Vector3D Point3D::operator-(const Point3D &p) const {
  return (Vector3D(x - p.x, y - p.y, z - p.z));
101
102
}

103
104
std::ostream &operator<<(std::ostream &os, const Point3D &p) {
  return os << p.toString();
105
}
106
}  // namespace radix