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

small bugfix for 2d models

This commit is contained in:
2022-04-11 22:22:56 -07:00
parent da5466d03a
commit 33ad462021
2 changed files with 29 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
name = "stlProcess"
uuid = "68914fc9-42cf-4b37-b06f-0b65edf9b8fa"
authors = ["Anson <anson@ansonbiggs.com>"]
version = "0.2.0"
version = "0.2.1"
[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

View File

@@ -117,27 +117,41 @@ function calc_characteristic_length(triangles, inertia, center_of_gravity, scale
sort_index = sortperm(θs)
min_points = points[sort_index[1:3]]
max_points = points[sort_index[(end - 2):end]]
min_point = 0
max_point = 0
# Create a parameterized function using the eigenvector and center_of_gravity
line_func(t) = center_of_gravity .+ eig .* t
# create a plane using 3 points, then find where the parameterized function intercepts it
max_normal = (max_points[1] - max_points[2]) × (max_points[2] - max_points[3])
max_t = find_zero(t -> let
l = line_func(t)
sum(max_normal .* (l .- max_points[1]))
end, norm(eig))
try
# create a plane using 3 points, then find where the parameterized function intercepts it
max_normal = (max_points[1] - max_points[2]) × (max_points[2] - max_points[3])
max_t = find_zero(t -> let
l = line_func(t)
sum(max_normal .* (l .- max_points[1]))
end, norm(eig))
max_point = line_func(max_t)
max_point = line_func(max_t)
# Build a plane in the opposite direction, and find the intercept again
min_normal = (min_points[1] - min_points[2]) × (min_points[2] - min_points[3])
min_t = find_zero(t -> let
l = line_func(t)
sum(min_normal .* (l .- min_points[1]))
end, -norm(eig))
# Build a plane in the opposite direction, and find the intercept again
min_normal = (min_points[1] - min_points[2]) × (min_points[2] - min_points[3])
min_t = find_zero(t -> let
l = line_func(t)
sum(min_normal .* (l .- min_points[1]))
end, -norm(eig))
min_point = line_func(min_t)
min_point = line_func(min_t)
catch e
if isa(e, Roots.ConvergenceFailed)
println("Characteristic Length Algorithm failed to converge, this usually means stl is flat.")
println("Setting length in dir to 0.")
else
println("Unknown error when calculating Characteristic Length.")
end
min_point = 0
max_point = 0
end
push!(characteristic_points, (min_point, max_point))
end