Skip to content

Commit 077035f

Browse files
committed
Test: Rigid bodies
1 parent db7f888 commit 077035f

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[deps]
2+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
23
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
34
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/rigid-bodies.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using DeformableBodies
2+
using Test
3+
using Random
4+
import LinearAlgebra: norm
5+
6+
# Uniform Distribution on Sphere
7+
function unif_sphere(m)
8+
v = randn(m)
9+
return v / norm(v)
10+
end
11+
12+
approx_zero_array(A) = all(isapprox.(A, 0.0, atol=1e-6))
13+
14+
@testset "Rigid Bodies" for i in 1:5
15+
@testset "Zero angular momentum" begin
16+
npts = rand(10:100)
17+
# A rigid body contained on a ball
18+
r_0 = [PointMass(rand()*10, unif_sphere(3)) for i in 1:npts]
19+
bigV_r0 = vcat(pos.(r_0)...)
20+
model = Model( t -> r_0 # Constant trajectories
21+
, (0., 1.)
22+
, quaternion(1)
23+
, [0.,0.,0.]
24+
)
25+
rotbodies, R, Π = solve!(model)
26+
27+
for t in range(0., 1., length=30)
28+
bigV_rt = vcat(pos.(model.inertialframe(t))...)
29+
@test R(t) 1 atol=1e-7
30+
@test approx_zero_array(Π(t))
31+
@test isapprox(bigV_r0, bigV_rt, atol=1e-6)
32+
end
33+
end
34+
end
35+

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ Random.seed!(12342352154)
1111
@testset "DeformableBodies Package" begin
1212
@info "Testing Quaternions"
1313
include(filepath("quaternions.jl"))
14+
@info "Testing dynamics for Rigid Bodies"
15+
include(filepath("rigid-bodies.jl"))
1416
end

0 commit comments

Comments
 (0)