forked from jacobwjs/MC-Boost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector3D.h
97 lines (66 loc) · 2.64 KB
/
vector3D.h
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
//
// vectorMath.h
// Xcode
//
// Created by jacob on 7/11/11.
// Copyright 2011 BMPI. All rights reserved.
//
#ifndef VECTOR3D_H
#define VECTOR3D_H
#include "coordinates.h"
#include "boost/shared_ptr.hpp"
#include <iostream>
using std::ostream;
class Vector3d
{
public:
Vector3d();
Vector3d(double x, double y, double z);
Vector3d(const coords &location, const directionCos &dir);
~Vector3d();
// Initializes the direction cosine private data. This allows general use
// of this vector class for objects that have position or position and direction.
void withDirection(void) {direction = boost::shared_ptr<directionCos> (new directionCos);}
// Check if vector object was initialized to have direction.
bool hasDirection(void) {return direction==NULL ? false:true;}
// Overloaded operators for working with Vector3d.
boost::shared_ptr<Vector3d> operator-(Vector3d &rhs);
boost::shared_ptr<Vector3d> operator+(Vector3d &rhs);
boost::shared_ptr<Vector3d> operator*(double num);
boost::shared_ptr<Vector3d> operator*(Vector3d &rhs);
boost::shared_ptr<Vector3d> operator/(double num);
bool operator&(Vector3d &rhs);
inline friend ostream& operator<< (ostream &out, const Vector3d &rhs);
inline friend ostream& operator<< (ostream &out, const boost::shared_ptr<Vector3d> rhs);
// Get the coordinates.
double getDirX(void);
double getDirY(void);
double getDirZ(void);
// Return the direction cosines vector.
boost::shared_ptr<directionCos> getDirection();
// Set the coordinates.
void setDirX(double x);
void setDirY(double y);
void setDirZ(double z);
// Making these public to ease manipulation in vector math.
// No longer need the getters and setters.
coords location; // Structure containing the cartesian coordinates of the photon.
//coords previousLocation; // Holds the coordinates of the previous location of the photon.
//directionCos direction; // Used in checking if the photon had passed through an absorber.
private:
// This is private since not every object that needs location needs direction.
boost::shared_ptr<directionCos> direction; // The direction cosines of the photon.
};
ostream& operator<< (ostream &out, const Vector3d &rhs)
{
out << rhs.location.x << "," << rhs.location.y << "," << rhs.location.z;
return out;
}
ostream& operator<<(ostream &out, const boost::shared_ptr<Vector3d> rhs)
{
out << rhs->location.x
<< "," << rhs->location.y
<< "," << rhs->location.z;
return out;
}
#endif