```  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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
```
```pub mod physics;
pub mod vector;

use physics::{magnetic_acceleration, magnetic_force, north_pole_magnetic_field};
use vector::Vec3;

pub fn calc(
velocity: &mut Vec3,
position: &mut Vec3,
acceleration: &mut Vec3,
force: &mut Vec3,
mass: f32,
charge: f32,
intensity: f32,
time_ms: f32,
) {
*force = magnetic_force(
charge,
velocity,
&north_pole_magnetic_field(intensity, position.x, position.y, position.z),
);
*acceleration = magnetic_acceleration(force, mass);
//velocity = physics::velocity(&velocity, &acceleration, 0.1); //velocity + acceleration;
*velocity += *acceleration * ((time_ms / 1000.0) as f32);
*position += *velocity * ((time_ms / 1000.0) as f32); // You should somehow get time here
//? You probably shouldn't get time here right? You're like doing it in a instant of time, doesn't make much sense to get time in there
}

pub fn iterate(
count: u32,
velocity: &mut Vec3,
position: &mut Vec3,
acceleration: &mut Vec3,
force: &mut Vec3,
mass: f32,
charge: f32,
intensity: f32,
time_ms: f32,
_print: bool,
) {
//use std::io::Write;
//let mut file = std::fs::File::create("geogebra/geogebra.xml").unwrap();

for i in 0..count {
//? 0..=count
calc(
velocity,
position,
acceleration,
force,
mass,
charge,
intensity,
time_ms,
);
if _print {
println!(
"\n----- {}ms -----\nForce: {:?}\nAcceleration: {:?}\nNew Velocity: {:?}\nPosition: {:?}\nGeoGebra point: ({}, {}, {})",
i as f32 * time_ms, force, acceleration, velocity, position, position.x, position.y, position.z
);

//sleep_ms(MS);

//println!("26 % {} = {}", i, 26 % i);
/*
let mut label = String::new();
for _ in 0..=(i as usize / 26) {
label.push(ASCII_UPPER[i.rem_euclid(26)]);
}
*/

//file.write_all(format!("<expression label=\"{l}\" exp=\"({x}, {y}, {z})\" type=\"point\"/>\n<element type=\"point3d\" label=\"{l}\">\n\t<show object=\"true\" label=\"true\" ev=\"4\"/>\n\t<objColor r=\"77\" g=\"77\" b=\"255\" alpha=\"0\"/>\n\t<layer val=\"0\"/>\n\t<labelMode val=\"0\"/>\n\t<animation step=\"0.1\" speed=\"1\" type=\"1\" playing=\"false\"/>\n\t<coords x=\"{x}\" y=\"{y}\" z=\"{z}\" w=\"1\"/>\n\t<pointSize val=\"5\"/>\n</element>", l = label, x = position.x, y = position.y, z = position.z).as_bytes()).unwrap();
}
}
}

type Vectors = (Vec3, Vec3, Vec3, Vec3);

pub fn iterate_return(
count: u32,
velocity: &mut Vec3,
position: &mut Vec3,
acceleration: &mut Vec3,
force: &mut Vec3,
mass: f32,
charge: f32,
intensity: f32,
time_ms: f32,
_print: bool,
) -> Vec<Vectors> {
let mut vec: Vec<Vectors> = Vec::new();

for i in 0..count {
calc(
velocity,
position,
acceleration,
force,
mass,
charge,
intensity,
time_ms,
);
if _print {
println!(
"\n----- {}ms -----\nForce: {:?}\nAcceleration: {:?}\nNew Velocity: {:?}\nPosition: {:?}\nGeoGebra point: ({}, {}, {})",
i as f32 * time_ms, force, acceleration, velocity, position, position.x, position.y, position.z
);

//sleep_ms(MS);

//println!("26 % {} = {}", i, 26 % i);
/*
let mut label = String::new();
for _ in 0..=(i as usize / 26) {
label.push(ASCII_UPPER[i.rem_euclid(26)]);
}
*/

//file.write_all(format!("<expression label=\"{l}\" exp=\"({x}, {y}, {z})\" type=\"point\"/>\n<element type=\"point3d\" label=\"{l}\">\n\t<show object=\"true\" label=\"true\" ev=\"4\"/>\n\t<objColor r=\"77\" g=\"77\" b=\"255\" alpha=\"0\"/>\n\t<layer val=\"0\"/>\n\t<labelMode val=\"0\"/>\n\t<animation step=\"0.1\" speed=\"1\" type=\"1\" playing=\"false\"/>\n\t<coords x=\"{x}\" y=\"{y}\" z=\"{z}\" w=\"1\"/>\n\t<pointSize val=\"5\"/>\n</element>", l = label, x = position.x, y = position.y, z = position.z).as_bytes()).unwrap();
}
vec.push((
velocity.clone(),
position.clone(),
acceleration.clone(),
force.clone(),
));
}

vec
}

pub fn exec(
count: u32,
velocity: &mut Vec3,
position: &mut Vec3,
mass: f32,
charge: f32,
intensity: f32,
time_ms: f32,
_print: bool,
) -> (Vec3, Vec3) {
let mut force: Vec3 = Vec3::ZERO;
let mut acceleration: Vec3 = Vec3::ZERO;

iterate(
count,
velocity,
position,
&mut acceleration,
&mut force,
mass,
charge,
intensity,
time_ms,
_print,
);

(acceleration, force)
}

pub fn exec_return(
count: u32,
velocity: &mut Vec3,
position: &mut Vec3,
mass: f32,
charge: f32,
intensity: f32,
time_ms: f32,
_print: bool,
) -> (Vec3, Vec3, Vec<Vectors>) {
let mut force: Vec3 = Vec3::ZERO;
let mut acceleration: Vec3 = Vec3::ZERO;

(
acceleration,
force,
iterate_return(
count,
velocity,
position,
&mut acceleration,
&mut force,
mass,
charge,
intensity,
time_ms,
_print,
),
)
}
```