Torus Homology Examples

MATH 348 Topology

Computing boundary matrices of a simplicial complex

The following function computes the boundary matrix for a given simplicial complex in the specified dimension. The simplicial complex must be supplied as a MeshRegion.

boundaryMatrix[complex_,dimension_]:=Module[
(* local variables *)
{simplices, faces,matrix, row, col},

(* get lists of simplices of the appropriate dimensions *)
simplices=MeshCells[complex,dimension];
faces=Table[If[dimension==1,{face[[1]]},Sort[face[[1]]]],{face,MeshCells[complex,dimension-1]}];

(* initialize a zero matrix *)
matrix=Table[0,Length[faces],Length[simplices]];

(* set entries in the matrix *)
col=1;
Do[
Do[
row=Position[faces,Sort[r]][[1,1]];
matrix[[row,col]]=1,
{r,Subsets[simp[[1]],{dimension}]}];
col+=1
,
{simp, simplices}];

(* return the matrix *)
matrix
]

Hexagonal Torus

(* generate a triangulation of a square *)
div=3;
squareMesh=DelaunayMesh[Flatten[Table[{u,v},{u,0,2 Pi,Pi/div},{v,0,2 Pi,Pi/div}],1]];

(* function to map a square onto a torus *)
r1=3;r2=1;
torusMap[{u_,v_}]:={(r1+r2 Cos[v]) Cos[u],(r1+r2 Cos[v]) Sin[u],r2 Sin[v]}

(* module to convert a square mesh into a toroidial mesh *)
makeTorus[mesh_]:=Module[
{r1=3,r2=1,
coords={},newP,oldP,newInd,indList,
points, lines={}, polygons={},
cells={}},

(* map points onto torus *)
Do[
newP=torusMap[p];
If[!MemberQ[coords,newP],AppendTo[coords,newP]],
{p,MeshCoordinates[mesh]}];

(* update simplices to the new coordinate indexes *) 
points=Table[Point[i],{i,Length[coords]}];
Do[
indList={};
Do[
oldP=MeshCoordinates[mesh][[ind]];
newInd=Position[coords,torusMap[oldP]][[1,1]];
AppendTo[indList,newInd],
{ind,edge[[1]]}];
AppendTo[lines,Line[indList]],
{edge,MeshCells[mesh,1]}];
Do[
indList={};
Do[
oldP=MeshCoordinates[mesh][[ind]];
newInd=Position[coords,torusMap[oldP]][[1,1]];
AppendTo[indList,newInd],
{ind,edge[[1]]}];
AppendTo[polygons,Polygon[indList]],
{edge,MeshCells[mesh,2]}];

(* return the MeshRegion *) 
MeshRegion[coords,{points,lines,polygons}]
]

(* now generate a torus *)
torus1=makeTorus[squareMesh]

0th homology: (Subscript[β, 0])=(number of vertices)-rank((Subscript[δ, 1]))

1st homology: (Subscript[β, 1])=nullity((Subscript[δ, 1]))-rank((Subscript[δ, 2]))

2nd homology: (Subscript[β, 2])=nullity((Subscript[δ, 2]))-rank((Subscript[δ, 3]))

Random Triangulated Torus

div=10;
randomPoints=400;
padding=1/10;
newPoints=Union[Flatten[Table[{u,v},{u,0,2 Pi,Pi/div},{v,{0,2 Pi}}],1],Flatten[Table[{v,u},{u,0,2 Pi,Pi/div},{v,{0,2 Pi}}],1],RandomReal[{padding,2Pi-padding},{randomPoints,2}]];
(*borderPoints=DeleteDuplicates[Flatten[Table[{{u,v},{v,u}},{u,0,2 Pi,Pi/div},{v,{0,2 Pi}}],2]];*)
mesh2=DelaunayMesh[newPoints];
torus2=makeTorus[mesh2]

0th homology: (Subscript[β, 0])=(number of vertices)-rank((Subscript[δ, 1]))

1st homology: (Subscript[β, 1])=nullity((Subscript[δ, 1]))-rank((Subscript[δ, 2]))

2nd homology: (Subscript[β, 2])=nullity((Subscript[δ, 2]))-rank((Subscript[δ, 3]))

Random Points on a Torus

numPoints=500;
torusPoints=torusMap /@RandomReal[{0,2Pi},{numPoints,2}];
ListPointPlot3D[torusPoints]