Home > matGeom > geom2d > edgePosition.m

edgePosition

PURPOSE ^

EDGEPOSITION Return position of a point on an edge.

SYNOPSIS ^

function pos = edgePosition(point, edge)

DESCRIPTION ^

EDGEPOSITION Return position of a point on an edge.

   POS = edgePosition(POINT, EDGE);
   Computes position of point POINT on the edge EDGE, relative to the
   position of edge vertices.
   EDGE has the form [x1 y1 x2 y2],
   POINT has the form [x y], and is assumed to belong to edge.
   The result POS has the following meaning:
     POS < 0:      POINT is located before the first vertex
     POS = 0:      POINT is located on the first vertex
     0 < POS < 1:  POINT is located between the 2 vertices (on the edge)
     POS = 1:      POINT is located on the second vertex
     POS < 0:      POINT is located after the second vertex

   POS = edgePosition(POINT, EDGES);
   If EDGES is an array of NL edges, return NE positions, corresponding to
   each edge.

   POS = edgePosition(POINTS, EDGE);
   If POINTS is an array of NP points, return NP positions, corresponding
   to each point.

   POS = edgePosition(POINTS, EDGES);
   If POINTS is an array of NP points and EDGES is an array of NE edges,
   return an array of [NP NE] position, corresponding to each couple
   point-edge.

   See also:
   edges2d, createEdge, isPointOnEdge

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pos = edgePosition(point, edge)
0002 %EDGEPOSITION Return position of a point on an edge.
0003 %
0004 %   POS = edgePosition(POINT, EDGE);
0005 %   Computes position of point POINT on the edge EDGE, relative to the
0006 %   position of edge vertices.
0007 %   EDGE has the form [x1 y1 x2 y2],
0008 %   POINT has the form [x y], and is assumed to belong to edge.
0009 %   The result POS has the following meaning:
0010 %     POS < 0:      POINT is located before the first vertex
0011 %     POS = 0:      POINT is located on the first vertex
0012 %     0 < POS < 1:  POINT is located between the 2 vertices (on the edge)
0013 %     POS = 1:      POINT is located on the second vertex
0014 %     POS < 0:      POINT is located after the second vertex
0015 %
0016 %   POS = edgePosition(POINT, EDGES);
0017 %   If EDGES is an array of NL edges, return NE positions, corresponding to
0018 %   each edge.
0019 %
0020 %   POS = edgePosition(POINTS, EDGE);
0021 %   If POINTS is an array of NP points, return NP positions, corresponding
0022 %   to each point.
0023 %
0024 %   POS = edgePosition(POINTS, EDGES);
0025 %   If POINTS is an array of NP points and EDGES is an array of NE edges,
0026 %   return an array of [NP NE] position, corresponding to each couple
0027 %   point-edge.
0028 %
0029 %   See also:
0030 %   edges2d, createEdge, isPointOnEdge
0031 %
0032 
0033 % ------
0034 % Author: David Legland
0035 % e-mail: david.legland@nantes.inra.fr
0036 % Created: 2004-05-25
0037 % Copyright 2009 INRA - Cepia Software Platform.
0038 %
0039 
0040 %   HISTORY:
0041 %   06/12/2009 created from linePosition
0042 
0043 % number of points and of edges
0044 nEdges = size(edge, 1);
0045 nPoints = size(point, 1);
0046 
0047 if nPoints == nEdges
0048     dxe = (edge(:, 3) - edge(:,1))';
0049     dye = (edge(:, 4) - edge(:,2))';
0050     dxp = point(:, 1) - edge(:, 1);
0051     dyp = point(:, 2) - edge(:, 2);
0052 
0053 else
0054     % expand one of the arrays to have the same size
0055     dxe = (edge(:,3) - edge(:,1))';
0056     dye = (edge(:,4) - edge(:,2))';
0057     dxp = bsxfun(@minus, point(:,1), edge(:,1)');
0058     dyp = bsxfun(@minus, point(:,2), edge(:,2)');
0059 
0060 end
0061 
0062 pos = (dxp .* dxe + dyp .* dye) ./ (dxe .* dxe + dye .* dye);

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