Home > matGeom > geom3d > clipEdge3d.m

clipEdge3d

PURPOSE ^

CLIPEDGE3D Clip a 3D edge with a cuboid box.

SYNOPSIS ^

function clipped = clipEdge3d(edge, box)

DESCRIPTION ^

CLIPEDGE3D Clip a 3D edge with a cuboid box.

   CLIPPED = clipEdge3d(EDGE, BOX)

   Example
   clipEdge3d

   See also
     lines3d, edges3d, clipLine3d

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function clipped = clipEdge3d(edge, box)
0002 %CLIPEDGE3D Clip a 3D edge with a cuboid box.
0003 %
0004 %   CLIPPED = clipEdge3d(EDGE, BOX)
0005 %
0006 %   Example
0007 %   clipEdge3d
0008 %
0009 %   See also
0010 %     lines3d, edges3d, clipLine3d
0011 
0012 % ------
0013 % Author: David Legland
0014 % E-mail: david.legland@inrae.fr
0015 % Created: 2018-04-12, using Matlab 9.3.0.713579 (R2017b)
0016 % Copyright 2018-2024 INRA - Cepia Software Platform
0017 
0018 % compute supporting line of edge
0019 line = [edge(:, 1:3) edge(:,4:6)-edge(:,1:3)];
0020 
0021 % clip supporting line
0022 clipped = clipLine3d(line, box);
0023 
0024 % for each clipped line, check that extremities are contained in edge
0025 nEdges = size(edge, 1);
0026 for i = 1:nEdges
0027     % if supporting line does not intersect the box, the edge is totally
0028     % clipped.
0029     if isnan(clipped(i,1))
0030         continue;
0031     end
0032     
0033     % position of intersection points on the current supporting line
0034     pos1 = linePosition3d(clipped(i,1:3), line(i,:));
0035     pos2 = linePosition3d(clipped(i,4:6), line(i,:));
0036     
0037     if pos1 > 1 || pos2 < 0
0038         % case of an edge totally clipped
0039         clipped(i,:) = NaN;
0040     elseif pos1 > 0 && pos2 < 1
0041         % case of an edge already contained within the bounding box
0042         % -> nothin to do...
0043         continue;
0044     else
0045         % otherwise, need to adjust bounds of the clipped edge
0046         pos1 = max(pos1, 0);
0047         pos2 = min(pos2, 1);
0048         p1 = line(i,1:3) + pos1 * line(i,4:6);
0049         p2 = line(i,1:3) + pos2 * line(i,4:6);
0050         clipped(i,:) = [p1 p2];
0051     end
0052 end

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022