Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
26
Добавлен:
09.02.2015
Размер:
290.82 Кб
Скачать

Geometric analysis

<delaunay> - Delaunay triangulation.

DELAUNAY Delaunay triangulation of a set of points in 2D/3D space

DELAUNAY is used to create a Delaunay triangulation of a set of points

In 2d/3d space. A 2d Delaunay triangulation ensures that the circumcircle

associated with each triangle contains no other point in its interior.

This definition extends naturally to higher dimensions.

TRI = DELAUNAY(X,Y) creates a 2D Delaunay triangulation of the points

(X,Y), where X and Y are column-vectors. TRI is a matrix representing

the set of triangles that make up the triangulation. The matrix is of

size mtri-by-3, where mtri is the number of triangles. Each row of TRI

specifies a triangle defined by indices with respect to the points.

TRI = DELAUNAY(X,Y,Z) creates a 3D Delaunay triangulation of the points

(X,Y,Z), where X, Y, and Z are column-vectors. TRI is a matrix

representing the set of tetrahedra that make up the triangulation. The

matrix is of size mtri-by-4, where mtri is the number of tetrahedra.

Each row of TRI specifies a tetrahedron defined by indices with respect

to the points.

TRI = DELAUNAY(X) creates a 2D/3D Delaunay triangulation from the

point coordinates X. This variant supports the definition of points in

matrix format. X is of size mpts-by-ndim, where mpts is the number of

points and ndim is the dimension of the space where the points reside,

2 <= ndim <= 3. The output triangulation is equivalent to that of the

dedicated functions supporting the 2-input or 3-input calling syntax.

The DELAUNAY function produces an isolated triangulation; this is

useful for applications like plotting surfaces via the TRISURF function.

If you wish to query the triangulation; for example, to perform nearest

neighbor, point location, or topology queries, then DelaunayTri should

be used instead.

Example 1:

x = [-0.5 -0.5 0.5 0.5]';

y = [-0.5 0.5 0.5 -0.5]';

tri = delaunay(x,y);

triplot(tri,x,y);

% Highlight the first triangle in red

tri1 = tri(1, [1:end 1]);

hold on

plot(x(tri1), y(tri1), 'r')

Example 2:

X = rand(15,3);

tri = delaunay(X);

tetramesh(tri,X);

See also DelaunayTri, voronoi, trimesh, trisurf, triplot, convhull,

delaunayn, TriScatteredInterp.

Reference page in Help browser

doc delaunay

<delaunay3> - 3-D Delaunay tessellation.

DELAUNAY3 3-D Delaunay triangulation.

DELAUNAY3 will be removed in a future release. Use DelaunayTri instead.

T = DELAUNAY3(X,Y,Z) returns a set of tetrahedra such that no data

points of X are contained in any circumspheres of the tetrahedra. T is

a numt-by-4 array. The entries in each row of T are indices of the

points in (X,Y,Z) forming a tetrahedron in the triangulation of (X,Y,Z).

T = DELAUNAY3(X,Y,Z,OPTIONS) specifies a cell array of strings OPTIONS

that were previously used by Qhull. Qhull-specific OPTIONS are no longer

required and are currently ignored.

Example:

X = [-0.5 -0.5 -0.5 -0.5 0.5 0.5 0.5 0.5];

Y = [-0.5 -0.5 0.5 0.5 -0.5 -0.5 0.5 0.5];

Z = [-0.5 0.5 -0.5 0.5 -0.5 0.5 -0.5 0.5];

T = delaunay3( X, Y, Z )

See also DelaunayTri, TriScatteredInterp, delaunay, delaunayn, griddatan,

voronoin, tetramesh.

Reference page in Help browser

doc delaunay3

<delaunayn> - N-D Delaunay tessellation.

DELAUNAYN N-D Delaunay tessellation.

T = DELAUNAYN(X) returns a set of simplices such that no data points of

X are contained in any circumspheres of the simplices. The set of

simplices forms the Delaunay tessellation. X is an m-by-n array

representing m points in n-D space. T is a numt-by-(n+1) array where

each row is the indices into X of the vertices of the corresponding

simplex.

DELAUNAYN uses Qhull.

T = DELAUNAYN(X,OPTIONS) specifies a cell array of strings OPTIONS to

be used as options in Qhull. The default options are:

{'Qt','Qbb','Qc'} for 2D and 3D input,

{'Qt','Qbb','Qc','Qx'} for 4D and higher.

If OPTIONS is [], the default options will be used.

If OPTIONS is {''}, no options will be used, not even the default.

For more information on Qhull options, see http://www.qhull.org.

Example:

X = [ -0.5 -0.5 -0.5;

-0.5 -0.5 0.5;

-0.5 0.5 -0.5;

-0.5 0.5 0.5;

0.5 -0.5 -0.5;

0.5 -0.5 0.5;

0.5 0.5 -0.5;

0.5 0.5 0.5];

T = delaunayn(X);

errors, but hints that adding 'Qz' to the default options might help.

T = delaunayn(X,{'Qt','Qbb','Qc','Qz'});

To visualize this answer you can use the TETRAMESH function:

tetramesh(T,X)

See also DelaunayTri, qhull, voronoin, convhulln, delaunay, tetramesh.

Reference page in Help browser

doc delaunayn

<dsearch> - Search Delaunay triangulation for nearest point.

DSEARCH Search Delaunay triangulation for nearest point.

DSEARCH will be removed in a future release.

Use DelaunayTri/nearestNeighbor instead.

K = DSEARCH(X,Y,TRI,XI,YI) returns the index of the nearest (x,y)

point to the point (xi,yi). Requires a triangulation TRI of

the points X,Y obtained from DELAUNAY.

K = DSEARCH(X,Y,TRI,XI,YI,S) uses the sparse matrix S instead of

computing it each time:

S = sparse(tri(:,[1 1 2 2 3 3]),tri(:,[2 3 1 3 1 2]),1,nxy,nxy)

where nxy = prod(size(x)).

See also DelaunayTri, delaunay, voronoi.

Reference page in Help browser

doc dsearch

<dsearchn> - Search N-D Delaunay tessellation for nearest point.

DSEARCHN N-D nearest point search.

K = DSEARCHN(X,T,XI) returns the indices K of the closest points in X for

each point in XI. X is an m-by-n matrix representing m points in n-D

space. XI is a p-by-n matrix, representing p points in n-D space. T is a

numt-by-n+1 matrix, a tessellation of the data X generated by DELAUNAYN.

The output K is a column vector of length p.

K = DSEARCHN(X,T,XI,OUTVAL) returns the indices K of the closest points

in X for each point in XI, unless a point is outside the convex hull.

If XI(J,:) is outside the convex hull, then K(J) is assigned OUTVAL,

a scalar double. Inf is often used for OUTVAL. If OUTVAL is [],

then K is the same as in the case K = DSEARCHN(X,T,XI).

K = DSEARCHN(X,T,XI,OUTVAL,COPTIONS) specifies COPTIONS, a cell array of

strings to be used as options in Qhull via CONVHULLN.

If COPTIONS is [], the default CONVHULLN options will be used.

If COPTIONS is {''}, no options will be used, not even the default.

K = DSEARCHN(X,T,XI,OUTVAL,COPTIONS,DOPTIONS) specifies DOPTIONS, a

cell array of strings to be used as options in Qhull via DELAUNAYN.

If DOPTIONS is [], the default DELAUNAYN options will be used.

If DOPTIONS is {''}, no options will be used, not even the default.

K = DSEARCHN(X,XI) performs the search without using a tessellation.

With large X and small XI, this approach is faster and uses much

less memory.

[K,D] = DSEARCHN(X,...) also returns the distances D to the closest

points. D is a column vector of length p.

See also DelaunayTri, tsearchn, qhull, griddatan, delaunayn,

convhulln.

Reference page in Help browser

doc dsearchn

<tsearch> - Closest triangle search.

TSEARCH Search for enclosing Delaunay triangle

TSEARCH will be removed in a future release.

Use DelaunayTri/pointLocation instead.

T = TSEARCH(X,Y,TRI,XI,YI) returns the index of the enclosing Delaunay

triangle for each point in XI,YI so that the enclosing triangle for

point (XI(k),YI(k)) is TRI(T(k),:). TSEARCH returns NaN for all

points outside the convex hull. Requires a triangulation TRI of the

points X,Y obtained from DELAUNAY.

See also DelaunayTri, delaunay, tsearchn, delaunayn.

Reference page in Help browser

doc tsearch

<tsearchn> - N-D closest triangle search.

TSEARCHN N-D closest simplex search.

T = TSEARCHN(X,TES,XI) returns the indices T of the enclosing simplex

of the Delaunay tessellation TES for each point in XI. X is

an m-by-n matrix, representing m points in n-D space. XI is

a p-by-n matrix, representing p points in n-D space. TSEARCHN returns

NaN for all points outside the convex hull of X. TSEARCHN requires a

tessellation TES of the points X obtained from DELAUNAYN.

[T,P] = TSEARCHN(X,TES,XI) also returns the barycentric coordinate P

of XI in the simplex TES. P is an p-by-n+1 matrix. Each row of P is the

barycentric coordinate of the corresponding point in XI. It is useful

for interpolation.

See also DelaunayTri, dsearchn, qhull, griddatan, delaunayn.

Reference page in Help browser

doc tsearchn

<convhull> - Convex hull.

CONVHULL Convex hull of a set of points in 2D/3D space

CONVHULL returns the convex hull of a set of points in 2D/3D space.

K = CONVHULL(X,Y) returns the 2D convex hull of the points (X,Y), where

X and Y are column-vectors. The convex hull K is expressed in terms of

a vector of point indices arranged in a counter-clockwise cycle around

the hull.

K = CONVHULL(X,Y,Z) returns the 3D convex hull of the points (X,Y,Z),

where X, Y, and Z are column-vectors. K is a triangulation representing

the boundary of the convex hull. K is of size mtri-by-3, where mtri is

the number of triangular facets. That is, each row of K is a triangle

defined in terms of the point indices.

K = CONVHULL(X) returns the 2D/3D convex hull of the points X. This

variant supports the definition of points in matrix format. X is of

size mpts-by-ndim, where mpts is the number of points and ndim is the

dimension of the space where the points reside, 2 <= ndim <= 3.

The output facets are equivalent to those generated by the 2-input or

3-input calling syntax.

K = CONVHULL(...,'simplify', logicalvar) provides the option of

removing vertices that do not contribute to the area/volume of the

convex hull, the default is false. Setting 'simplify' to true returns

the topology in a more concise form.

[K,V] = CONVHULL(...) returns the convex hull K and the corresponding

area/volume V bounded by K.

Example 1:

x = rand(20,1);

y = rand(20,1);

plot(x,y, '.');

k = convhull(x,y)

hold on, plot(x(k), y(k), '-r'), hold off

Example 2:

[x,y,z] = meshgrid(-2:1:2, -2:1:2, -2:1:2);

x = x(:); y = y(:); z = z(:);

K1 = convhull(x,y,z);

subplot(1,2,1);

trisurf(K1,x,y,z, 'Facecolor','cyan'); axis equal;

title(sprintf('Convex hull with simplify\nset to false'));

K2 = convhull(x,y,z, 'simplify',true);

subplot(1,2,2);

trisurf(K2,x,y,z, 'Facecolor','cyan'); axis equal;

title(sprintf('Convex hull with simplify\nset to true'));

See also DelaunayTri, TriRep, trisurf, inpolygon, convhulln, delaunay,

voronoi, polyarea.

Reference page in Help browser

doc convhull

<convhulln> - N-D convex hull.

CONVHULLN N-D Convex hull.

K = CONVHULLN(X) returns the indices K of the points in X that

comprise the facets of the convex hull of X.

X is an m-by-n array representing m points in n-D space.

If the convex hull has p facets then K is p-by-n.

CONVHULLN uses Qhull.

K = CONVHULLN(X,OPTIONS) specifies a cell array of strings OPTIONS to be

used as options in Qhull. The default options are:

{'Qt'} for 2D, 3D and 4D input,

{'Qt','Qx'} for 5D and higher.

If OPTIONS is [], the default options will be used.

If OPTIONS is {''}, no options will be used, not even the default.

For more information on Qhull and its options, see http://www.qhull.org.

[K,V] = CONVHULLN(...) also returns the volume of the convex hull

in V.

Example:

X = [0 0; 0 1e-10; 0 0; 1 1];

K = convhulln(X)

gives a warning that is suppresed by the additional option 'Pp':

K = convhulln(X,{'Qt','Pp'})

See also DelaunayTri, TriRep, convhull, qhull, delaunayn, voronoin,

tsearchn, dsearchn.

Reference page in Help browser

doc convhulln

<voronoi> - Voronoi diagram.

VORONOI Voronoi diagram.

VORONOI(X,Y) plots the Voronoi diagram for the points X,Y. Lines-to-

infinity are approximated with an arbitrarily distant endpoint.

VORONOI(X,Y,OPTIONS) specifies a cell array of strings OPTIONS

that were previously used by Qhull. Qhull-specific OPTIONS are no longer

required and are currently ignored. Support for these options will be

removed in a future release.

VORONOI(X,Y,TRI) uses the Delaunay triangulation TRI instead of

computing it internally.

VORONOI(DT) uses the Delaunay triangulation DT instead of computing it

internally, where DT is a DelaunayTri.

VORONOI(AX,...) plots into AX instead of GCA.

H = VORONOI(...,'LineSpec') plots the diagram with color and linestyle

specified and returns handles to the line objects created in H.

[VX,VY] = VORONOI(...) returns the vertices of the Voronoi edges in VX

and VY so that plot(VX,VY,'-',X,Y,'.') creates the Voronoi diagram.

The lines-to-infinity are the last columns of VX and VY. To

ensure the lines-to-infinity do not affect the settings of the axis

limits, use the commands:

h = plot(VX,VY,'-',X,Y,'.');

set(h(1:end-1),'xliminclude','off','yliminclude','off')

For the topology of the voronoi diagram, i.e. the vertices for

each voronoi cell, use DelaunayTri/voronoiDiagram as follows:

dt = DelaunayTri(X(:),Y(:))

[V,C] = voronoiDiagram(dt)

See also DelaunayTri, voronoin, delaunay, convhull.

Reference page in Help browser

doc voronoi

<voronoin> - N-D Voronoi diagram.

VORONOIN N-D Voronoi diagram.

[V,C] = VORONOIN(X) returns Voronoi vertices V and the Voronoi cells C

of the Voronoi diagram of X. V is a numv-by-n array of the numv Voronoi

vertices in n-D space, each row corresponds to a Voronoi vertex. C is

a vector cell array where each element is the indices into V of the

vertices of the corresponding Voronoi cell. X is an m-by-n array,

representing m n-D points.

VORONOIN uses Qhull.

[V,C] = VORONOIN(X,OPTIONS) specifies a cell array of strings OPTIONS

to be used as options in Qhull. The default options are:

{'Qbb'} for 2D and 3D input,

{'Qbb','Qx'} for 4D and higher.

If OPTIONS is [], the default options will be used.

If OPTIONS is {''}, no options will be used, not even the default.

For more information on Qhull options, see http://www.qhull.org.

Example 1:

If

X = [0.5 0; 0 0.5; -0.5 -0.5; -0.2 -0.1; -0.1 0.1; 0.1 -0.1; 0.1 0.1]

[V,C] = voronoin(X)

To see the contents of C, use the following commands

for i = 1:length(C), disp(C{i}), end

In particular, the fifth Voronoi cell consists of 4 points:

V(10,:), V(3,:), V(5,:), V(7,:).

For 2-D, vertices in C are listed in adjacent order, i.e. connecting

them will generate a closed polygon (Voronoi diagram). For 3-D

and above, vertices are listed in ascending order. To generate

a particular cell of the Voronoi diagram, use CONVHULLN to compute

the facets of that cell, e.g. to generate the fifth Voronoi cell,

X = V(C{5},:);

K = convhulln(X);

Example 2:

X = [-1 -1; 1 -1; 1 1; -1 1];

[V,C] = voronoin(X)

errors, but hints that adding 'Qz' to the default options might help.

[V,C] = voronoin(X,{'Qbb','Qz'})

See also DelaunayTri, voronoi, qhull, delaunayn, convhulln, delaunay, convhull.

Reference page in Help browser

doc voronoin

<inpolygon> - True for points inside polygonal region.

INPOLYGON True for points inside or on a polygonal region.

IN = INPOLYGON(X,Y,XV,YV) returns a matrix IN the size of X and Y.

IN(p,q) = 1 if the point (X(p,q), Y(p,q)) is either strictly inside or

on the edge of the polygonal region whose vertices are specified by the

vectors XV and YV; otherwise IN(p,q) = 0.

[IN ON] = INPOLYGON(X,Y,XV,YV) returns a second matrix, ON, which is

the size of X and Y. ON(p,q) = 1 if the point (X(p,q), Y(p,q)) is on

the edge of the polygonal region; otherwise ON(p,q) = 0.

INPOLYGON supports non-convex and self-intersecting polygons.

The function also supports multiply-connected or disjoint polygons;

however, the distinct edge loops should be separated by NaNs. In the

case of multiply-connected polygons, the external and internal loops

should have opposite orientations; for example, a counterclockwise

outer loop and clockwise inner loops or vice versa. Self-intersections

are not supported in this context due to the ambiguity associated with

loop orientations.

Example 1:

% Self-intersecting polygon

xv = rand(6,1); yv = rand(6,1);

xv = [xv ; xv(1)]; yv = [yv ; yv(1)];

x = rand(1000,1); y = rand(1000,1);

in = inpolygon(x,y,xv,yv);

plot(xv,yv,x(in),y(in),'.r',x(~in),y(~in),'.b')

Example 2:

% Multiply-connected polygon - a square with a square hole.

% Counterclockwise outer loop, clockwise inner loop.

xv = [0 3 3 0 0 NaN 1 1 2 2 1];

yv = [0 0 3 3 0 NaN 1 2 2 1 1];

x = rand(1000,1)*3; y = rand(1000,1)*3;

in = inpolygon(x,y,xv,yv);

plot(xv,yv,x(in),y(in),'.r',x(~in),y(~in),'.b')

Class support for inputs X,Y,XV,YV:

float: double, single

See also, DelaunayTri

Copyright 1984-2010 The MathWorks, Inc.

$Revision: 1.14.4.8 $ $Date: 2010/04/21 21:32:41 $

Reference page in Help browser

doc inpolygon

<rectint> - Rectangle intersection area.

RECTINT Rectangle intersection area.

AREA = RECTINT(A,B) returns the area of intersection of the

rectangles specified by position vectors A and B.

If A and B each specify one rectangle, the output AREA is a scalar.

A and B can also be matrices, where each row is a position vector.

AREA is then a matrix giving the intersection of all rectangles

specified by A with all the rectangles specified by B. That is, if A

is M-by-4 and B is N-by-4, then AREA is an M-by-N matrix where

AREA(P,Q) is the intersection area of the rectangles specified by the

Pth row of A and the Qth row of B.

Note: A position vector is a four-element vector [X,Y,WIDTH,HEIGHT],

where the point defined by X and Y specifies one corner of the

rectangle, and WIDTH and HEIGHT define the size in units along the x-

and y-axes respectively.

Class support for inputs A,B:

float: double, single

Reference page in Help browser

doc rectint

<polyarea> - Area of polygon.

POLYAREA Area of polygon.

POLYAREA(X,Y) returns the area of the polygon specified by

the vertices in the vectors X and Y. If X and Y are matrices

of the same size, then POLYAREA returns the area of

polygons defined by the columns X and Y. If X and Y are

arrays, POLYAREA returns the area of the polygons in the

first non-singleton dimension of X and Y.

The polygon edges must not intersect. If they do, POLYAREA

returns the absolute value of the difference between the clockwise

encircled areas and the counterclockwise encircled areas.

POLYAREA(X,Y,DIM) returns the area of the polygons specified

by the vertices in the dimension DIM.

Class support for inputs X,Y:

float: double, single

Reference page in Help browser

doc polyarea

Triangulation Representation

<TriRep> - A Triangulation Representation

TriRep A Triangulation Representation

TriRep is a triangulation representation that provides topological and

geometric queries for triangulations in 2D and 3D space. For example,

for triangular meshes you can query triangles attached to a vertex,

triangles that share an edge, neighbor information, circumcenters, etc.

You can create a TriRep directly using existing triangulation data.

Alternatively, you can create a Delaunay triangulation, via DelaunayTri,

which provides access to the TriRep functionality.

TR = TriRep(TRI, X, Y) creates a 2D TriRep from the triangulation matrix

TRI and the vertex coordinates (X, Y). TRI is an m-by-3 matrix that

defines the triangulation in face-vertex format, where m is the

number of triangles. Each row of TRI is a triangle defined by indices

into the column vector of vertex coordinates (X, Y).

TR = TriRep(TRI, X, Y, Z) creates a 3D TriRep from the triangulation

matrix TRI and the vertex coordinates (X, Y, Z). TRI is an m-by-3 or

m-by-4 matrix that defines the triangulation in simplex-vertex

format, where m is the number of simplices; triangles or tetrahedra

in this case. Each row of TRI is a simplex defined by indices into the

column vector of vertex coordinates (X, Y, Z).

TR = TriRep(TRI, X) creates a TriRep from the triangulation matrix TRI

and the vertex coordinates X. TRI is an m-by-n matrix that defines the

triangulation in simplex-vertex format, where m is the number of

simplices and n is the number of vertices per simplex. Each row of TRI

is a simplex defined by indices into the array of vertex coordinates X.

X is a mpts-by-ndim matrix where mpts is the number of points and ndim

is the dimension of the space where the points reside, 2 <= ndim <= 3.

Example 1:

% Load a 2D triangulation and use the TriRep

% to build an array of the free boundary edges.

load trimesh2d

% This loads triangulation tri and vertex coordinates x, y

trep = TriRep(tri, x,y);

fe = freeBoundary(trep)';

triplot(trep);

% Add the free edges in red

hold on; plot(x(fe), y(fe), 'r','LineWidth',2); hold off;

axis([-50 350 -50 350]);

axis equal;

Example 2:

% Load a 3D tetrahedral triangulation and use the TriRep

% to compute the free boundary; the surface of the triangulation.

load tetmesh

% This loads triangulation tet and vertex coordinates X

trep = TriRep(tet, X);

[tri, Xb] = freeBoundary(trep);

%Plot the surface mesh

trisurf(tri, Xb(:,1), Xb(:,2), Xb(:,3), 'FaceColor', 'cyan', 'FaceAlpha', 0.8);

Example 3:

% Direct query of a 3D Delaunay triangulation created using

% DelaunayTri. Compute the free boundary as in Example 2

X = rand(50,3);

dt = DelaunayTri(X);

[tri, Xb] = freeBoundary(dt);

%Plot the surface mesh

trisurf(tri, Xb(:,1), Xb(:,2), Xb(:,3), 'FaceColor', 'cyan','FaceAlpha', 0.8);

TriRep methods:

baryToCart - Converts the coordinates of a point from barycentric to cartesian

cartToBary - Converts the coordinates of a point from cartesian to barycentric

circumcenters - Returns the circumcenters of the specified simplices

edgeAttachments - Returns the simplices attached to the specified edges

edges - Returns the edges in the triangulation

faceNormals - Returns the unit normals to the specified triangles

featureEdges - Returns the sharp edges of a surface triangulation

freeBoundary - Returns the facets referenced by only one simplex

incenters - Returns the incenters of the specified simplices

isEdge - Tests whether a pair of vertices are joined by an edge

neighbors - Returns the simplex neighbor information

vertexAttachments - Returns the simplices attached to the specified vertices

size - Returns the size of the Triangulation matrix

TriRep properties:

X - The coordinates of the points in the triangulation

Triangulation - The triangulation data structure

See also DelaunayTri.

Reference page in Help browser

doc TriRep

<TriRep/baryToCart> - Converts the coordinates of a point from barycentric to cartesian

baryToCart Converts the coordinates of a point from barycentric to cartesian

XC = baryToCart(TR, SI, B) Returns the cartesian coordinates XC of each

point in B that represents the barycentric coordinates with respect to

its associated simplex SI. A simplex is a triangle/tetrahedron or higher

dimensional equivalent. SI is a column vector of simplex indices that

index into the triangulation matrix TR.Triangulation.

B is a matrix that represents the barycentric coordinates of the points

to convert with respect to the simplices SI. B is of size m-by-k,

where m is of length(SI), the number of points to convert, and k

is the number of vertices per simplex.

XC is a matrix that represents the cartesian coordinates of the converted

points. XC is of size m-by-n, where n is the dimension of the space

where the triangulation resides. That is, the cartesian coordinates of

the point B(j) with respect to simplex SI(j) is XC(j).

Example 1: Compute the Delaunay triangulation of a set of points.

Compute the barycentric coordinates of the incenters.

"Stretch" the triangulation and compute the mapped locations

of the incenters on the deformed triangulation.

x = [0 4 8 12 0 4 8 12]';

y = [0 0 0 0 8 8 8 8]';

dt = DelaunayTri(x,y)

cc = incenters(dt);

tri = dt(:,:);

subplot(1,2,1);

triplot(dt); hold on;

plot(cc(:,1), cc(:,2), '*r'); hold off;

axis equal;

title(sprintf('Original triangulation and reference points.\n'));

b = cartToBary(dt,[1:length(tri)]',cc);

% Create a representation of the stretched triangulation

y = [0 0 0 0 16 16 16 16]';

tr = TriRep(tri,x,y)

xc = baryToCart(tr, [1:length(tri)]', b);

subplot(1,2,2);

triplot(tr); hold on;

plot(xc(:,1), xc(:,2), '*r'); hold off;

axis equal;

title(sprintf('Deformed triangulation and mapped\n locations of the reference points.\n'));

See also TriRep, TriRep/cartToBary, DelaunayTri, DelaunayTri/pointLocation.

Reference page in Help browser

doc TriRep/baryToCart

<TriRep/cartToBary> - Converts the coordinates of a point from cartesian to barycentric

cartToBary Converts the coordinates of a point from cartesian to barycentric

B = cartToBary(TR, SI, XC) Returns the barycentric coordinates of each

point in XC with respect to its associated simplex SI.

A simplex is a triangle/tetrahedron or higher dimensional equivalent.

SI is a column vector of simplex indices that index into the

triangulation matrix TR.Triangulation. XC is a matrix that represents

the cartesian coordinates of the points to be converted. XC is of size

m-by-n, where m is of length(SI), the number of points to convert, and n

is the dimension of the space where the triangulation resides.

B represents the barycentric coordinates of the points XC with respect

to the simplices SI. That is, the barycentric coordinates of the point

XC(j) with respect to simplex SI(j) is B(j). B is a matrix of dimension

m-by-k where k is the number of vertices per simplex.

Example 1: Compute the Delaunay triangulation of a set of points.

Compute the barycentric coordinates of the incenters.

"Stretch" the triangulation and compute the mapped locations

of the incenters on the deformed triangulation.

x = [0 4 8 12 0 4 8 12]';

y = [0 0 0 0 8 8 8 8]';

dt = DelaunayTri(x,y)

cc = incenters(dt);

tri = dt(:,:);

subplot(1,2,1);

triplot(dt); hold on;

plot(cc(:,1), cc(:,2), '*r'); hold off;

axis equal;

title(sprintf('Original triangulation and reference points.\n'));

b = cartToBary(dt,[1:length(tri)]',cc);

% Create a representation of the stretched triangulation

y = [0 0 0 0 16 16 16 16]';

tr = TriRep(tri,x,y)

xc = baryToCart(tr, [1:length(tri)]', b);

subplot(1,2,2);

triplot(tr); hold on;

plot(xc(:,1), xc(:,2), '*r'); hold off;

axis equal;

title(sprintf('Deformed triangulation and mapped\n locations of the reference points.\n'));

See also TriRep, TriRep/baryToCart, DelaunayTri, DelaunayTri/pointLocation.

Reference page in Help browser

doc TriRep/cartToBary

<TriRep/circumcenters> - Returns the circumcenters of the specified simplices

circumcenters Returns the circumcenters of the specified simplices

CC = circumcenters(TR, SI) Returns the coordinates of the circumcenter

of each specified simplex SI. A simplex is a triangle/tetrahedron or

higher dimensional equivalent. SI is a column vector of simplex indices

that index into the triangulation matrix TR.Triangulation.

CC is an m-by-n matrix, where m is of length(SI), the number of specified

simplices, and n is the dimension of the space where the triangulation

resides. Each row CC(i,:) represents the coordinates of the circumcenter

of simplex SI(i). If SI is not specified the circumcenter information for

the entire triangulation is returned, where the circumcenter associated

with simplex i is the i'th row of CC.

[CC RCC] = circumcenters(TR, SI) returns in addition, the corresponding

radius of the circumscribed circle/sphere. RCC is a vector of length

length(SI), the number of specified simplices.

Example 1: Load a 2D triangulation and use the TriRep to compute the

circumcenters.

load trimesh2d

% This loads triangulation tri and vertex coordinates x, y

trep = TriRep(tri, x,y)

cc = circumcenters(trep);

triplot(trep);

axis([-50 350 -50 350]);

axis equal;

hold on; plot(cc(:,1),cc(:,2),'*r'); hold off;

% The circumcenters represent points on the

% medial axis of the polygon.

Example 2: Direct query of a 3D triangulation created using DelaunayTri

Compute the circumcenters of the first five tetrahedra.

X = rand(10,3);

dt = DelaunayTri(X);

[cc rcc] = circumcenters(dt, [1:5]')

See also TriRep, TriRep/incenters, DelaunayTri.

Reference page in Help browser

doc TriRep/circumcenters

<TriRep/edges> - Returns the edges in the triangulation

edges returns the edges in the triangulation

E = edges(TR) Returns the edges in the triangulation in an n-by-2

matrix, n being the number of edges. The vertices of the edges index

into TR.X, the array of points representing the vertex coordinates.

Example 1:

% Load a 2D triangulation and use the TriRep

% to construct a set of edges.

load trimesh2d

% This loads triangulation tri and vertex coordinates x, y

trep = TriRep(tri, x,y)

e = edges(trep)

% Direct query of a 2D Delaunay triangulation created using

% DelaunayTri. Construct the set of edges as in the previous case.

X = rand(10,2)

dt = DelaunayTri(X)

e = edges(dt)

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/edges

<TriRep/edgeAttachments> - Returns the simplices attached to the specified edges

edgeAttachments Returns the simplices attached to the specified edges

SI = edgeAttachments(TR, V1, V2) Returns the simplices SI attached to the

edges specified by (V1, V2). A simplex is a triangle/tetrahedron or

higher dimensional equivalent. SI is a vector cell array where each cell

contains indices into the triangulation matrix; TR.Triangulation.

(V1, V2) are column vectors of vertex indices into the array of points

representing the vertex coordinates, TR.X. (V1, V2) represents the start

and end vertices of the edges to be queried.

SI is a cell array because the number of simplices associated with each

edge can vary.

SI = edgeAttachments(TR, EDGE) Specifies the edge start and end

points in matrix format, where EDGE is of size m-by-2, m being the

number of edges to query.

Example 1: Load a 3D triangulation and use the TriRep to compute the

tetrahedra attached to an edge.

load tetmesh

% This loads triangulation tet and vertex coordinates X

trep = TriRep(tet, X)

v1 = [15 21]'

v2 = [936 716]'

t = edgeAttachments(trep, v1, v2)

t{:}

% Alternatively, specify as edges

e = [v1 v2]

t = edgeAttachments(trep, e)

t{:}

Example 2: Direct query of a triangulation created using DelaunayTri

% Create a 2D Delaunay triangulation and query the triangles attached

% to edge(1,5)

x = [0 1 1 0 0.5]'

y = [0 0 1 1 0.5]'

dt = DelaunayTri(x,y)

t = edgeAttachments(dt, 1,5)

t{:}

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/edgeAttachments

<TriRep/faceNormals> - Returns the normals to the specified triangular simplices

faceNormals Returns the unit normals to the specified triangles

This query is only applicable to triangular surface meshes.

FN = faceNormals(TR, TI) Returns the unit normal vector to each of the

specified triangles TI, where TI is a column vector of indices that

index into the triangulation matrix TR.Triangulation.

FN is an m-by-3 matrix, where m is length(TI), the number of triangles

to be queried. Each row FN(i,:) represents the unit normal vector to

triangle TI(i). If TI is not specified the unit normal information for

the entire triangulation is returned, where the normal associated with

triangle i is the i'th row of FN.

Example:

% Triangulate a sample of random points on the surface of a sphere

% and use the TriRep to compute the normal to each triangle.

% Display the result using a quiver plot.

numpts = 100;

thetha = rand(numpts,1)*2*pi;

phi = rand(numpts,1)*pi;

x = cos(thetha).*sin(phi);

y = sin(thetha).*sin(phi);

z = cos(phi);

dt = DelaunayTri(x,y,z);

[tri Xb] = freeBoundary(dt);

tr = TriRep(tri, Xb);

P = incenters(tr);

fn = faceNormals(tr);

trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3),'FaceColor', 'cyan', 'faceAlpha', 0.8);

axis equal;

hold on;

quiver3(P(:,1),P(:,2),P(:,3),fn(:,1),fn(:,2),fn(:,3),0.5, 'color','r');

hold off;

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/faceNormals

<TriRep/featureEdges> - Returns the sharp edges of a surface triangulation

featureEdges Returns the sharp edges of a surface triangulation

This query is only applicable to triangular surface meshes.

FE = featureEdges(TR, FILTERANGLE) Returns a matrix FE that represents

the edges of the triangulation whose adjacent triangles have a dihedral

angle that deviates from PI by an angle greater than FILTERANGLE. This

method is typically used to extract the sharp edges in the surface mesh

for the purpose of display. Edges that are shared by only one triangle,

and edges that are shared by more than two triangles are considered to

be feature edges by default.

FE is of size m-by-2 where m is the number of feature edges in the mesh.

The vertices of the edges index into the array of points

representing the vertex coordinates, TR.X.

Example 1:

% Create a surface triangulation and extract the feature edges.

x = [0 0 0 0 0 3 3 3 3 3 3 6 6 6 6 6 9 9 9 9 9 9]';

y = [0 2 4 6 8 0 1 3 5 7 8 0 2 4 6 8 0 1 3 5 7 8]';

dt = DelaunayTri(x,y);

tri = dt(:,:);

% Elevate the 2D mesh to create a surface

z = [0 0 0 0 0 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0]';

subplot(1,2,1);

trisurf(tri,x,y,z, 'FaceColor', 'cyan'); axis equal;

title(sprintf('TRISURF display of surface mesh\n showing mesh edges\n'));

% Compute the feature edges using a filter angle of pi/4

tr = TriRep(tri, x,y,z);

fe = featureEdges(tr,pi/6)';

subplot(1,2,2);

trisurf(tr, 'FaceColor', 'cyan', 'EdgeColor','none', ...

'FaceAlpha', 0.8); axis equal;

% Add the feature edges

hold on; plot3(x(fe), y(fe), z(fe), 'k', 'LineWidth',1.5); hold off;

title(sprintf('TRISURF display of surface mesh\n suppressing mesh edges\nand showing feature edges'));

Example 2:

% Load a 3D triangulation and use the TriRep to compute the

% featureEdges and plot the result.

load trimesh3d.mat

% Construct a TriRep that represents the triangulation

tr = TriRep(tri, x,y,z);

% Extract the feature edges.

fe = tr.featureEdges(pi/4);

fe = fe';

trisurf(tr,'FaceColor', 'cyan', 'EdgeColor', 'none');

axis equal

hold on

plot3(x(fe), y(fe), z(fe), '-k', 'LineWidth', 1.35);

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/featureEdges

<TriRep/freeBoundary> - Returns the facets that are referenced by only one simplex

freeBoundary Returns the facets referenced by only one simplex

FF = freeBoundary(TR) Returns a matrix FF that represents the free

boundary facets of the triangulation. A facet is on the free boundary

if it is referenced by only one simplex (triangle/tetrahedron, etc).

FF is of size m-by-n, where m is the number of boundary facets and n is

the number of vertices per facet. The vertices of the facets index into

the array of points representing the vertex coordinates TR.X. The array

FF could be empty as in the case of a triangular mesh representing the

surface of a sphere.

[FF XF] = freeBoundary(TR) Returns a matrix of free boundary facets FF

that has vertices defined in terms of a compact array of coordinates XF.

XF is of size m-by-ndim where m is the number of free facets, and ndim

is the dimension of the space where the triangulation resides.

Example 1: Load a 3D triangulation and use the TriRep to compute the

boundary triangulation.

load tetmesh

% This loads triangulation tet and vertex coordinates X

trep = TriRep(tet, X)

[tri xf] = freeBoundary(trep);

%Plot the boundary triangulation

trisurf(tri, xf(:,1),xf(:,2),xf(:,3), 'FaceColor', 'cyan', 'FaceAlpha', 0.8);

Example 2:Direct query of a 2D triangulation created using DelaunayTri

% Plot the mesh and display the free boundary edges in red.

x = rand(20,1)

y = rand(20,1)

dt = DelaunayTri(x,y)

fe = freeBoundary(dt)';

triplot(dt);

hold on ; plot(x(fe), y(fe), '-r', 'LineWidth',2) ; hold off ;

% In this instance the free edges correspond to the convex hull of

% (x, y).

See also TriRep.

Reference page in Help browser

doc TriRep/freeBoundary

<TriRep/incenters> - Returns the incenters of the specified simplices

incenters Returns the incenters of the specified simplices

IC = incenters(TR, SI) Returns the coordinates of the incenter of each

specified simplex SI. A simplex is a triangle/tetrahedron or higher

dimensional equivalent. SI is a column vector of simplex indices that

index into the triangulation matrix TR.Triangulation.

IC is an m-by-n matrix, where m is of length(SI), the number of specified

simplices, and n is the dimension of the space where the triangulation

resides. Each row IC(i,:) represents the coordinates of the incenter

of simplex SI(i). If SI is not specified the incenter information for the

entire triangulation is returned, where the incenter associated with

simplex i is the i'th row of IC.

[IC RIC] = incenters(TR, SI) returns in addition, the corresponding

radius of the inscribed circle/sphere. RIC is a vector of length

length(SI), the number of specified simplices.

Example 1: Load a 3D triangulation and use the TriRep to compute the

incenters of the first five tetraherda.

load tetmesh

% This loads triangulation tet and vertex coordinates X

trep = TriRep(tet, X)

[ic ric] = incenters(trep, [1:5]')

Example 2: Direct query of a 2D triangulation created using DelaunayTri

Compute the incenters of the triangles and plot triangles

and incenters.

x = [0 1 1 0 0.5]';

y = [0 0 1 1 0.5]';

dt = DelaunayTri(x,y);

ic = incenters(dt);

% Display the triangles and incenters

triplot(dt);

axis equal;

axis([-0.2 1.2 -0.2 1.2]);

hold on; plot(ic(:,1),ic(:,2),'*r'); hold off;

See also TriRep, TriRep/circumcenters, DelaunayTri.

Reference page in Help browser

doc TriRep/incenters

<TriRep/isEdge> - Tests whether a pair of vertices are joined by an edge

isEdge Tests whether a pair of vertices are joined by an edge

TF = isEdge(TR, V1, V2) Returns an array of 1/0 (true/false) flags,

where each entry TF(i) is true if V1(i), V2(i) is an edge in the

triangulation. V1, V2 are column vectors representing the indices of the

vertices in the mesh, that is, indices into the vertex coordinate arrays.

TF = isEdge(TR, EDGE) Specifies the edge start and end indices in

matrix format where EDGE is of size n-by-2, n being the number of

query edges.

Example 1:

% Load a 2D triangulation and use the TriRep to query the

% presence of an edge between a pair of points.

load trimesh2d

% This loads triangulation tri and vertex coordinates x, y

trep = TriRep(tri, x,y);

triplot(trep);

vxlabels = arrayfun(@(n) {sprintf('P%d', n)}, [3 117 164]');

Hpl = text(x([3 117 164]), y([3 117 164]), vxlabels, 'FontWeight', ...

'bold', 'HorizontalAlignment',...

'center', 'BackgroundColor', 'none');

axis([-50 350 -50 350]);

axis equal;

% Are vertices 3 and 117 connected by an edge?

% (Bottom right-hand corner.)

isEdge(trep, 3, 117)

isEdge(trep, 3, 164)

Example 2:

% Direct query of a 3D Delaunay triangulation created using

% DelaunayTri.

X = rand(10,3)

dt = DelaunayTri(X)

% Are vertices 2 and 7 connected by an edge?

isEdge(dt, 2, 7)

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/isEdge

<TriRep/neighbors> - Returns the simplex neighbor information

neighbors Returns the simplex neighbor information

SN = neighbors(TR, SI) Returns the simplex neighbor information for

the specified simplices SI. A simplex is a triangle/tetrahedron or

higher dimensional equivalent. SI is a column vector of simplex indices

that index into the triangulation matrix TR.Triangulation.

SN is an m-by-n matrix, where m is of length(SI), the number of specified

simplices, and n is the number of neighbors per simplex. Each row SN(i,:)

represents the neighbors of the simplex SI(i). If SI is not specified the

neighbor information for the entire triangulation is returned, where

the neighbors associated with simplex i are defined by the i'th row of SN.

By convention, the simplex opposite vertex(j) of simplex SI(i)

is SN(i,j). If a simplex has one or more boundary facets, the

nonexistent neighbors are represented by NaN.

Example 1: Load a 2D triangulation and use the TriRep to compute the

neighboring triangles.

load trimesh2d

% This loads triangulation tet and vertex coordinates X

trep = TriRep(tri,x,y)

triplot(trep);

trigroup = neighbors(trep,35)';

trigroup(end+1) = 35;

ic = incenters(trep, trigroup);

hold on

axis([-50 350 -50 350]);

axis equal;

trilabels = arrayfun(@(x) {sprintf('T%d', x)}, trigroup);

Htl = text(ic(:,1), ic(:,2), trilabels, 'FontWeight', 'bold', ...

'HorizontalAlignment', 'center', 'Color', 'red');

hold off

Example 2: Direct query of a 2D triangulation created using DelaunayTri

% Create a 2D Delaunay Triangulation

% from random points in the unit square.

x = rand(10,1)

y = rand(10,1)

dt = DelaunayTri(x,y)

% What are the neighbors of the first triangle

n1 = neighbors(dt, 1)

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/neighbors

<TriRep/size> - Returns the size of the Triangulation matrix

size Returns the size of the Triangulation matrix

TriRep overrides the MATLAB size function to provide size

information for the Triangulation matrix. The matrix is of size

mtri-by-nv, where mtri is the number of simplices and nv is the

number of vertices per simplex (triangle/tetrahedron, etc).

Reference page in Help browser

doc TriRep/size

<TriRep/vertexAttachments> - Returns the simplices attached to the specified vertices

vertexAttachments Returns the simplices attached to the specified vertices

SI = vertexAttachments(TR, VI) Returns the vertex-to-simplex information

for the specified vertices VI. A simplex is a triangle/tetrahedron or

higher dimensional equivalent. VI is a column vector of indices into

the array of points representing the vertex coordinates, TR.X.

The simplices associated with vertex i are the i'th entry in the cell

array. If VI is not specified the vertex-simplex information for the

entire triangulation is returned, where the simplices associated with

vertex i are in the i'th entry in the cell array SI. A cell array is

used to store the information because the number of simplices associated

with each vertex can vary.

In relation to 2D triangulations, if the triangulation has a consistent

orientation the triangles in each cell will be ordered consistently

around each vertex.

Example 1: Load a 2D triangulation and use the TriRep to compute the

vertex-to-ttriangle relations.

load trimesh2d

% This loads triangulation tet and vertex coordinates X

trep = TriRep(tri, x, y);

Tv = vertexAttachments(trep, 1)

% The indices of the tetrahedra attached to the first vertex

Tv{:}

Example 2: Direct query of a 2D triangulation created using DelaunayTri

x = rand(20,1);

y = rand(20,1);

dt = DelaunayTri(x,y);

t = vertexAttachments(dt,5);

% Plot the triangles attached to vertex 5, in red.

triplot(dt);

hold on; triplot(dt(t{:},:),x,y,'Color','r'); hold off;

See also TriRep, DelaunayTri.

Reference page in Help browser

doc TriRep/vertexAttachments

Соседние файлы в папке Библиотеки Matlab