(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



Needs["ComputationalGeometry`"]
AdjacentTriangles[ i_,AdjListIn_,IgnoreIn_]:=Module[
{j,k,p,AdjList,Triangles},
{p,AdjList}=AdjListIn[[i]];
AdjList=Complement[AdjList,IgnoreIn]; 
Triangles=AdjListIn[[AdjList,2]];
Triangles=Map[Intersection[AdjList,#]&,Triangles,{1}];
Union[
Flatten[
Table[
Table[
Sort[{p,AdjList[[j]],Triangles[[j]][[k]]}],
{k,Length[Triangles[[j]]]}],
{j, Length[Triangles]}
],
1]
]
]


Needs["ComputationalGeometry`"]
AdjacencyListToTriangles[ AdjListIn_]:=Module[
{i,CompletedVertices,Temp},
CompletedVertices={};
Temp=Table[
CompletedVertices=Append[CompletedVertices,i];
AdjacentTriangles[i,AdjListIn,CompletedVertices],
{i,Length[AdjListIn]}
];
Apply[Union,Temp]
]


Clear[CheckTrianglePlot,InPoints]
CheckTrianglePlot[InPoints_]:=Module[
{MyTriang,MyPic,
p1,p2,p3,
i},
MyTriang=AdjacencyListToTriangles[DelaunayTriangulation[InPoints]];
MyPic=Table[
{p1,p2,p3}=Part[InPoints,MyTriang[[i]]];
{Hue[i/Length[MyTriang]],Polygon[{p1,p2,p3}]},
{i, Length[MyTriang]}
];
Show[
Graphics[MyPic],
PlanarGraphPlot[InPoints,
Frame->True],
Frame->True
]
]


Clear[FromRef]
FromRef[P_,{p1_,p2_,p3_}]:= Module[
{A,p},
p=p1;
A=Transpose[{p3-p,p2-p}];
A.P+p
]


Clear[Jac]
Jac[{p1_,p2_,p3_}]:= Module[
{A},
A=Transpose[{p3-p1,p2-p1}];
Det[A]
]


Clear[RefSlab,TriangulationSlab]
RefSlab[{X_,Y_}]:=If[0<X<1\[And]0<Y<1-X,(1-X-Y)]
TriangulationSlab[P_,{p1_,p2_,p3_}]:=Append[FromRef[P,{p1,p2,p3}],RefSlab[P]]


XR[S_,\[Theta]_]:= S/(1+Tan[\[Theta]]);
YR[S_,\[Theta]_]:= S Tan[\[Theta]]/(1+Tan[\[Theta]])



