dS2D
Approximation of the infinitesimal element of a closed contour with control points.
Contents
Syntax
dSp = dS2D(p)
Description
dSp = dS2D(p) computes approximation of the infinitesimal element of a closed contour with control points. p is a real matrix of size Nb x 2. dSp is a vector of size Nb x 1.
- If all elements of dSp are almost the same dSp is a value.
- If input is only one point, it is set dSp = 1 (a closed contour does not make sense).
Note that p is a matrix of size Nb x 2 and not 2 x Nb. This is why in pntsGeometry is used:
dS = dS2D(transpose(Pnts));
Examples
Example 1
Point coordinates: (0,0), (1,0), (1,1)
p = [0 0; 1 0; 1 1]; dS2D(p)
Result:
1.2071 1.0000 1.2071
Example 2
Point coordinates: (0,0), (1,0), (1,1), (0,1) (a square)
p = [0 0; 1 0; 1 1; 0 1]; dS2D(p)
Result:
1
Result is a value and not a vector because if all elements of dSp are almost the same size, it is reduced to a single number.
Input Arguments
- p : coordinates of points (real matrix of size Nb x 2)
Output Arguments
- dSp : approximation of the infinitesimal element of a closed contour with control points. dSp is a vector of size Nb x 1. If all elements of dSp are almost the same dSp is a value. If input is only one point, it is set dSp = 1 (a closed contour does not make sense).
More About
Please note that dSp does not contain the distances between the points, because then it would depend on the orientation of the parametrization. To omit this problem we use an average value (similar to the central difference in comparison to the forward or backward difference). It is explained in the following.
First, but wrong idea
The first (but kind of wrong) idea to discretize a closed contour is to compute the distances between the points, e.g. for points
.
Then, the distances for the point coordinates ,
and
are 1,
and 1.
The problem is that the infinitesimal element then depends on the orientation of the parametrization. We consider the parametrization and the (equivalent) one
. Then the length of the infinitesimal element of
changes: In the first case it is
and in the second
.
Second, orientation independent idea
The second idea avoids the orientation's dependence using the forward and backward definition of the distances between the points, i.e. and
and compute the average, i.e.
This results in the infinitesimal elements are
,
and
.
The definition is chosen such that the point is in the center of the closed contour's element belonging to
. This is kind of a 'staggered definition' between
and
(similar to the central difference in comparison to the forward or backward difference).
See Also
Code
function dSp = dS2D(p) if numel(p) == 2 % i.e. ONE coordinate (a distance does not make sense) dSp = 1; elseif numel(p) > 2 pm1 = circshift(p, 1); % p minus 1 pp1 = circshift(p,-1); % p plus 1 n = @(x) sqrt(sum( x.^2 ,2)); dSp = ( n(p-pm1) + n(p-pp1) )/2; % if all elements of dSp almost the same size, % reduce dSp to a single number if var(dSp) < 10E-5*mean(dSp) dSp = mean(dSp); end else disp('Error in function dSp: size of input array too small') end end