diff --git a/Project.toml b/Project.toml index 3913d8b..eee994f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "stlProcess" uuid = "68914fc9-42cf-4b37-b06f-0b65edf9b8fa" authors = ["Anson "] -version = "0.2.0" +version = "0.2.1" [deps] FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" diff --git a/src/stlProcess.jl b/src/stlProcess.jl index 7d39bb5..bfd3798 100644 --- a/src/stlProcess.jl +++ b/src/stlProcess.jl @@ -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