-
Notifications
You must be signed in to change notification settings - Fork 0
/
orbital_example.rb
74 lines (57 loc) · 1.43 KB
/
orbital_example.rb
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
$: << 'lib'
require 'orbital_example'
SIM_NUM = ARGV[0] ? ARGV[0].to_i : 10000
N = ARGV[1] ? ARGV[1].to_i : 15
objects = {}
N.times do |i|
objects[i] = Astrodynamics::AstronomicalObject.new i
end
p = ProgressBar.new "Simulation", SIM_NUM
t_vector = []
name_vector = []
x_vector = []
y_vector = []
z_vector = []
SIM_NUM.times do | i |
p.set(i)
objects.each { | key, object | object.calc_tick(objects.except key) }
objects.each { | key, object | object.apply_tick }
objects.each do | key, object |
t_vector << i
name_vector << object.to_s
x_vector << object.get_position[0]
y_vector << object.get_position[1]
z_vector << object.get_position[2]
end
end
R.echo false, false
R.t = t_vector
R.name = name_vector
R.x = x_vector
R.y = y_vector
R.z = z_vector
R.eval <<-EOF
library(scatterplot3d)
library(animation)
x <- data.frame(t <- t, name <- name, x <- x, y <- x, z <- z)
colnames(x) <- c("t","name","x","y","z")
UNIQUE <- length(unique(x$name))
N <- nrow(x)/UNIQUE
x <- x[1:(N*UNIQUE), ]
xl = c(min(x$x)-1, max(x$x)+1)
yl = c(min(x$y)-1, max(x$y)+1)
zl = c(min(x$z)-1, max(x$z)+1)
every = 100
t_list = unique(x$t)
t_list = t_list[t_list %% every == 0]
ani.start()
for(i in t_list)
{
this <- x[x$t == i, ]
scatterplot3d(this$x, this$y, this$z, xlab="x", ylab="y", zlab="z", xlim=xl, ylim=yl, zlim=zl)
}
ani.stop()
EOF
puts ''
puts 'Press enter to continue.'
STDIN.gets.chomp