(* ::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.                                                         *)
(************************************************************************)



(* ::Input::Initialization:: *)
SetDirectory["C:/drorbn/AcademicPensieve/Classes/25-1301-AlgebraicTopology/"];
SaveImage[fname_String, img_] := Export[fname,
ImageCrop[Rasterize[img, ImageSize -> {1600, 1600}]]
];


(* ::Input::Initialization:: *)
del[s_Simplex] := Table[
Delete[s, i],
{i, Length[s]}
];
del[expr_] := expr /. s_Simplex :> del[s];
cone[a_, s_Simplex] := Prepend[s, a];
cone[a_, expr_] := expr /. s_Simplex :> cone[a, s];
B[Simplex[v_]] := Simplex[v];
B[s_Simplex] := cone[Expand[Mean[List @@ s]], B[del[s]]];
B[expr_] := expr /. s_Simplex :> B[s];


(* ::Input::Initialization:: *)
Draw2D[ss_] := Module[
{rule, mat},
rule = Thread[{e0,e1,e2} -> ({
 {1, 0, 0},
 {0, 1, 0},
 {0, 0, 1}
})];
mat=Drop[Orthogonalize[({
 {1, 1, 1},
 {0, 1, 0},
 {0, 0, 1}
})], 1];
Graphics[ss /. s_Simplex :> {
RGBColor[Random[], Random[], Random[]],
Polygon[mat . (# /.rule)& /@ List @@ s]
}]
]


(* ::Input::Initialization:: *)
Draw3D[ss_,opts___] := Module[
{rule, mat, z, r, t},
mat=IdentityMatrix[4];
rule = Thread[{e0,e1,e2, e3} -> mat];
mat=Drop[Orthogonalize[ReplacePart[mat, {1,1,1,1}, 1]], 1];
z=2Random[]-1; r=Sqrt[1-z^2];
t = 2Pi Random[];
Graphics3D[{
 Opacity[0.5],
Union[Flatten[ss]] /. s_Simplex :> {
Hue[Random[]],
Polygon[mat . (# /.rule)& /@ List @@ s]
}
},
Boxed -> False, ViewPoint -> 3{r Cos[t], r Sin[t], z},opts
]
]


(* ::Input::Initialization:: *)
{f0,f1,f2} = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
{g0, g1, g2} = {{1,0,0,3}, {0,1,0,3}, {0,0,1,3}};


(* ::Input::Initialization:: *)
ShrinkTo[p_, s_Simplex] := Module[
{b=(1-p)Mean[List @@s]},
Expand[p #+b]& /@ s
];
ShrinkTo[p_, expr_] := expr /. s_Simplex :> ShrinkTo[p, s]



