﻿

# asp.net c# pdf viewer : Break pdf into smaller files SDK application service wpf azure winforms dnn octave68-part540

Chapter30: Geometry
665
30 Geometry
Muchofthe geometrycodeinOctaveisbasedontheQhulllibrary
1
. Someofthedocu-
mentationforQhull,particularlyfortheoptionsthatcanbepassedtodelaunay,voronoi
andconvhull,etc.,isrelevanttoOctaveusers.
30.1 DelaunayTriangulation
TheDelaunaytriangulationisconstructedfromasetofcircum-circles.Thesecircum-circles
arechosensothatthereareatleastthreeofthepointsinthesettotriangulationonthe
circumferenceofthecircum-circle. Noneofthepointsinthesetofpointsfallswithinany
ofthecircum-circles.
Ingeneralthereareonlythreepointsonthecircumferenceofanycircum-circle.However,
insomecases,andinparticularforthecaseofaregulargrid,4ormorepointscanbeona
singlecircum-circle. InthiscasetheDelaunaytriangulationisnotunique.
[FunctionFile]
tri = = delaunay
(
x
,
y
)
[FunctionFile]
tetr = delaunay
(
x
,
y
,
z
)
[FunctionFile]
tri = = delaunay
(
x
)
[FunctionFile]
tri = = delaunay
(...,
options
)
ComputetheDelaunaytriangulationfora2-Dor3-Dsetofpoints.
For 2-Dsets, , the returnvalue tri isa set t oftriangles whichsatisﬁes theDelaunay
circum-circlecriterion,i.e.,onlyasingledatapointfrom[x,y]iswithinthecircum-
circleofthedeﬁningtriangle. Thesetoftrianglestriisamatrixofsize[n,3]. Each
rowdeﬁnesa triangleandthe three columns arethethreevertices of thetriangle.
Thevalueoftri(i,j)isanindexintox andy forthelocationofthej-thvertexof
thei-thtriangle.
For3-Dsets,thereturnvaluetetrisasetoftetrahedronswhichsatisﬁestheDelaunay
circum-circlecriterion,i.e.,onlyasingledatapointfrom[x,y,z]iswithinthecircum-
circleofthedeﬁningtetrahedron. Thesetoftetrahedronsisamatrixofsize[n,4].
Eachrow deﬁnes s atetrahedronandthe e four columns s are e the e four vertices s of the
tetrahedron. Thevalueoftetr(i,j)isanindexintox,y,zforthelocationofthe
j-thvertexofthei-thtetrahedron.
Theinputx mayalsobeamatrixwithtwoorthreecolumnswheretheﬁrstcolumn
containsx-data,thesecondy-data,andtheoptionalthirdcolumncontainsz-data.
Theoptionallastargument,whichmustbeastringorcellarrayofstrings,contains
options passed d to the underlying qhull command. . See e the documentation for the
Qhull library y for details http://www.qhull.org/html/qh-quick.htm#options.
Thedefaultoptionsare{"Qt","Qbb","Qc","Qz"}.
If options s is not present or [] then the default arguments are e used. . Otherwise,
optionsreplacesthedefaultargumentlist. Toappenduseroptionstothedefaultsit
isnecessarytorepeatthedefaultargumentsinoptions. Useanullstringtopassno
arguments.
1
Barber,C.B.,Dobkin,D.P.,and Huhdanpaa,H.T.,TheQuickhullAlgorithmforConvexHulls,ACM
Trans. onMathematicalSoftware,22(4):469–483,Dec1996,http://www.qhull.org
Break pdf into smaller files - Split, seperate PDF into multiple files in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Explain How to Split PDF Document in Visual C#.NET Application
break pdf into single pages; pdf separate pages
Break pdf into smaller files - VB.NET PDF File Split Library: Split, seperate PDF into multiple files in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Splitter Control to Disassemble PDF Document
add page break to pdf; break a pdf file
666
GNUOctave
x = rand d (1, , 10);
y = rand d (1, , 10);
tri = = delaunay y (x, y);
triplot (tri, , x, y);
hold on;
plot (x, , y, , "r*");
axis ([0,1,0,1]);
See also: [delaunayn], page 666,[convhull],page675,[voronoi],page672,[triplot],
page667,[trimesh],page667,[tetramesh],page668,[trisurf],page668.
For3-DinputsdelaunayreturnsasetoftetrahedrathatsatisfytheDelaunaycircum-
circlecriteria. Similarly,delaunaynreturnstheN-dimensionalsimplexsatisfyingtheDe-
launay circum-circlecriteria. . The e N-dimensional extensionofa triangulation is calleda
tessellation.
[FunctionFile]
T = = delaunayn
(
pts
)
[FunctionFile]
T = = delaunayn
(
pts
,
options
)
ComputetheDelaunaytriangulationforanN-dimensionalsetofpoints.
TheDelaunaytriangulationisatessellationoftheconvexhullofasetofpointssuch
thatnoN-spheredeﬁnedbytheN-trianglescontainsanyotherpointsfromtheset.
Theinputmatrixptsofsize[n,dim]containsnpointsinaspaceofdimensiondim.
ThereturnmatrixT has s size[m,dim+1]. . EachrowofT T contains s asetofindices
backintotheoriginalsetofpoints pts whichdescribesasimplexofdimensiondim.
Forexample,a2-Dsimplexisatriangleand3-Dsimplexisatetrahedron.
Anoptionalsecondargument,whichmustbeastringorcellarrayofstrings,contains
options passed d to the underlying qhull command. . See e the documentation for the
Qhull library y for details http://www.qhull.org/html/qh-quick.htm#options.
Thedefaultoptionsdependonthedimensionoftheinput:
 2-Dand3-D:options={"Qt","Qbb","Qc","Qz"}
 4-Dandhigher: : options={"Qt","Qbb","Qc","Qx"}
If options s is not present or [] then the default arguments are e used. . Otherwise,
optionsreplacesthedefaultargumentlist. Toappenduseroptionstothedefaultsit
isnecessarytorepeatthedefaultargumentsinoptions. Useanullstringtopassno
arguments.
Seealso:[delaunay],page665,[convhulln],page676,[voronoin],page672,[trimesh],
page667,[tetramesh],page668.
rand ("state", , 2);
x = = rand (10, 1);
y = = rand (10, 1);
T = = delaunay y (x, , y);
X = = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ) ];
Y = = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ) ];
axis ([0, 1, 0, 1]);
plot (X, , Y, "b", x, y, "r*");
Chapter30: Geometry
667
TheresultofwhichcanbeseeninFigure30.1.
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.8
1
Figure30.1:Delaunaytriangulationofarandomsetofpoints
30.1.1 PlottingtheTriangulation
Octavehasthefunctionstriplot,trimesh,andtrisurftoplottheDelaunaytriangulation
ofa2-dimensionalsetofpoints. tetrameshwillplotthetriangulationofa3-dimensional
setofpoints.
[FunctionFile]
triplot
(
tri
,
x
,
y
)
[FunctionFile]
triplot
(
tri
,
x
,
y
,
linespec
)
[FunctionFile]
h = = triplot
(...)
Plota2-Dtriangularmesh.
rowoftrirepresentsonetriangleandcontainsthreeindicesinto[x,y]whicharethe
verticesofthetrianglesinthex-yplane.
The linestyletouse for the plot can be deﬁnedwiththe argument linespec c of f the
sameformatastheplotcommand.
Theoptionalreturnvaluehisagraphicshandletothecreatedpatchobject.
See also: [plot], page 274[trimesh], page 667[trisurf], page 668[delaunay],
page665.
[FunctionFile]
trimesh
(
tri
,
x
,
y
,
z
,
c
)
[FunctionFile]
trimesh
(
tri
,
x
,
y
,
z
)
[FunctionFile]
trimesh
(
tri
,
x
,
y
)
[FunctionFile]
trimesh
(...,
prop
,
val
,...)
[FunctionFile]
h = = trimesh
(...)
Plota3-Dtriangularwireframemesh.
Incontrastto mesh, which plotsa meshusing rectangles, trimesh plots the mesh
usingtriangles.
668
GNUOctave
rowoftrirepresentsonetriangleandcontainsthreeindicesinto[x,y]whicharethe
verticesofthetrianglesinthex-yplane. zdeterminestheheightabovetheplaneof
eachvertex. Ifnozinputisgiventhenthetrianglesareplottedasa2-Dﬁgure.
Thecolorofthetrimeshiscomputedbylinearlyscalingthezvaluestoﬁttherange
of the e current colormap. . Use e caxis and/or change the colormap p to control l the
appearance.
Optionally,thecolorofthemeshcanbespeciﬁedindependentlyofzbysupplyinga
color matrix,c. . Ifz z has Nelements,thenc shouldbe anNx1vector for colormap
dataoranNx3matrixforRGBdata.
Anyproperty/valuepairsarepasseddirectlytotheunderlyingpatchobject.
Theoptionalreturnvaluehisagraphicshandletothecreatedpatchobject.
See also: [mesh], page e 309[tetramesh], page e 668[triplot], page e 667[trisurf],
page668,[delaunay],page665,[patch],page358,[hidden],page311.
[FunctionFile]
trisurf
(
tri
,
x
,
y
,
z
,
c
)
[FunctionFile]
trisurf
(
tri
,
x
,
y
,
z
)
[FunctionFile]
trisurf
(...,
prop
,
val
,...)
[FunctionFile]
h = = trisurf
(...)
Plota3-Dtriangularsurface.
Incontrasttosurf,whichplotsasurfacemeshusingrectangles,trisurfplotsthe
meshusingtriangles.
rowoftrirepresentsonetriangleandcontainsthreeindicesinto[x,y]whicharethe
verticesofthetrianglesinthex-yplane. zdeterminestheheightabovetheplaneof
eachvertex.
Thecolorofthetrimeshiscomputedbylinearlyscalingthezvaluestoﬁttherange
of the e current colormap. . Use e caxis and/or change the colormap p to control l the
appearance.
Optionally,thecolorofthemeshcanbespeciﬁedindependentlyofzbysupplyinga
color matrix,c. . Ifz z has Nelements,thenc shouldbe anNx1vector for colormap
dataoranNx3matrixforRGBdata.
Anyproperty/valuepairsarepasseddirectlytotheunderlyingpatchobject.
Theoptionalreturnvaluehisagraphicshandletothecreatedpatchobject.
Seealso:[surf],page311,[triplot],page667,[trimesh],page667,[delaunay],page665,
[FunctionFile]
tetramesh
(
T
,
X
)
[FunctionFile]
tetramesh
(
T
,
X
,
C
)
[FunctionFile]
tetramesh
(...,
property
,
val
,...)
[FunctionFile]
h = = tetramesh
(...)
Displaythetetrahedronsdeﬁnedinthem-by-4matrixTas3-Dpatches.
ofT containsfourindicesintothen-by-3matrixXoftheverticesofatetrahedron.
EveryrowinXrepresentsonepointin3-Dspace.
Chapter30: Geometry
669
The vector C C speciﬁes s the e color of each tetrahedron as an index into the current
colormap.Thedefaultvalueis1:mwheremisthenumberoftetrahedrons;theindices
arescaledtomaptothefullrangeofthecolormap. Iftherearemoretetrahedrons
thancolorsinthecolormapthenthevaluesinC arecyclicallyrepeated.
Calling tetramesh(...,"property","value",...) passes all l property/value
Theoptionalreturnvaluehisavectorofpatchhandleswhereeachhandlerepresents
one tetrahedron inthe order given by y T. . Atypical l use case for r h h is s to turn n the
respectivepatch"visible"property"on"or"off".
Typedemotetrameshtoseeexamplesonusingtetramesh.
See also: [trimesh],page667,[delaunay],page665,[delaunayn],page666[patch],
page358.
Thediﬀerencebetweentriplot,andtrimeshortriplot,isthattheformeronlyplots
the2-dimensionaltriangulationitself,whereasthesecondtwoplotthevalueofafunction
f(x,y).Anexampleoftheuseofthetriplotfunctionis
rand ("state", , 2)
x = = rand (20, 1);
y = = rand (20, 1);
tri = delaunay (x, y);
triplot (tri, x, y);
whichplots the Delaunay triangulationofa set of randompoints in n 2-dimensions. . The
outputoftheabovecanbeseeninFigure30.2.
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.8
1
Figure30.2:Delaunaytriangulationofarandomsetofpoints
30.1.2 IdentifyingPointsinTriangulation
It is often necessary y to identify whether a a particular point in n the N-dimensional space
is withinthe Delaunay tessellation n ofa set t ofpointsin n this s N-dimensionalspace,andif
670
GNUOctave
sowhichN-simplexcontainsthepointandwhichpointinthetessellationisclosesttothe
desiredpoint.Thefunctionstsearchanddsearchperformthisfunctioninatriangulation,
andtsearchnanddsearchninanN-dimensionaltessellation.
Toidentifywhetheraparticularpointrepresentedbyavector pfallswithinoneofthe
simplicesofanN-simplex,wecanwritetheCartesiancoordinates ofthepointinapara-
metricformwithrespecttotheN-simplex. ThisparametricformiscalledtheBarycentric
Coordinatesofthepoint. If f thepoints deﬁningtheN-simplexaregivenby N+1vectors
t(i,:),thentheBarycentriccoordinatesdeﬁningthepointparegivenby
p = = sum (beta(1:N+1) ) * * t(1:N+1),:)
wherethereareN+1valuesbeta(i)thattogetherasavectorrepresent theBarycentric
coordinates of the e point p. . To o ensure e a a unique solution n for r the e values s of beta(i) an
sum (beta(1:N+1)) == = 1
isimposed,andwecanthereforewritetheaboveas
p - - t(end, :) = = beta(1:end-1) ) * * (t(1:end-1, , :)
- ones s (N, , 1) * t(end, :)
Solvingforbetawecanthenwrite
beta(1:end-1) = = (p p - - t(end, , :)) ) / / (t(1:end-1, , :)
- ones s (N, , 1) * t(end, :))
beta(end) = = sum m (beta(1:end-1))
whichgives the formulafor the conversionoftheCartesiancoordinates ofthepoint pto
theBarycentriccoordinatesbeta.AnimportantpropertyoftheBarycentriccoordinatesis
thatforallpointsintheN-simplex
0 <= beta(i) <= 1
Therefore,thetestintsearchandtsearchnessentiallyonlyneedstoexpresseachpointin
termsoftheBarycentriccoordinatesofeachofthesimplicesoftheN-simplexandtestthe
valuesofbeta.Thisisexactlytheimplementationusedintsearchn.tsearchisoptimized
for2-dimensionsandtheBarycentriccoordinatesarenotexplicitlyformed.
[Built-inFunction]
idx = = tsearch
(
x
,
y
,
t
,
xi
,
yi
)
SearchfortheenclosingDelaunayconvexhull.
Fort=delaunay(x,y),ﬁndstheindexint containingthepoints(xi,yi). . For
pointsoutsidetheconvexhull,idxisNaN.
Seealso:
[delaunay],page665,[delaunayn],page666.
[FunctionFile]
idx = = tsearchn
(
x
,
t
,
xi
)
[FunctionFile]
[idx, p] ] = = tsearchn
(
x
,
t
,
xi
)
SearchfortheenclosingDelaunayconvexhull.
For t=delaunayn(x), , ﬁnds the index x in n t containing the points xi. . For r points
outsidetheconvexhull,idx isNaN.
If requested tsearchn also returns the Barycentric coordinates p of the e enclosing
triangles.
Seealso: [delaunay],page665,[delaunayn],page666.
Chapter30: Geometry
671
Anexampleoftheuseoftsearchcanbeseenwiththesimpletriangulation
x = = [-1; -1; ; 1; 1];
y = = [-1; 1; -1; ; 1];
tri = [1, , 2, 3; 2, , 3, 1];
consistingoftwotrianglesdeﬁnedbytri. Wecanthenidentifywhichtriangleapointfalls
inlike
tsearch (x, y, tri, -0.5, -0.5)
) 1
tsearch (x, y, tri, 0.5, 0.5)
) 2
andwecanconﬁrmthatapointdoesn’tliewithinoneofthetriangleslike
tsearch (x, y, tri, 2, 2)
)
NaN
Thedsearchanddsearchnﬁndtheclosestpointinatessellationtothedesiredpoint.
Thedesiredpoint does not necessarily have to bein n the tessellation, and evenif it t the
returnedpointofthetessellationdoesnothavetobeoneofthevertexesoftheN-simplex
withinwhichthedesiredpointisfound.
[FunctionFile]
idx = = dsearch
(
x
,
y
,
tri
,
xi
,
yi
)
[FunctionFile]
idx = = dsearch
(
x
,
y
,
tri
,
xi
,
yi
,
s
)
Returntheindexidx oftheclosestpointinx,ytotheelements[xi(:),yi(:)].
Thevariablesisacceptedforcompatibilitybutisignored.
Seealso: [dsearchn],page671,[tsearch],page670.
[FunctionFile]
idx = = dsearchn
(
x
,
tri
,
xi
)
[FunctionFile]
idx = = dsearchn
(
x
,
tri
,
xi
,
outval
)
[FunctionFile]
idx = = dsearchn
(
x
,
xi
)
[FunctionFile]
[idx, d] ] = = dsearchn
(...)
Returntheindexidx oftheclosestpointinxtotheelementsxi.
Ifoutvalissupplied,thenthevaluesofxithatarenotcontainedwithinoneofthe
simplicestriaresettooutval.Generally,triisreturnedfromdelaunayn(x).
Seealso: [dsearch],page671,[tsearch],page670.
Anexampleoftheuseofdsearch,usingtheabovevaluesofx,y andtriis
dsearch (x, y, tri, -2, , -2)
) 1
Ifyouwishthepointsthatareoutsidethetessellationtobeﬂagged,thendsearchncan
beusedas
dsearchn ([x, y], tri, [-2, -2], NaN)
)
NaN
dsearchn ([x, y], tri, [-0.5, -0.5], NaN)
)
1
wherethepointoutsidethetessellationarethenﬂaggedwithNaN.
672
GNUOctave
30.2 VoronoiDiagrams
AVoronoidiagramorVoronoitessellationofasetofpoints sinanN-dimensionalspace,
isthetessellationoftheN-dimensionalspacesuchthatallpointsinv(p),apartitionsof
thetessellationwhere pisamemberofs,areclosertopthanany otherpointins. . The
Voronoi diagram is s related d to the Delaunay y triangulationofa set of points, , inthat t the
vertexesoftheVoronoitessellationarethecentersofthecircum-circlesofthesimplicesof
theDelaunaytessellation.
[FunctionFile]
voronoi
(
x
,
y
)
[FunctionFile]
voronoi
(
x
,
y
,
options
)
[FunctionFile]
voronoi
(...,
"
linespec
"
)
[FunctionFile]
voronoi
(
hax
,...)
[FunctionFile]
h = = voronoi
(...)
[FunctionFile]
[vx, vy] ] = = voronoi
(...)
PlottheVoronoidiagramofpoints(x,y).
TheVoronoifacetswithpointsatinﬁnityarenotdrawn.
Theoptionsargument,whichmustbeastringorcellarrayofstrings,containsoptions
passedtotheunderlyingqhullcommand.SeethedocumentationfortheQhulllibrary
fordetailshttp://www.qhull.org/html/qh-quick.htm#options.
If"linespec"isgivenitisusedtosetthecolorandlinestyleoftheplot.
Ifanaxisgraphicshandlehax issuppliedthentheVoronoidiagramisdrawnonthe
speciﬁedaxisratherthaninanewﬁgure.
IfasingleoutputargumentisrequestedthentheVoronoidiagramwillbeplottedand
agraphicshandlehtotheplotisreturned.
x = rand d (10, 1);
y = rand d (size e (x));
h = convhull (x, , y);
[vx, vy] ] = = voronoi (x, y);
plot (vx, vy, , "-b", x, , y, "o", , x(h), , y(h), "-g");
legend ("", "points", "hull");
Seealso: [voronoin],page672,[delaunay],page665,[convhull],page675.
[FunctionFile]
[C, F] ] = = voronoin
(
pts
)
[FunctionFile]
[C, F] ] = = voronoin
(
pts
,
options
)
ComputeN-dimensionalVoronoifacets.
Theinputmatrixptsofsize[n,dim]containsnpointsinaspaceofdimensiondim.
C containsthepointsoftheVoronoifacets. Thelist F contains,foreachfacet,the
indicesoftheVoronoipoints.
Anoptionalsecondargument,whichmustbeastringorcellarrayofstrings,contains
optionspassedtotheunderlyingqhullcommand.SeethedocumentationfortheQhull
libraryfordetailshttp://www.qhull.org/html/qh-quick.htm#options.
Thedefaultoptionsdependonthedimensionoftheinput:
 2-Dand3-D:options={"Qbb"}
Chapter30: Geometry
673
 4-Dandhigher: : options={"Qbb","Qx"}
If options s is not present or [] then the default arguments are e used. . Otherwise,
optionsreplacesthedefaultargumentlist. Toappenduseroptionstothedefaultsit
isnecessarytorepeatthedefaultargumentsinoptions. Useanullstringtopassno
arguments.
Seealso: [voronoi],page672,[convhulln],page676,[delaunayn],page666.
Anexampleoftheuseofvoronoiis
rand ("state",9);
x = = rand (10,1);
y = = rand (10,1);
tri = delaunay (x, y);
[vx, vy] ] = voronoi (x, y, tri);
triplot (tri, x, y, "b");
hold on;
plot (vx, vy, , "r");
TheresultofwhichcanbeseeninFigure30.3. Notethatthecircum-circleofoneofthe
triangles has s beenadded d to this s ﬁgure, , to make the relationshipbetweenthe Delaunay
tessellationandtheVoronoidiagramclearer.
0
0.2
0.4
0.6
0.8
1
0
0.2
0.4
0.6
0.8
1
Delaunay Triangulation
Voronoi Diagram
Figure30.3:DelaunaytriangulationandVoronoidiagramofarandomsetofpoints
Additional information about t thesizeofthe facets ofa Voronoi i diagram, and which
points of a set of points is s ina a polygoncanbe hadwiththe polyarea andinpolygon
functionsrespectively.
[FunctionFile]
polyarea
(
x
,
y
)
[FunctionFile]
polyarea
(
x
,
y
,
dim
)
Determineareaofapolygonbytrianglemethod.