mirror of
https://gitlab.com/MisterBiggs/stl-process.git
synced 2025-08-03 12:01:33 +00:00
added surface area calculation
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
# This file is machine-generated - editing it directly is not advised
|
||||
|
||||
julia_version = "1.7.2"
|
||||
julia_version = "1.8.0-beta3"
|
||||
manifest_format = "2.0"
|
||||
project_hash = "19dd795ccf3365426e09536ac7ad8bf96e8ee766"
|
||||
|
||||
[[deps.Adapt]]
|
||||
deps = ["LinearAlgebra"]
|
||||
@@ -11,6 +12,7 @@ version = "3.3.3"
|
||||
|
||||
[[deps.ArgTools]]
|
||||
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
|
||||
version = "1.1.1"
|
||||
|
||||
[[deps.Artifacts]]
|
||||
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
|
||||
@@ -32,6 +34,7 @@ version = "0.2.0"
|
||||
[[deps.CompilerSupportLibraries_jll]]
|
||||
deps = ["Artifacts", "Libdl"]
|
||||
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
|
||||
version = "0.5.2+0"
|
||||
|
||||
[[deps.ConstructionBase]]
|
||||
deps = ["LinearAlgebra"]
|
||||
@@ -54,8 +57,9 @@ deps = ["Printf"]
|
||||
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
||||
|
||||
[[deps.Downloads]]
|
||||
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
|
||||
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
|
||||
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
|
||||
version = "1.6.0"
|
||||
|
||||
[[deps.EarCut_jll]]
|
||||
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
|
||||
@@ -69,6 +73,9 @@ git-tree-sha1 = "80ced645013a5dbdc52cf70329399c35ce007fae"
|
||||
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
|
||||
version = "1.13.0"
|
||||
|
||||
[[deps.FileWatching]]
|
||||
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
|
||||
|
||||
[[deps.FixedPointNumbers]]
|
||||
deps = ["Statistics"]
|
||||
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
|
||||
@@ -108,10 +115,12 @@ version = "1.4.1"
|
||||
[[deps.LibCURL]]
|
||||
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
|
||||
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
|
||||
version = "0.6.3"
|
||||
|
||||
[[deps.LibCURL_jll]]
|
||||
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
|
||||
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
|
||||
version = "7.81.0+0"
|
||||
|
||||
[[deps.LibGit2]]
|
||||
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
|
||||
@@ -120,6 +129,7 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
|
||||
[[deps.LibSSH2_jll]]
|
||||
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
|
||||
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
|
||||
version = "1.10.2+0"
|
||||
|
||||
[[deps.Libdl]]
|
||||
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
|
||||
@@ -144,6 +154,7 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
|
||||
[[deps.MbedTLS_jll]]
|
||||
deps = ["Artifacts", "Libdl"]
|
||||
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
|
||||
version = "2.28.0+0"
|
||||
|
||||
[[deps.MeshIO]]
|
||||
deps = ["ColorTypes", "FileIO", "GeometryBasics", "Printf"]
|
||||
@@ -153,13 +164,16 @@ version = "0.4.10"
|
||||
|
||||
[[deps.MozillaCACerts_jll]]
|
||||
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
|
||||
version = "2022.2.1"
|
||||
|
||||
[[deps.NetworkOptions]]
|
||||
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
|
||||
version = "1.2.0"
|
||||
|
||||
[[deps.OpenBLAS_jll]]
|
||||
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
|
||||
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
|
||||
version = "0.3.20+0"
|
||||
|
||||
[[deps.OrderedCollections]]
|
||||
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
|
||||
@@ -169,6 +183,7 @@ version = "1.4.1"
|
||||
[[deps.Pkg]]
|
||||
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
|
||||
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
|
||||
version = "1.8.0"
|
||||
|
||||
[[deps.Preferences]]
|
||||
deps = ["TOML"]
|
||||
@@ -196,12 +211,13 @@ version = "1.3.0"
|
||||
|
||||
[[deps.Roots]]
|
||||
deps = ["CommonSolve", "Printf", "Setfield"]
|
||||
git-tree-sha1 = "6085b8ac184add45b586ed8d74468310948dcfe8"
|
||||
git-tree-sha1 = "e382260f6482c27b5062eba923e36fde2f5ab0b9"
|
||||
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
version = "1.4.0"
|
||||
version = "2.0.0"
|
||||
|
||||
[[deps.SHA]]
|
||||
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
|
||||
version = "0.7.0"
|
||||
|
||||
[[deps.Serialization]]
|
||||
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
|
||||
@@ -238,6 +254,7 @@ version = "0.6.5"
|
||||
[[deps.TOML]]
|
||||
deps = ["Dates"]
|
||||
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
|
||||
version = "1.0.0"
|
||||
|
||||
[[deps.TableTraits]]
|
||||
deps = ["IteratorInterfaceExtensions"]
|
||||
@@ -254,6 +271,7 @@ version = "1.7.0"
|
||||
[[deps.Tar]]
|
||||
deps = ["ArgTools", "SHA"]
|
||||
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
|
||||
version = "1.10.0"
|
||||
|
||||
[[deps.Test]]
|
||||
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
|
||||
@@ -269,15 +287,19 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
|
||||
[[deps.Zlib_jll]]
|
||||
deps = ["Libdl"]
|
||||
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
|
||||
version = "1.2.12+1"
|
||||
|
||||
[[deps.libblastrampoline_jll]]
|
||||
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
|
||||
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
|
||||
version = "5.1.0+0"
|
||||
|
||||
[[deps.nghttp2_jll]]
|
||||
deps = ["Artifacts", "Libdl"]
|
||||
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
|
||||
version = "1.41.0+1"
|
||||
|
||||
[[deps.p7zip_jll]]
|
||||
deps = ["Artifacts", "Libdl"]
|
||||
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
|
||||
version = "16.2.1+1"
|
||||
|
@@ -5,5 +5,6 @@ version = "0.1.0"
|
||||
|
||||
[deps]
|
||||
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
MeshIO = "7269a6da-0436-5bbc-96c2-40638cbb6118"
|
||||
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
|
||||
|
@@ -3,17 +3,19 @@ module stlProcess
|
||||
using MeshIO
|
||||
using FileIO
|
||||
using Roots
|
||||
using LinearAlgebra
|
||||
|
||||
struct Properties
|
||||
volume::Float64
|
||||
center_of_gravity::Vector{Float64}
|
||||
inertia::Matrix{Float64}
|
||||
surface_area::Float64
|
||||
|
||||
function Properties(volume, center_of_gravity, inertia)
|
||||
function Properties(volume, center_of_gravity, inertia,surface_area)
|
||||
@assert size(center_of_gravity) == (3,)
|
||||
@assert size(inertia) == (3, 3)
|
||||
|
||||
return new(volume, center_of_gravity, inertia)
|
||||
return new(volume, center_of_gravity, inertia, surface_area)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,7 +76,9 @@ function get_mass_properties(triangles; scale=1)
|
||||
inertia[2, 3] = inertia[3, 2] = -(intg[9] - volume .* center_of_gravity[2] .* center_of_gravity[3])
|
||||
inertia[1, 3] = inertia[3, 1] = -(intg[10] - volume .* center_of_gravity[3] .* center_of_gravity[1])
|
||||
|
||||
return Properties(volume, center_of_gravity, inertia ./ volume)
|
||||
surface_area = norm.(eachrow([x0 y0 z0] - [x1 y1 z1]) .× eachrow([x1 y1 z1] - [x2 y2 z2])) / 2 |> sum
|
||||
|
||||
return Properties(volume, center_of_gravity, inertia ./ volume, surface_area)
|
||||
end
|
||||
|
||||
function fast_volume(triangles; scale=1)
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user