Skip to content
Snippets Groups Projects
Commit fa50ebb8 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Polyhedron: fixed possible issue with incomplete sets of plane normals

parent cb8a63db
No related branches found
No related tags found
No related merge requests found
......@@ -19,8 +19,9 @@ function verts = gtMathsGetPolyhedronVerticesFromPlaneNormals(pl_normals)
for ii = 1:num_pls
[ps, ds_vers] = get_intersecting_lines(ii, pl_normals, pl_normals_vers, pl_normals_norm);
verts = [verts; ...
get_intersection_points(ps, ds_vers, pl_normals_vers, pl_normals_norm)]; %#ok<AGROW>
[new_verts, valid] = ...
get_intersection_points(ps, ds_vers, pl_normals_vers, pl_normals_norm);
verts = [verts; new_verts(valid, :)]; %#ok<AGROW>
end
validation_norms = pl_normals_norm + eps('single');
......@@ -73,7 +74,7 @@ function [ps, ds_vers] = get_intersecting_lines(pl_ii, pl_normals, pl_normals_ve
end
end
function points = get_intersection_points(ps, ds_vers, pl_normals_vers, pl_normals_norm)
function [points, valid] = get_intersection_points(ps, ds_vers, pl_normals_vers, pl_normals_norm)
num_ps = size(ps, 1);
% this is based on the fact that the intersection with the different planes
......@@ -83,6 +84,7 @@ function points = get_intersection_points(ps, ds_vers, pl_normals_vers, pl_norma
% If they are not valid, we will take care of it later.
points = zeros(2 * num_ps, 3);
valid = false(2 * num_ps, 1);
dot_prods_ds_pls = (ds_vers * pl_normals_vers')';
not_perpendiculars = abs(dot_prods_ds_pls) > eps('single');
......@@ -103,8 +105,13 @@ function points = get_intersection_points(ps, ds_vers, pl_normals_vers, pl_norma
min_norm = min(ds_norm(dot_prods_d_pls > 0));
max_norm = max(ds_norm(dot_prods_d_pls < 0));
points(2*(line_ii-1)+1, :) = p + d_vers * min_norm;
points(2*line_ii, :) = p + d_vers * max_norm;
if (~isempty(min_norm))
points(2*(line_ii-1)+1, :) = p + d_vers * min_norm;
end
if (~isempty(max_norm))
points(2*line_ii, :) = p + d_vers * max_norm;
end
valid(2*line_ii+(-1:0)) = ~[isempty(min_norm); isempty(max_norm)];
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment