-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.cpp
More file actions
62 lines (57 loc) · 2.15 KB
/
simulator.cpp
File metadata and controls
62 lines (57 loc) · 2.15 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
/*
* simulator.cpp
*
* This file is part of acts
*
* Copyright (C) 2015 Enrico Polesel <enrico.polesel@sns.it>,
* Copyright (C) 2015 Andrea Stacchiotti <andrea.stacchiotti@sns.it>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
*/
#include <cmath>
#include "simulator.hpp"
#include "utilities.hpp"
Vec3D Simulator::calculate_nonfriction(const Vec3D position, const Vec3D velocity) const
// Calculate all the non-friction accelerations (gravity & non-inertial)
{
Vec3D vecGravity = Vec3D(0, 0, -gravity);
Vec3D vecNonInertial = - this->omega ^ ( 2 * velocity + (this->omega ^ position) );
return vecGravity + vecNonInertial;
}
Event Simulator::simulate (const Launch launch)
{
Vec3D position(0,0,0);
Vec3D velocity = launch.speed * Vec3D(
cos(launch.theta)*cos(launch.phi),
cos(launch.theta)*sin(launch.phi),
sin(launch.theta)
);
double t = 0;
Vec3D prev_position(0, 0, 0);
do
{
prev_position = position;
Vec3D acceleration = this->calculate_friction(velocity) + this->calculate_nonfriction(position,velocity);
position = position + this->dtime * velocity + .5 * (this->dtime*this->dtime) * acceleration;
velocity = velocity + this->dtime * acceleration;
t += this->dtime;
}
while (position.z > target_elevation);
Target trg = Target(0.5 * (position.x + prev_position.x), 0.5 * (position.y + prev_position.y));
return Event(launch, trg, t - 0.5*dtime);
}