Home > matGeom > geom3d > intersectEdgePolygon3d.m

intersectEdgePolygon3d

PURPOSE ^

Intersection point of a 3D EDGE segment and a 3D polygon.

SYNOPSIS ^

function [inter, valid] = intersectEdgePolygon3d(edge, poly)

DESCRIPTION ^

 Intersection point of a 3D EDGE segment and a 3D polygon.

   INTER = intersectEdgePolygon3d(EDGE, POLY)
   Compute coordinates of intersection point between the 3D edge EDGE and
   the 3D polygon POLY. EDGE is a 1-by-6 row vector containing source and
   target positions of the edge, POLY is a Nv-by-3 array containing
   coordinates of 3D polygon vertices.
   INTER is a 1-by-3 row vector containing coordinates of intersection
   point, or [NaN NaN NaN] if edge and polygon do not intersect.

   INTERS = intersectEdgePolygon3d(EDGES, POLY)
   If EDGES is a N-by-6 array representing several edges, the result
   INTERS is a N-by-3 array containing coordinates of intersection of each
   edge with the polygon.

   [INTER, INSIDE] = intersectEdgePolygon3d(EDGE, POLY)
   Also return a N-by-1 boolean array containing TRUE if the corresponding
   edge contains the intersection point.

   Example
     % Compute intersection between a 3D edge and a 3D triangle
     pts3d = [3 0 0; 0 6 0;0 0 9];
     edge1 = [0 0 0 3 6 9];
     inter = intersectEdgePolygon3d(edge1, pts3d)
     inter =
           1   2   3

     % keep only valid intersections with several edges
     pts3d = [3 0 0; 0 6 0;0 0 9];
     edges = [0 0 0 3 6 9;10 0 0 10 2 3];
     [inter, inside] = intersectEdgePolygon3d(edges, pts3d);
     inter(inside, :)
     ans = 
           1   2   3

   See Also
   intersectLinePolygon, intersectRayPolygon3d, intersectLinePlane

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [inter, valid] = intersectEdgePolygon3d(edge, poly)
0002 % Intersection point of a 3D EDGE segment and a 3D polygon.
0003 %
0004 %   INTER = intersectEdgePolygon3d(EDGE, POLY)
0005 %   Compute coordinates of intersection point between the 3D edge EDGE and
0006 %   the 3D polygon POLY. EDGE is a 1-by-6 row vector containing source and
0007 %   target positions of the edge, POLY is a Nv-by-3 array containing
0008 %   coordinates of 3D polygon vertices.
0009 %   INTER is a 1-by-3 row vector containing coordinates of intersection
0010 %   point, or [NaN NaN NaN] if edge and polygon do not intersect.
0011 %
0012 %   INTERS = intersectEdgePolygon3d(EDGES, POLY)
0013 %   If EDGES is a N-by-6 array representing several edges, the result
0014 %   INTERS is a N-by-3 array containing coordinates of intersection of each
0015 %   edge with the polygon.
0016 %
0017 %   [INTER, INSIDE] = intersectEdgePolygon3d(EDGE, POLY)
0018 %   Also return a N-by-1 boolean array containing TRUE if the corresponding
0019 %   edge contains the intersection point.
0020 %
0021 %   Example
0022 %     % Compute intersection between a 3D edge and a 3D triangle
0023 %     pts3d = [3 0 0; 0 6 0;0 0 9];
0024 %     edge1 = [0 0 0 3 6 9];
0025 %     inter = intersectEdgePolygon3d(edge1, pts3d)
0026 %     inter =
0027 %           1   2   3
0028 %
0029 %     % keep only valid intersections with several edges
0030 %     pts3d = [3 0 0; 0 6 0;0 0 9];
0031 %     edges = [0 0 0 3 6 9;10 0 0 10 2 3];
0032 %     [inter, inside] = intersectEdgePolygon3d(edges, pts3d);
0033 %     inter(inside, :)
0034 %     ans =
0035 %           1   2   3
0036 %
0037 %   See Also
0038 %   intersectLinePolygon, intersectRayPolygon3d, intersectLinePlane
0039 %
0040 
0041 % ------
0042 % Author: David Legland
0043 % e-mail: david.legland@inrae.fr
0044 % Created: 2011-05-22,    using Matlab 7.9.0.529 (R2009b)
0045 % Copyright 2011 INRA - Cepia Software Platform.
0046 
0047 % supporting plane of polygon vertices
0048 plane = createPlane(poly(1:3, :));
0049 
0050 % intersection of edge supporting line with the plane
0051 line = edgeToLine3d(edge);
0052 inter = intersectLinePlane(line, plane);
0053 
0054 onEdge = isPointOnEdge3d(inter, edge);
0055 
0056 % project all points on reference plane
0057 pts2d = planePosition(poly, plane);
0058 pInt2d = planePosition(inter, plane);
0059 
0060 % need to check polygon orientation
0061 insidePoly = xor(isPointInPolygon(pInt2d, pts2d), polygonArea(pts2d) < 0);
0062 
0063 % intersection points either outside the polygon on outside the edge bounds
0064 % are set to NaN
0065 valid = insidePoly & onEdge;
0066 inter(~valid, :) = NaN;

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019