1
0
mirror of https://gitlab.com/MisterBiggs/stl-process.git synced 2025-08-03 20:11:31 +00:00

added surface area calculation

This commit is contained in:
2022-04-09 11:51:34 -07:00
parent ae5ffe6545
commit 7facc6c0aa
4 changed files with 44 additions and 14 deletions

View File

@@ -53,24 +53,27 @@ end
models = Dict(
# Inertia math: https://en.wikipedia.org/wiki/List_of_moments_of_inertia#List_of_3D_inertia_tensors
# Properties(volume, center_of_gravity, inertia)
"cube.stl" => Properties(2.0^3, center, I_mat .* 2^2 / 6), # l = 2
"sphere.stl" => Properties(4 / 3 * pi, center, I_mat .* 2 / 5), # r = 1
"2_4_8_cuboid.stl" => Properties(2 * 4 * 8, center, diagm([2^2 + 4^2, 8^2 + 2^2, 8^2 + 4^2]) ./ 12), # h, d, w = 2, 4, 8
"slender_y.stl" => Properties(10 * π * 0.1^2, center, diagm([1, 0, 1]) .* (10^2 / 12)), # l_z = 10, r = 0.1
"cylinder.stl" => Properties(10 * π * 1^2, center, diagm([(3 + 10^2) / 12, (3 + 10^2) / 12, 1^2 / 2])), # l_z = 10, r = 1
"cube.stl" => Properties(2.0^3, center, I_mat .* 2^2 / 6, 6 * 2^2), # l = 2
"sphere.stl" => Properties(4 / 3 * pi, center, I_mat .* 2 / 5, 4π), # r = 1
"2_4_8_cuboid.stl" =>
Properties(2 * 4 * 8, center, diagm([2^2 + 4^2, 8^2 + 2^2, 8^2 + 4^2]) ./ 12, 2(2 * 4 + 2 * 8 + 4 * 8)), # h, d, w = 2, 4, 8
"slender_y.stl" => Properties(10 * π * 0.1^2, center, diagm([1, 0, 1]) .* (10^2 / 12), 2π * 0.05 * (0.1 + 10)), # l_z = 10, r = 0.1
"cylinder.stl" =>
Properties(10 * π * 1^2, center, diagm([(3 + 10^2) / 12, (3 + 10^2) / 12, 1^2 / 2]), 2π * 1 * (1 + 10)), # l_z = 10, r = 1
)
@testset "$model" for (model, control) in models
path = "test_assets/$model"
stl = load(path)
@testset "get_mass_properties" begin
@testset "get_mass_properties for $model" begin
props = get_mass_properties(stl)
@test props.volume control.volume atol = 0.5
@test props.center_of_gravity control.center_of_gravity atol = 0.01
@test eigvals(props.inertia) eigvals(control.inertia) atol = 0.1
@test props.surface_area control.surface_area atol = 0.5
end
@testset "Compare volumes with scaling" begin
@testset "Compare volumes with scaling for $model" begin
for scale in 1:5
props = get_mass_properties(stl; scale=scale)
volume = _check_volume(stl; scale=scale)