1
0
mirror of https://gitlab.com/MisterBiggs/stl-process.git synced 2025-08-03 12:01:33 +00:00

small changes

This commit is contained in:
2022-03-22 08:24:15 -07:00
parent 9b3004e226
commit eae1e0bb1c
2 changed files with 71 additions and 49 deletions

15
.JuliaFormatter.toml Normal file
View File

@@ -0,0 +1,15 @@
style = "blue"
margin = 120
always_for_in = true
whitespace_ops_in_indices = true
remove_extra_newlines = true
import_to_using = true
pipe_to_function_call = false
short_to_long_function_def = false
always_use_return = false
format_docstrings = true
conditional_to_if = true
trailing_comma = true
join_lines_based_on_source = false
format_markdown = true

View File

@@ -1,17 +1,15 @@
using MeshIO using MeshIO
using FileIO using FileIO
using GeometryBasics
using LinearAlgebra using LinearAlgebra
stl = load(raw"C:\Users\albig\Downloads\cubeblender.stl") stl = load(raw"C:\Users\albig\Downloads\cubeblender.stl")
# stl = load(raw"C:\Coding\stl_read\3DBenchy.stl")
function get_mass_properties(triangles) function get_mass_properties(triangles)
x = [ [v[1] for v in tri] for tri in triangles] |> x -> reduce(hcat,x)' x = reduce(hcat, [[v[1] for v in tri] for tri in triangles])'
y = [ [v[2] for v in tri] for tri in triangles] |> x -> reduce(hcat,x)' y = reduce(hcat, [[v[2] for v in tri] for tri in triangles])'
z = [ [v[3] for v in tri] for tri in triangles] |> x -> reduce(hcat,x)' z = reduce(hcat, [[v[3] for v in tri] for tri in triangles])'
function subexpression(x) function subexpression(x)
w0, w1, w2 = x[:, 1], x[:, 2], x[:, 3] w0, w1, w2 = x[:, 1], x[:, 2], x[:, 3]
@@ -46,18 +44,27 @@ function get_mass_properties(triangles)
intg[9] = sum(d1 .* (z0 .* g0y + z1 .* g1y + z2 .* g2y)) intg[9] = sum(d1 .* (z0 .* g0y + z1 .* g1y + z2 .* g2y))
intg[10] = sum(d2 .* (x0 .* g0z + x1 .* g1z + x2 .* g2z)) intg[10] = sum(d2 .* (x0 .* g0z + x1 .* g1z + x2 .* g2z))
intg = intg ./ [6, 24, 24, 24, 60, 60, 60, 120, 120, 120] intg = intg ./ [6, 24, 24, 24, 60, 60, 60, 120, 120, 120]
volumee = intg[1]
cog = intg[2:4] / volumee volume = intg[1]
cogsq = cog .^ 2
center_of_gravity = intg[2:4] / volume
cogsq = center_of_gravity .^ 2
inertia = zeros((3, 3)) inertia = zeros((3, 3))
inertia[1, 1] = intg[6] + intg[7] - volumee .* (cogsq[2] + cogsq[3]) inertia[1, 1] = intg[6] + intg[7] - volume .* (cogsq[2] + cogsq[3])
inertia[2, 2] = intg[5] + intg[7] - volumee .* (cogsq[3] + cogsq[1]) inertia[2, 2] = intg[5] + intg[7] - volume .* (cogsq[3] + cogsq[1])
inertia[3, 3] = intg[5] + intg[6] - volumee .* (cogsq[1] + cogsq[2]) inertia[3, 3] = intg[5] + intg[6] - volume .* (cogsq[1] + cogsq[2])
inertia[1, 2] = inertia[2, 1] = -(intg[8] - volumee .* cog[1] .* cog[2]) inertia[1, 2] = inertia[2, 1] = -(intg[8] - volume .* center_of_gravity[1] .* center_of_gravity[2])
inertia[2, 3] = inertia[3, 2] = -(intg[9] - volumee .* cog[2] .* cog[3]) 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] - volumee .* cog[3] .* cog[1]) inertia[1, 3] = inertia[3, 1] = -(intg[10] - volume .* center_of_gravity[3] .* center_of_gravity[1])
return volume, cog, inertia
return volume, center_of_gravity, inertia
end end
volumee
v, cog, inertia = get_mass_properties(stl)
v
cog cog
inertia inertia
eigen(inertia)