From 3d52c55f09903ed8c468b5402b1311b0d6fd2165 Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 9 Apr 2022 12:04:07 -0700 Subject: [PATCH] add comments --- src/stlProcess.jl | 5 +++-- test/runtests.jl | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/stlProcess.jl b/src/stlProcess.jl index 489710f..98bdf01 100644 --- a/src/stlProcess.jl +++ b/src/stlProcess.jl @@ -11,7 +11,7 @@ struct Properties inertia::Matrix{Float64} surface_area::Float64 - function Properties(volume, center_of_gravity, inertia,surface_area) + function Properties(volume, center_of_gravity, inertia, surface_area) @assert size(center_of_gravity) == (3,) @assert size(inertia) == (3, 3) @@ -76,7 +76,8 @@ 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]) - surface_area = norm.(eachrow([x0 y0 z0] - [x1 y1 z1]) .× eachrow([x1 y1 z1] - [x2 y2 z2])) / 2 |> sum + # https://math.stackexchange.com/questions/128991/how-to-calculate-the-area-of-a-3d-triangle + surface_area = sum(norm.(eachrow([x0 y0 z0] - [x1 y1 z1]) .× eachrow([x1 y1 z1] - [x2 y2 z2])) / 2) return Properties(volume, center_of_gravity, inertia ./ volume, surface_area) end diff --git a/test/runtests.jl b/test/runtests.jl index 9f9227e..d5ca289 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,7 +52,7 @@ 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) + # Properties(volume, center_of_gravity, inertia, surface_area) "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" =>