-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.h
More file actions
142 lines (111 loc) · 4.07 KB
/
Node.h
File metadata and controls
142 lines (111 loc) · 4.07 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// Created by lucy on 04/03/25.
//
#ifndef NODE_H
#define NODE_H
#include <cmath>
#include "Particle.h"
#include <utility>
#include <vector>
class Node {
// Class to represent a node in an octree
// The node has a position, size, and children
public:
/*****************************************//**
* Constructor for the Node class
* @param posX: Initial x position of the node in parsecs
* @param posY: Initial y position of the node in parsecs
* @param posZ: Initial z position of the node in parsecs
* @param size: Size of a side of the node (box) in parsecs
******************************************/
Node(
long double posX, long double posY, long double posZ,
long double size) :
posX(posX), posY(posY), posZ(posZ), size(size) {
// Constructor for the Node class
// x, y, z: position of the node
// size: size of a side of the node (box)
for (auto & i : children) {
i = nullptr;
}
}
/** @brief Position of the center of the node (box) */
long double posX, posY, posZ;
/** @brief Size of a side of the node (box) in parsecs */
long double size;
/** @brief Half size of the node (box) in parsecs */
long double halfSize = size / 2.0;
/** @brief Children of the node (8 children for an octree) */
Node* children[8];
/** @brief Vector of particles in the node */
std::vector<Particle*> particles;
/** @brief Center of mass of the node */
long double comX, comY, comZ;
/** @brief Total mass of the node in solar masses */
double totalMass;
/**
* @brief Method to make the children of the node
*/
void makeChildren();
/**
* @brief Method to add a particle to this node
* @param particle: Particle to add to the node
*/
void addParticle(Particle* particle);
/**
* @brief Method to check if this node contains the particle
* @param particle: Particle to check
* @return true if the node contains the particle, false otherwise
*/
bool containsParticle(const Particle &particle) const;
/**
* @brief Method to calculate the center of mass of the node
*/
void calculateCOM();
/**
* @brief Method to print the node information
*/
void printNode() const;
/**
* @brief Update all particles in the root node (sim area)
* @param deltaTime: Time step for the simulation in seconds
* @param pheta: The threshold for the size to distance ratio
*/
void updateParticlesRoot(double deltaTime, float pheta);
/**
* @brief Delete the children of the node (recursively)
*/
void deleteChildren();
/**
* @brief Update the particle passed in (assuming the particle is in this node)
* @param pheta: The threshold for the size to distance ratio
* @param particle: Particle to update
*/
void updateParticleNode(float pheta, Particle* particle);
/**
* @brief Check if the node is empty
* @return true if the node is empty, false otherwise
*/
long double getDistToNode(Particle* p);
/**
* @brief Get the normalised vector (direction) from this node to another node eg (0.1,0.5,0.9)
* @param other: The other node to get the vector to
* @param distance: The distance between the two nodes
* @return A vector containing the normalised vector from this node to the other node
*/
std::vector<long double> getNormalisedVector(Node *other, double distance) const;
/**
* @brief Get the size to distance ratio for the particle to this node
* @param p: Particle to get the size to distance ratio for
* @return The size to distance ratio
*/
double getSDRatio(Particle* p);
/**
* @brief Get the acceleration on a particle due to the mass of this node
* @param mass: Mass of this node in solar masses
* @param distance: Distance to the particle in parsecs
* @return The acceleration on the particle in km/s^2
*/
long double getAcceleration(double mass, long double distance);
};
#endif //NODE_H