-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPoint.h
More file actions
executable file
·117 lines (95 loc) · 2.39 KB
/
Copy pathPoint.h
File metadata and controls
executable file
·117 lines (95 loc) · 2.39 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// Point.h
//
//
// Created by Ling Zou on 5/27/13.
//
//
#ifndef _Point_h
#define _Point_h
#include <cmath>
#include <stdlib.h>
#include <iostream>
class Vec3d {
public:
Vec3d() : _x(0.0), _y(0.0), _z(0.0) {}
~Vec3d() {}
Vec3d(double xx, double yy, double zz) :
_x(xx), _y(yy), _z(zz)
{}
void print() const { std::cout << "(" << _x << ", " << _y << ", " << _z << ")" << std::endl; }
const double x() const { return _x; }
const double y() const { return _y; }
const double z() const { return _z; }
double & x() { return _x; }
double & y() { return _y; }
double & z() { return _z; }
inline Vec3d operator+ (const Vec3d & v) const {
return Vec3d(x() + v.x(), y() + v.y(), z() + v.z()); }
inline Vec3d operator- (const Vec3d & v) const {
return Vec3d(x() - v.x(), y() - v.y(), z() - v.z()); }
inline double operator * (const Vec3d & v) const {
return x() * v.x() + y() * v.y() + z() * v.z(); }
inline Vec3d operator / (const double & s) const
{
if(s == 0) // Not the best way to check 0; FIXME
{
std::cerr << "File: " << __FILE__ << std::endl;
std::cerr << "Function: " << __FUNCTION__ << std::endl;
std::cerr << "Line: " << __LINE__ << std::endl;
std::cerr << "ERROR: Vec3d divided by zero.\n";
exit(1);
}
else
return Vec3d(x()/s, y()/s, z()/s);
}
inline Vec3d cross(const Vec3d & v) {
return Vec3d(y() * v.z() - z() * v.y(),
z() * v.x() - x() * v.z(),
x() * v.y() - y() * v.x());
}
double norm() {
return std::sqrt(_x * _x + _y * _y + _z * _z); }
Vec3d unitVector()
{
if(norm() == 0) // Not the best way to check 0; FIXME
return Vec3d(0, 0, 0);
else
return (*this) / norm();
}
protected:
double _x, _y, _z;
};
class Point
{
public:
Point() : _x(0.0), _y(0.0), _z(0.0)
{}
Point(double xx, double yy, double zz) :
_x(xx),
_y(yy),
_z(zz)
{
}
~Point()
{}
double x() const { return _x; }
double y() const { return _y; }
double z() const { return _z; }
double & x() { return _x; }
double & y() { return _y; }
double & z() { return _z; }
inline
Point operator+ (const Point & p) const
{
return Point(x() + p.x(), y() + p.y(), z() + p.z());
}
inline
Vec3d operator- (const Point & p) const
{
return Vec3d(x() - p.x(), y() - p.y(), z() - p.z());
}
protected:
double _x, _y, _z;
};
#endif