Cell[CellGroupData[{Cell[BoxData[ RowBox[{ RowBox[{"(*", RowBox[{ "This", " ", "generates", " ", "the", " ", "visible", " ", "region", " ", "seen", " ", "by", " ", "a", " ", "point", " ", "at", " ", "pm", " ", "in", " ", "an", " ", "environment", " ", "with", " ", "the", " ", "polygons", " ", "in", " ", RowBox[{"polys", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"visiblePolys", "[", RowBox[{"polys_", ",", RowBox[{"pm", ":", RowBox[{"{", RowBox[{"x_", ",", "y_"}], "}"}]}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"p", ",", "listofAllLines", ",", "infiniteLine", ",", RowBox[{"length", "=", RowBox[{"Length", "@", "polys"}]}], ",", "orderedList", ",", "sortedList", ",", RowBox[{"jList", "=", RowBox[{"{", "}"}]}], ",", RowBox[{"visibleList", "=", RowBox[{"{", "}"}]}], ",", RowBox[{"wi", "=", "False"}], ",", RowBox[{"wip", "=", "False"}], ",", "lvLine", ",", "a", ",", "b", ",", "c", ",", "abcList", ",", "ba", ",", "bc", ",", "pb", ",", "pbaAngle", ",", "pbcAngle", ",", "startJlistInt", ",", "m", ",", "bcVisiInt", ",", "gLine", ",", "giList", ",", "giPoint", ",", "giLine", ",", "abNotGlaInt", ",", "abNotVisInt", ",", "bcNotVisInt", ",", RowBox[{"i", "=", "1"}], ",", "prevA", ",", "prevB", ",", "prevC", ",", "postA", ",", "postB", ",", "postC", ",", "tb", ",", "index", ",", "theta", ",", RowBox[{"gFlag", "=", "False"}], ",", "pprevbAngle", ",", "pbAngle"}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "Check", " ", "if", " ", "point", " ", "p", " ", "lies", " ", "on", " ", "any", " ", "of", " ", "the", " ", "lines", " ", "in", " ", "the", " ", "environment"}], ",", " ", RowBox[{ "if", " ", "so", " ", "then", " ", "shift", " ", "it", " ", "by", " ", "a", " ", "very", " ", "small", " ", RowBox[{"offset", "."}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"p", "=", "pm"}], ";", "\[IndentingNewLine]", RowBox[{"Table", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"(", RowBox[{"pointOnSegmentQ", "[", RowBox[{"#", ",", "pm"}], "]"}], ")"}], ",", RowBox[{"p", "=", RowBox[{"pm", "-", RowBox[{"0.00001", RowBox[{"normalVector", "[", "#", "]"}]}]}]}]}], "]"}], "&"}], "/@", RowBox[{"(", RowBox[{"lineList", "@", RowBox[{ "polys", "\[LeftDoubleBracket]", "k", "\[RightDoubleBracket]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", "length"}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "Check", " ", "if", " ", "point", " ", "p", " ", "lies", " ", "on", " ", "any", " ", "of", " ", "the", " ", "vertices", " ", "of", " ", "the", " ", "polygons", " ", "in", " ", "the", " ", "environment"}], ",", " ", RowBox[{ "if", " ", "so", " ", "then", " ", "shift", " ", "it", " ", "by", " ", "a", " ", "very", " ", "small", " ", RowBox[{"offset", "."}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Or", "@@", RowBox[{"Table", "[", RowBox[{ RowBox[{"Or", "@@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"index", "=", RowBox[{"Flatten", "@", RowBox[{"Position", "[", RowBox[{ RowBox[{ "polys", "\[LeftDoubleBracket]", "k", "\[RightDoubleBracket]"}], ",", "#"}], "]"}]}]}], ";", RowBox[{"pm", "\[Equal]", "#"}]}], ")"}], "&"}], "/@", RowBox[{ "polys", "\[LeftDoubleBracket]", "k", "\[RightDoubleBracket]"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"k", ",", "1", ",", "length"}], "}"}]}], "]"}]}], ",", RowBox[{"p", "=", RowBox[{"pm", "+", " ", RowBox[{"0.00001", RowBox[{"(", RowBox[{ RowBox[{"Flatten", "@", RowBox[{"polys", "\[LeftDoubleBracket]", RowBox[{"1", ",", RowBox[{"index", "-", "1"}]}], "\[RightDoubleBracket]"}]}], "+", RowBox[{"Flatten", "@", RowBox[{"polys", "\[LeftDoubleBracket]", RowBox[{"1", ",", RowBox[{"index", "+", "1"}]}], "\[RightDoubleBracket]"}]}]}], ")"}]}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "get", " ", "a", " ", "line", " ", "parallel", " ", "to", " ", "x", " ", "axis"}], "*)"}], "\[IndentingNewLine]", RowBox[{"infiniteLine", "=", RowBox[{"{", RowBox[{"p", ",", RowBox[{ RowBox[{"{", RowBox[{"0.11", ",", "0"}], "}"}], "+", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"MaximalBy", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{"polys", ",", "1"}], "]"}], ",", "First"}], "]"}], "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], ",", "y"}], "}"}]}]}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "reverse", " ", "the", " ", "order", " ", "of", " ", "the", " ", "list", " ", "representing", " ", "a", " ", "polygon", " ", "if", " ", "point", " ", "p", " ", "is", " ", "inside", " ", "the", " ", "polygon"}], "*)"}], "\[IndentingNewLine]", RowBox[{"orderedList", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"testpoint", "[", RowBox[{ RowBox[{ "polys", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", "p"}], "]"}], ",", RowBox[{"Reverse", "@", RowBox[{ "polys", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], ",", RowBox[{ "polys", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "@", "polys"}], ",", "1"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "make", " ", "a", " ", "list", " ", "of", " ", "all", " ", "lines"}], "*)"}], "\[IndentingNewLine]", RowBox[{"listofAllLines", "=", RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"lineList", "@", "#"}], ")"}], "&"}], "/@", "orderedList"}], "]"}], ",", "1"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "sort", " ", "the", " ", "lines", " ", "based", " ", "on", " ", "the", " ", "angle", " ", RowBox[{"w", ".", "r", ".", "t"}], " ", "to", " ", "point", " ", "p"}], "*)"}], "\[IndentingNewLine]", RowBox[{"sortedList", "=", RowBox[{"Sort", "[", RowBox[{ RowBox[{"Flatten", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"vertexList", "@", RowBox[{"N", "@", "#"}]}], ")"}], "&"}], "/@", "orderedList"}], "]"}], ",", "1"}], "]"}], ",", RowBox[{ RowBox[{"angleSortCond", "[", RowBox[{"p", ",", "#1", ",", "#2"}], "]"}], " ", "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "number", " ", "of", " ", "vertices", " ", "in", " ", "the", " ", "environment"}], "*)"}], "\[IndentingNewLine]", RowBox[{"m", "=", RowBox[{"Length", "@", "sortedList"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "get", " ", "the", " ", "intersection", " ", "of", " ", "lines", " ", "for", " ", "the", " ", "infiniteLine"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"infiniteLine", ",", "#"}], "}"}], "]"}], ",", RowBox[{"AppendTo", "[", RowBox[{"jList", ",", RowBox[{"Reverse", "@", "#"}]}], "]"}]}], "]"}], "&"}], "/@", "listofAllLines"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "store", " ", "the", " ", "sorted", " ", "values", " ", "in", " ", "jList"}], "*)"}], "\[IndentingNewLine]", RowBox[{"jList", "=", RowBox[{"Sort", "[", RowBox[{"jList", ",", RowBox[{ RowBox[{"distSortCond", "[", RowBox[{"infiniteLine", ",", "#1", ",", "#2", ",", "p"}], "]"}], "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"lvLine", "=", RowBox[{"First", "@", "jList"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "find", " ", "the", " ", "line", " ", "which", " ", "is", " ", "closest", " ", "and", " ", "also", " ", "visible"}], "*)"}], "\[IndentingNewLine]", RowBox[{"Table", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"lvLine", ",", RowBox[{ "jList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"startJlistInt", "=", RowBox[{"N", "@", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"lvLine", ",", RowBox[{ "jList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "}"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{ "p", ",", "startJlistInt", ",", "listofAllLines"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", "startJlistInt"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ "startJlistInt", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ">", RowBox[{ "p", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ",", RowBox[{"lvLine", "=", RowBox[{ "jList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}]}], "]"}]}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "@", "jList"}]}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "loop", " ", "around", " ", "all", " ", "the", " ", "vertices", " ", "of", " ", "all", " ", "the", " ", "polygons"}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", "=", "1"}], ",", RowBox[{"i", "\[LessEqual]", " ", "m"}], ",", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "intialize", " ", "all", " ", "the", " ", "variables"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"a", ",", "b", ",", "c"}], "}"}], "=", RowBox[{"sortedList", "\[LeftDoubleBracket]", RowBox[{"i", ",", RowBox[{"1", ";;", "3"}]}], "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"prevA", ",", "prevB", ",", "prevC"}], "}"}], "=", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[NotEqual]", " ", "1"}], ",", RowBox[{"sortedList", "\[LeftDoubleBracket]", RowBox[{ RowBox[{"i", "-", "1"}], ",", RowBox[{"1", ";;", "3"}]}], "\[RightDoubleBracket]"}], ",", RowBox[{"sortedList", "\[LeftDoubleBracket]", RowBox[{"m", ",", RowBox[{"1", ";;", "3"}]}], "\[RightDoubleBracket]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"postA", ",", "postB", ",", "postC"}], "}"}], "=", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[NotEqual]", " ", "m"}], ",", RowBox[{"sortedList", "\[LeftDoubleBracket]", RowBox[{ RowBox[{"i", "+", "1"}], ",", RowBox[{"1", ";;", "3"}]}], "\[RightDoubleBracket]"}], ",", RowBox[{"sortedList", "\[LeftDoubleBracket]", RowBox[{"1", ",", RowBox[{"1", ";;", "3"}]}], "\[RightDoubleBracket]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"pbAngle", "=", RowBox[{"getAngle", "[", RowBox[{"{", RowBox[{"p", ",", "b"}], "}"}], "]"}]}], ";", RowBox[{"pprevbAngle", "=", RowBox[{"getAngle", "[", RowBox[{"{", RowBox[{"p", ",", "prevB"}], "}"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "for", " ", "collinearity", " ", "between", " ", "current", " ", "vertice"}], ",", " ", RowBox[{ RowBox[{ "next", " ", "vertex", " ", "and", " ", "point", " ", "p", " ", "then", " ", "make", " ", "them", " ", "non"}], "-", "collinear"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"tb", "=", RowBox[{"N", "@", RowBox[{"If", "[", RowBox[{ RowBox[{"pointOnSegmentQ", "[", RowBox[{ RowBox[{"{", RowBox[{"p", ",", "postB"}], "}"}], ",", "b"}], "]"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"postB", "\[Equal]", " ", "a"}], "||", RowBox[{"pbaAngle", " ", "\[LessEqual]", RowBox[{"Pi", "/", "3"}]}]}], ",", RowBox[{"b", "+", RowBox[{"0.00001", RowBox[{"normalVector", "[", RowBox[{"{", RowBox[{"a", ",", "p"}], "}"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"b", "-", RowBox[{"0.00001", RowBox[{"normalVector", "[", RowBox[{"{", RowBox[{"postB", ",", "p"}], "}"}], "]"}]}]}]}], "]"}], ",", "b"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "get", " ", "all", " ", "the", " ", "angles", " ", "and", " ", "the", " ", "lists"}], "*)"}], "\[IndentingNewLine]", RowBox[{"abcList", "=", RowBox[{"{", RowBox[{"a", ",", "tb", ",", "c"}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"ba", "=", RowBox[{"{", RowBox[{"b", ",", "a"}], "}"}]}], ";", RowBox[{"bc", "=", RowBox[{"{", RowBox[{"b", ",", "c"}], "}"}]}], ";", RowBox[{"pb", "=", RowBox[{"{", RowBox[{"p", ",", "b"}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"pbaAngle", "=", RowBox[{"Re", "@", RowBox[{"getClockwiseAngle", "[", RowBox[{"p", ",", "b", ",", "a"}], "]"}]}]}], ";", RowBox[{"pbcAngle", "=", RowBox[{"Re", "@", RowBox[{"getClockwiseAngle", "[", RowBox[{"p", ",", "b", ",", "c"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "conditions", " ", "to", " ", "determine", " ", "whether", " ", "a", " ", "vertex", " ", "is", " ", "visible", " ", "or", " ", "not"}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"intersectInteriorQRev2", "[", RowBox[{"p", ",", "abcList"}], "]"}], ",", RowBox[{"wi", "=", "False"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"i", "\[Equal]", "1"}], " ", "||", RowBox[{"Not", "@", RowBox[{"pointOnSegmentQ", "[", RowBox[{"pb", ",", "a"}], "]"}]}]}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{"p", ",", "b", ",", "jList"}], "]"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"i", "\[NotEqual]", "1"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ "pbAngle", "\[NotEqual]", " ", "pprevbAngle"}], ",", RowBox[{"wi", "=", "True"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"b", "\[Equal]", " ", "prevA"}], " ", "||", " ", RowBox[{"b", "\[Equal]", "prevC"}], " ", "||", " ", RowBox[{"b", "\[Equal]", " ", "postA"}], " ", "||", " ", RowBox[{"b", "\[Equal]", "postC"}], " ", "||", " ", "gFlag"}], ",", RowBox[{"wi", "=", "True"}], ",", RowBox[{"wi", "=", "False"}]}], "]"}]}], "]"}], ",", RowBox[{"wi", "=", "True"}]}], "]"}], ",", RowBox[{"wi", "=", "False"}]}], "]"}], ",", RowBox[{"If", "[", RowBox[{"wip", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{"b", ",", "a", ",", "jList"}], "]"}], ",", RowBox[{"wi", "=", "True"}], ",", RowBox[{"wi", "=", "False"}]}], "]"}], ",", RowBox[{"wi", "=", "False"}]}], "]"}]}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "if", " ", "the", " ", "vertices", " ", "are", " ", "visible"}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{"wi", ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Check", " ", "if", " ", "there", " ", "is", " ", "an", " ", "intersection", " ", "with", " ", "lastest", " ", "visible", " ", "line", " ", "with", " ", "the", " ", "bc", " ", RowBox[{"line", ".", " ", "The"}], " ", "intersection", " ", "is", " ", "appended", " ", "in", " ", "visible", " ", RowBox[{"list", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"lvLine", ",", "bc"}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"bcVisiInt", "=", RowBox[{"N", "@", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"lvLine", ",", "bc"}], "}"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{ "p", ",", "bcVisiInt", ",", "listofAllLines"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", "bcVisiInt"}], "]"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"Glancing", " ", "blow", " ", RowBox[{"condition", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"(", RowBox[{"glancingBlow", "[", RowBox[{"p", ",", "abcList"}], "]"}], ")"}], ",", RowBox[{"gFlag", "=", "False"}], ",", RowBox[{"gFlag", "=", "True"}]}], " ", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "If", " ", "glancing", " ", "blow", " ", "and", " ", "previous", " ", "vertes", " ", "does", " ", "not", " ", "lie", " ", "on", " ", "the", " ", "line", " ", "pb"}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"gFlag", "&&", RowBox[{"(", RowBox[{"Not", "@", RowBox[{"pointOnSegmentQ", "[", RowBox[{"pb", ",", "prevB"}], "]"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "extend", " ", "the", " ", "glancing", " ", "line", " ", "pb"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"gLine", "=", RowBox[{"extendedLine", "[", RowBox[{"p", ",", "tb"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "check", " ", "for", " ", "intersection", " ", "between", " ", "all", " ", "the", " ", "lines", " ", "in", " ", "Jlist", " ", "and", " ", "the", " ", "extended", " ", RowBox[{"line", ".", " ", "Get"}], " ", "the", " ", "intersection", " ", "point", " ", "nearest", " ", "to", " ", "p"}], "*)"}], "\[IndentingNewLine]", RowBox[{"giList", " ", "=", " ", RowBox[{"Sort", "[", RowBox[{ RowBox[{"(", RowBox[{ "DeleteCases", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"gLine", ",", "#"}], "}"}], "]"}], "||", " ", RowBox[{"And", "[", RowBox[{ RowBox[{"b", "\[NotEqual]", RowBox[{ "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ",", RowBox[{"pointOnSegmentQ", "[", RowBox[{"gLine", ",", RowBox[{ "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "]"}]}], "]"}], "||", " ", RowBox[{"And", "[", RowBox[{ RowBox[{"b", "\[NotEqual]", RowBox[{ "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], ",", RowBox[{"pointOnSegmentQ", "[", RowBox[{"gLine", ",", RowBox[{ "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "]"}]}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"gLine", ",", "#"}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"N", "@", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"gLine", ",", "#"}], "}"}], "]"}]}], ",", "#"}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"And", "[", RowBox[{ RowBox[{"b", "\[NotEqual]", RowBox[{ "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], ",", RowBox[{"pointOnSegmentQ", "[", RowBox[{"gLine", ",", RowBox[{ "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "]"}]}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{ "#", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], ",", "#"}], "}"}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"And", "[", RowBox[{ RowBox[{"b", "\[NotEqual]", RowBox[{ "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], ",", RowBox[{"pointOnSegmentQ", "[", RowBox[{"gLine", ",", RowBox[{ "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "]"}]}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{ "#", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", "#"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "]"}]}], "]"}], "&"}], "/@", RowBox[{"DeleteCases", "[", RowBox[{ RowBox[{"DeleteCases", "[", RowBox[{"listofAllLines", ",", RowBox[{"{", RowBox[{"b", ",", "_"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"_", ",", "b"}], "}"}]}], "]"}]}], "\[IndentingNewLine]", ")"}], ",", "Null"}], "]"}], ")"}], ",", RowBox[{ RowBox[{ RowBox[{"EuclideanDistance", "[", RowBox[{"p", ",", RowBox[{ "#1", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "]"}], "<", " ", RowBox[{"EuclideanDistance", "[", RowBox[{"p", ",", RowBox[{ "#2", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "]"}]}], "&"}]}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"giList", "\[NotEqual]", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "giPoint", " ", "is", " ", "the", " ", "closest", " ", "point", " ", "of", " ", "intersection", " ", "between", " ", "the", " ", "extended", " ", "glancing", " ", "line", " ", "and", " ", "the", " ", "lines", " ", "in", " ", RowBox[{"Jlist", ".", " ", "Where"}], " ", "the", " ", "giLine", " ", "is", " ", "the", " ", "line", " ", "for", " ", "the", " ", "intersection", " ", "point"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"giPoint", "=", RowBox[{"giList", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}]}], ";", RowBox[{"giLine", "=", RowBox[{"giList", "\[LeftDoubleBracket]", RowBox[{"1", ",", "2"}], "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "condition", " ", "to", " ", "decide", " ", "the", " ", "order", " ", "of", " ", "appending", " ", "the", " ", "vertex", " ", "and", " ", "the", " ", "intersection", " ", "point"}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"pointOnSegmentQ", "[", RowBox[{"lvLine", ",", "giPoint"}], "]"}], "&&", " ", RowBox[{ RowBox[{"Chop", "[", RowBox[{"getAngle", "[", "pb", "]"}], "]"}], "\[NotEqual]", " ", "0"}]}], ")"}], "||", RowBox[{"(", RowBox[{ RowBox[{"i", "\[Equal]", "1"}], "&&", RowBox[{"pbaAngle", "\[LessEqual]", " ", RowBox[{"Pi", "/", "2"}]}]}], ")"}], "\[IndentingNewLine]", "||", " ", RowBox[{"(", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"gLine", ",", "lvLine"}], "}"}], "]"}], "&&", " ", RowBox[{"(", RowBox[{ RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"gLine", ",", "lvLine"}], "}"}], "]"}], "\[Equal]", "giPoint"}], ")"}]}], ")"}], "||", RowBox[{"giPoint", "\[Equal]", RowBox[{ "lvLine", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"visibleList", "=", RowBox[{"Join", "[", RowBox[{"visibleList", ",", RowBox[{"{", RowBox[{"giPoint", ",", "b"}], "}"}]}], "]"}]}], ";", RowBox[{"lvLine", "=", "ba"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"visibleList", "=", RowBox[{"Join", "[", RowBox[{"visibleList", ",", RowBox[{"{", RowBox[{"b", ",", "giPoint"}], "}"}]}], "]"}]}], ";", RowBox[{"lvLine", "=", "giLine"}]}]}], "]"}]}]}], "]"}]}], "\[IndentingNewLine]", ",", RowBox[{"(*", RowBox[{ "if", " ", "not", " ", "glancing", " ", "blow", " ", "then", " ", "just", " ", "append", " ", "the", " ", "vertex"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"(", RowBox[{ "pbAngle", "\[NotEqual]", " ", "pprevbAngle"}], " ", ")"}], ",", RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", "b"}], "]"}]}], "]"}], ";", RowBox[{"lvLine", "=", "ba"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Check", " ", "if", " ", "there", " ", "is", " ", "an", " ", "intersection", " ", "with", " ", "any", " ", "line", " ", "in", " ", "Jlist", " ", "with", " ", "line", " ", RowBox[{"ba", ".", " ", "The"}], " ", "intersection", " ", "is", " ", "appended", " ", "in", " ", "visible", " ", RowBox[{"list", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"Table", "[", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"ba", ",", RowBox[{ "jList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"abNotGlaInt", "=", RowBox[{"N", "@", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"ba", ",", RowBox[{ "jList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "}"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{ "p", ",", "abNotGlaInt", ",", "listofAllLines"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", "abNotGlaInt"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"lvLine", "=", RowBox[{ "jList", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}]}]}], "]"}]}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "@", "jList"}], ",", "1"}], "}"}]}], "]"}], ";"}]}], "\[IndentingNewLine]", "]"}]}], RowBox[{"(*", RowBox[{ "If", " ", "it", " ", "is", " ", "not", " ", "a", " ", "visible", " ", "vertex"}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "check", " ", "if", " ", "there", " ", "is", " ", "an", " ", "intersection", " ", "of", " ", "lastest", " ", "visible", " ", "line", " ", "with", " ", "the", " ", "pb", " ", RowBox[{"line", "."}]}], "*)"}], "\[IndentingNewLine]", ",", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"pb", ",", "lvLine"}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "If", " ", "the", " ", "line", " ", "ba", " ", "lies", " ", "on", " ", "the", " ", "left", " ", "side", " ", "of", " ", "line", " ", "pb", " ", "then", " ", "check", " ", "the", " ", "intersection", " ", "of", " ", "line", " ", "ba", " ", "with", " ", "the", " ", "lastest", " ", "visible", " ", RowBox[{"line", ".", " ", "Append"}], " ", "the", " ", "intersection", " ", "in", " ", "visible", " ", RowBox[{"list", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"pbaAngle", "<", "pbcAngle"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "@", RowBox[{"leftOrRight", "[", RowBox[{"p", ",", "b", ",", "a"}], "]"}]}], " ", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"lvLine", ",", "ba"}], "}"}], "]"}], ",", RowBox[{ RowBox[{"abNotVisInt", "=", RowBox[{"N", "@", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"lvLine", ",", "ba"}], "}"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{ "p", ",", "abNotVisInt", ",", "listofAllLines"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", "abNotVisInt"}], "]"}], ";", RowBox[{"lvLine", "=", "ba"}]}]}], "]"}]}]}], "]"}]}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "If", " ", "the", " ", "line", " ", "bc", " ", "lies", " ", "on", " ", "the", " ", "left", " ", "side", " ", "of", " ", "line", " ", "pb", " ", "then", " ", "check", " ", "the", " ", "intersection", " ", "of", " ", "line", " ", "bc", " ", "with", " ", "the", " ", "lastest", " ", "visible", " ", RowBox[{"line", ".", " ", "Append"}], " ", "the", " ", "intersection", " ", "in", " ", "visible", " ", RowBox[{"list", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"pbcAngle", "<", "pbaAngle"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Not", "@", RowBox[{"leftOrRight", "[", RowBox[{"p", ",", "b", ",", "c"}], "]"}]}], ",", RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"lvLine", ",", "bc"}], "}"}], "]"}], ",", RowBox[{ RowBox[{"bcNotVisInt", "=", RowBox[{"N", "@", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"lvLine", ",", "bc"}], "}"}], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{ "p", ",", "bcNotVisInt", ",", "listofAllLines"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", "bcNotVisInt"}], "]"}], ";", RowBox[{"lvLine", "=", "bc"}]}]}], "]"}]}]}], "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", ",", RowBox[{"(*", RowBox[{ "If", " ", "there", " ", "is", " ", "no", " ", "intersection", " ", "of", " ", "lastest", " ", "visible", " ", "line", " ", "with", " ", "the", " ", "pb", " ", "line", " ", "then", " ", "search", " ", "in", " ", "Jlist", " ", "for", " ", "a", " ", "line", " ", "intersecting", " ", "with", " ", "lastest", " ", "visible", " ", "line", " ", "and", " ", "append", " ", "the", " ", "intersection", " ", "in", " ", "visible", " ", RowBox[{"list", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{"#", ",", "lvLine"}], "}"}], "]"}], ",", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"visibleList", ",", RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"#", ",", "lvLine"}], "}"}], "]"}]}], "]"}], ";", RowBox[{"lvLine", "=", "#"}]}]}], "]"}], "&"}], "/@", "jList"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"Update", " ", "the", " ", "Jlist"}], " ", "&"}], " ", "wip"}], "*)"}], "\[IndentingNewLine]", RowBox[{"wip", "=", "wi"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "choose", " ", "a", " ", "line", " ", "to", " ", "be", " ", "added", " ", "in", " ", "Jlist", " ", "if", " ", "the", " ", "line", " ", "is", " ", "in", " ", "the", " ", "counterclockwise", " ", "direction"}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"pbaAngle", "<", "Pi"}], ",", RowBox[{"AppendTo", "[", RowBox[{"jList", ",", "ba"}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"pbcAngle", "<", "Pi"}], ",", RowBox[{"AppendTo", "[", RowBox[{"jList", ",", "bc"}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "remove", " ", "the", " ", "line", " ", "which", " ", "is", " ", "already", " ", "in", " ", "Jlist", " ", "and", " ", "has", " ", "the", " ", "ending", " ", "vertex", " ", "same", " ", "as", " ", "the", " ", "current", " ", "point", " ", "in", " ", "the", " ", "loop"}], "*)"}], "\[IndentingNewLine]", RowBox[{"jList", "=", RowBox[{"(", RowBox[{"DeleteCases", "[", RowBox[{"jList", ",", RowBox[{"{", RowBox[{"_", ",", "b"}], "}"}]}], "]"}], ")"}]}], ";"}]}], "\[IndentingNewLine]", "]"}], ";", RowBox[{"(*", RowBox[{"return", " ", "the", " ", "visible", " ", "list"}], "*)"}], "\[IndentingNewLine]", "visibleList"}]}], "\[IndentingNewLine]", "]"}]}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{{3.7698005042478313`*^9, 3.7698005067611156`*^9}, { 3.769800663565995*^9, 3.7698007120902953`*^9}, { 3.769800821544349*^9, 3.769800821762767*^9}, { 3.7698008895525713`*^9, 3.769800889827838*^9}, { 3.769800922992238*^9, 3.769800928805654*^9}, { 3.7698010094042263`*^9, 3.769801146391124*^9}, { 3.769801183869901*^9, 3.7698012085657644`*^9}, { 3.769801251149911*^9, 3.769801289881386*^9}, {3.769801325189013*^9, 3.769801652264784*^9}, {3.7698016951422124`*^9, 3.7698017424078417`*^9}, {3.769801787714773*^9, 3.7698018140434303`*^9}, {3.7698018558725963`*^9, 3.7698018589433875`*^9}, {3.7698062809785786`*^9, 3.769806289132785*^9}, {3.7699087285928154`*^9, 3.769908737056224*^9}, 3.769961379154033*^9, {3.769961439559438*^9, 3.7699614408390155`*^9}, {3.770400006911172*^9, 3.770400012242868*^9}, {3.770400042389982*^9, 3.7704000442729673`*^9}, {3.7704009994268675`*^9, 3.7704010943336606`*^9}, {3.7704036818987455`*^9, 3.7704036913076196`*^9}, {3.7711627139377656`*^9, 3.7711627349076447`*^9}, {3.7711627790203915`*^9, 3.771162814516395*^9}, 3.771162850380498*^9, { 3.7711629060574417`*^9, 3.7711629438797865`*^9}, { 3.771162978839809*^9, 3.7711630033203006`*^9}, { 3.7711632945606613`*^9, 3.771163322274009*^9}, { 3.7711645614492736`*^9, 3.77116471732237*^9}, { 3.771164770309903*^9, 3.7711647706395025`*^9}, { 3.771777646430233*^9, 3.771777957480303*^9}, 3.7717784613571343`*^9, {3.7717821585367117`*^9, 3.7717822358102427`*^9}, {3.77178364221205*^9, 3.771783644424407*^9}, 3.7717836760468683`*^9, { 3.771783734087491*^9, 3.7717838015425777`*^9}, { 3.7717838388101234`*^9, 3.7717838745449905`*^9}, { 3.7717839363766108`*^9, 3.7717839462750535`*^9}, { 3.7717839776811614`*^9, 3.7717839807928267`*^9}, { 3.7717840114852448`*^9, 3.771784076598447*^9}, { 3.771784167174958*^9, 3.7717843507775545`*^9}, { 3.7717844037619424`*^9, 3.7717844590921974`*^9}, { 3.771784509672432*^9, 3.7717845437822413`*^9}, { 3.7717845859756308`*^9, 3.771784630014027*^9}, { 3.7717846622415733`*^9, 3.7717846931467*^9}, { 3.7717847879360185`*^9, 3.771784790476824*^9}, { 3.771785128256211*^9, 3.771785153447566*^9}, 3.771794969612465*^9, {3.7717950242776937`*^9, 3.771795256392707*^9}, {3.7717952921361847`*^9, 3.771795353558486*^9}, {3.7717961515105257`*^9, 3.77179619045815*^9}, {3.7717963679262133`*^9, 3.771796462239355*^9}, {3.771796511240015*^9, 3.771796573897749*^9}, {3.771842898089777*^9, 3.7718429403457904`*^9}, {3.7719610986286545`*^9, 3.771961244604424*^9}, {3.771961284837776*^9, 3.771961313040526*^9}, {3.7719613440237694`*^9, 3.7719613462439384`*^9}, {3.7719614154548655`*^9, 3.771961451749844*^9}, {3.7719614906548386`*^9, 3.7719615102169437`*^9}, {3.7719615678921137`*^9, 3.771961573627469*^9}, {3.771961658105631*^9, 3.7719617764410768`*^9}, {3.771962223139771*^9, 3.771962312151781*^9}, {3.7719623546938057`*^9, 3.7719624070716114`*^9}, {3.771962465499015*^9, 3.7719624875279465`*^9}, {3.771962524690345*^9, 3.7719625653849564`*^9}, {3.771962603390987*^9, 3.7719626062154503`*^9}, 3.7722206247259855`*^9, { 3.7722206862467413`*^9, 3.77222076189198*^9}, { 3.772221007386054*^9, 3.7722211098525457`*^9}, { 3.7722211828174453`*^9, 3.7722211884926105`*^9}, { 3.7722212237095065`*^9, 3.7722212625295534`*^9}, { 3.7722213190006304`*^9, 3.772221423190547*^9}, { 3.772221463128175*^9, 3.7722214637182617`*^9}, { 3.772221505624196*^9, 3.7722219936266375`*^9}, { 3.772223341815149*^9, 3.7722233677641225`*^9}, { 3.7722247755103445`*^9, 3.7722247894744368`*^9}, { 3.7722251018338804`*^9, 3.7722251048833895`*^9}, { 3.7729842957160206`*^9, 3.772984304955039*^9}, 3.772985541507193*^9, {3.7729855772117596`*^9, 3.772985584887515*^9}, {3.7729858878335037`*^9, 3.772985900062381*^9}, {3.7729860345526695`*^9, 3.7729860627806644`*^9}, 3.772988070017886*^9, { 3.7729885642031775`*^9, 3.7729885657989197`*^9}, { 3.7729886245817733`*^9, 3.772988630947749*^9}, { 3.7729889277339997`*^9, 3.7729889374466968`*^9}, { 3.7729898006937017`*^9, 3.772989831448451*^9}, { 3.772995741022297*^9, 3.772995803540862*^9}, { 3.7729960200413637`*^9, 3.7729960204841747`*^9}, { 3.7729962070387707`*^9, 3.772996215211237*^9}, { 3.772996732350994*^9, 3.7729967495962696`*^9}, { 3.772997077538068*^9, 3.7729970910558977`*^9}, { 3.7729971876676226`*^9, 3.772997211822091*^9}, { 3.772997322168092*^9, 3.772997331829231*^9}, 3.7729975984414873`*^9, {3.7735155936014524`*^9, 3.7735156097023816`*^9}, 3.773515926743907*^9, { 3.773516036212731*^9, 3.773516049052164*^9}, {3.773516122734087*^9, 3.773516141146262*^9}, 3.773516255806281*^9, { 3.773516287452095*^9, 3.7735163216217113`*^9}, { 3.773516537093948*^9, 3.773516568612083*^9}, { 3.7735166215440383`*^9, 3.7735166311529646`*^9}, { 3.7735166770084105`*^9, 3.7735166978540845`*^9}, { 3.7735168597340975`*^9, 3.773516912094287*^9}, { 3.7735169438252535`*^9, 3.7735169737922707`*^9}, { 3.773517006591273*^9, 3.773517042473402*^9}, {3.773517072874154*^9, 3.773517098851974*^9}, {3.7735171321908913`*^9, 3.7735171845972853`*^9}, {3.7735172195584974`*^9, 3.773517229294261*^9}, 3.7735173421243277`*^9, 3.7735173895243964`*^9, {3.773517461204486*^9, 3.7735175025345583`*^9}, {3.77359640482654*^9, 3.7735965235475984`*^9}, {3.7735965625221033`*^9, 3.773596566680029*^9}, 3.773596629556552*^9, { 3.7735967072127934`*^9, 3.7735967732281427`*^9}, { 3.7735968241985817`*^9, 3.7735968287683873`*^9}, 3.773596862657117*^9, {3.7735969203154545`*^9, 3.7735969207610817`*^9}, {3.773597015629098*^9, 3.773597091934434*^9}, 3.773597188675688*^9, {3.773597478510667*^9, 3.773597509749444*^9}, {3.7735987347413545`*^9, 3.7735987367194576`*^9}, {3.7736322743439236`*^9, 3.773632399704029*^9}, 3.773632901468319*^9, {3.773634730436205*^9, 3.773634743493744*^9}, {3.773635555129939*^9, 3.773635570417782*^9}, {3.773635617819194*^9, 3.773635621592131*^9}, {3.7736356625363865`*^9, 3.773635666597662*^9}, {3.773635699609984*^9, 3.773635758298592*^9}, 3.7736592455045614`*^9, 3.77462698006672*^9, 3.77533726033313*^9, {3.7753374847496605`*^9, 3.775337514071699*^9}, {3.77533754547904*^9, 3.7753375568919363`*^9}, {3.775337588553842*^9, 3.7753376151412396`*^9}, {3.7753377414486885`*^9, 3.775337865695151*^9}, {3.7753379215588946`*^9, 3.7753379838571925`*^9}, 3.7753382409706306`*^9, 3.775339412652478*^9, {3.7753394812889957`*^9, 3.775339896387873*^9}, {3.7753399450887775`*^9, 3.775339996742114*^9}, {3.775499354288939*^9, 3.775499700433617*^9}, {3.776183070627548*^9, 3.7761830760084133`*^9}, 3.779703222532337*^9}, CellID->25838681], Cell[BoxData[ RowBox[{ RowBox[{"(*", RowBox[{ "true", " ", "if", " ", "pt", " ", "is", " ", "inside", " ", "polygon"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"testpoint", "[", RowBox[{"poly_", ",", "pt_"}], "]"}], ":=", RowBox[{ RowBox[{"Round", "[", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"Total", "@", RowBox[{"Mod", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"#", "-", RowBox[{"RotateRight", "[", "#", "]"}]}], ")"}], "&"}], "@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"ArcTan", "@@", RowBox[{"(", RowBox[{"pt", "-", "#"}], ")"}]}], "&"}], "/@", "poly"}], ")"}]}], ",", RowBox[{"2", " ", "Pi"}], ",", RowBox[{"-", "Pi"}]}], "]"}]}], "/", "2"}], "/", "Pi"}], ")"}], "]"}], "\[NotEqual]", "0"}]}], "\n", RowBox[{"(*", RowBox[{ "Returns", " ", "a", " ", "nested", " ", "list", " ", "of", " ", "pair", " ", "of", " ", "points", " ", "representing", " ", "each", " ", "line", " ", "in", " ", RowBox[{"polygon", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"lineList", "[", "list_", "]"}], ":=", RowBox[{"Partition", "[", RowBox[{ RowBox[{"Append", "[", RowBox[{"list", ",", RowBox[{"First", "[", "list", "]"}]}], "]"}], ",", "2", ",", "1"}], "]"}]}], ";"}], " ", "\n", RowBox[{"(*", RowBox[{ "Returns", " ", "a", " ", "vector", " ", "for", " ", "a", " ", "line", " ", "between", " ", "two", " ", RowBox[{"points", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"vector", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x1_", ",", "y1_"}], "}"}], ",", RowBox[{"{", RowBox[{"x2_", ",", "y2_"}], "}"}]}], "}"}], "]"}], ":=", RowBox[{"{", RowBox[{ RowBox[{"x2", "-", "x1"}], ",", RowBox[{"y2", "-", "y1"}]}], "}"}]}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Returns", " ", "a", " ", "list", " ", "of", " ", "three", " ", RowBox[{"vertices", "."}]}], "*)"}], "\n", RowBox[{ RowBox[{"vertexList", "[", "list_", "]"}], ":=", RowBox[{"Partition", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{"list", ",", RowBox[{"list", "\[LeftDoubleBracket]", RowBox[{"1", ";;", "2"}], "\[RightDoubleBracket]"}]}], "]"}], ",", "3", ",", "1"}], "]"}]}], "\n", RowBox[{"(*", RowBox[{ "Sorting", " ", "condition", " ", "where", " ", "first", " ", "sorted", " ", "by", " ", "angle", " ", "and", " ", "if", " ", "equal", " ", "angle", " ", "then", " ", "sorted", " ", "based", " ", "on", " ", "the", " ", RowBox[{"distance", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"angleSortCond", "[", RowBox[{"point_", ",", "l1_", ",", "l2_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "=", RowBox[{"getAngle", "[", RowBox[{"{", RowBox[{"point", ",", RowBox[{ "l1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "}"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"getAngle", "[", RowBox[{"{", RowBox[{"point", ",", RowBox[{ "l2", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "}"}], "]"}]}], ",", RowBox[{"c", "=", RowBox[{"Norm", "[", RowBox[{"point", "-", RowBox[{ "l1", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "]"}]}], ",", RowBox[{"d", "=", RowBox[{"Norm", "[", RowBox[{"point", "-", RowBox[{ "l2", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "]"}]}]}], "}"}], ",", RowBox[{ RowBox[{"a", "<", "b"}], "||", RowBox[{"(", RowBox[{ RowBox[{"a", "\[Equal]", "b"}], " ", "&&", " ", RowBox[{"c", "<", "d"}]}], ")"}]}]}], "]"}]}], "\n", RowBox[{"(*", RowBox[{ RowBox[{" ", RowBox[{"Returns", " ", "the", " ", "angle", " ", "made", " ", RowBox[{"in", " ", "[", RowBox[{"o", ",", RowBox[{"2", "Pi"}]}]}]}], ")"}], " ", RowBox[{"range", "."}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"Reference", ":", " ", "https", ":"}], "//", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"mathematica", ".", "stackexchange", ".", "com"}], "/", "questions"}], "/", "111629"}], "/", "calculating"}], "-", "the", "-", "angle", "-", "between", "-", "the", "-", "line", "-", "joining", "-", "two", "-", "points", "-", "and", "-", "the", "-", "x", "-", "axis"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"getAngle", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x1_", ",", "y1_"}], "}"}], ",", RowBox[{"{", RowBox[{"x2_", ",", "y2_"}], "}"}]}], "}"}], "]"}], ":=", RowBox[{"Mod", "[", RowBox[{ RowBox[{"ArcTan", "[", RowBox[{ RowBox[{"x2", "-", "x1"}], ",", RowBox[{"y2", "-", "y1"}]}], "]"}], ",", RowBox[{"2", " ", "\[Pi]"}]}], "]"}]}], "\n", RowBox[{"(*", RowBox[{ RowBox[{ "The", " ", "parametric", " ", "equation", " ", "of", " ", "the", " ", "line", " ", "containing", " ", "the", " ", "points", " ", FormBox["a", TraditionalForm], " ", "and", " ", FormBox["b", TraditionalForm], " ", "is", " ", FormBox[ RowBox[{"a", "+", RowBox[{"\[Lambda]", " ", RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}]}]}], TraditionalForm]}], ",", " ", RowBox[{"where", " ", FormBox[ RowBox[{"0", "\[LessEqual]", "\[Lambda]", "\[LessEqual]", "1"}], TraditionalForm], " ", "for", " ", "points", " ", "between", " ", FormBox["a", TraditionalForm], " ", "and", " ", RowBox[{ FormBox["b", TraditionalForm], ".", " ", "The"}], " ", "value", " ", "of", " ", FormBox["\[Lambda]", TraditionalForm], " ", "is", " ", "given", " ", "by"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"\[Lambda]", "[", RowBox[{"{", RowBox[{"a_", ",", "b_"}], "}"}], "]"}], "[", "p_", "]"}], ":=", FractionBox[ RowBox[{ RowBox[{"(", RowBox[{"a", "-", "p"}], ")"}], ".", RowBox[{"(", RowBox[{"a", "-", "b"}], ")"}]}], RowBox[{ RowBox[{"(", RowBox[{"a", "-", "b"}], ")"}], ".", RowBox[{"(", RowBox[{"a", "-", "b"}], ")"}]}]]}], "\n", RowBox[{"(*", RowBox[{ RowBox[{"for", " ", FormBox["p", TraditionalForm], " ", "on", " ", "the", " ", RowBox[{"line", ".", " ", "For"}], " ", FormBox["p", TraditionalForm], " ", "not", " ", "on", " ", "the", " ", "line"}], ",", " ", RowBox[{ FormBox["\[Lambda]", TraditionalForm], " ", "gives", " ", "the", " ", "closest", " ", "point", " ", "on", " ", "the", " ", RowBox[{"line", "."}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"Two", " ", "lines"}], ",", " ", RowBox[{ SubscriptBox["L", RowBox[{"1", " "}]], "containing", " ", "the", " ", "points", " ", "a", " ", "and", " ", "b", " ", "with", " ", "line", " ", FormBox[ SubscriptBox["L", "2"], TraditionalForm], " ", "containing", " ", "the", " ", "points", " ", FormBox["c", TraditionalForm], " ", "and", " ", FormBox["d", TraditionalForm]}], ",", " ", RowBox[{"intersect", " ", "at", " ", "a", " ", RowBox[{ RowBox[{"point", " ", "\[DoubleLongLeftRightArrow]", " ", FormBox[ RowBox[{ FormBox[ TagBox[ RowBox[{"\[LeftBracketingBar]", RowBox[{"{", RowBox[{ RowBox[{"a", "-", "b"}], ",", RowBox[{"c", "-", "d"}]}], "}"}], "\[RightBracketingBar]"}], {Det}], TraditionalForm], "\[NotEqual]", "0"}], TraditionalForm]}], ".", " ", "Compute"}], " ", "the", " ", "intersection", " ", RowBox[{"point", ":"}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"a_", ",", "b_"}], "}"}], ",", RowBox[{"{", RowBox[{"c_", ",", "d_"}], "}"}]}], "}"}], "]"}], ":=", FractionBox[ RowBox[{ RowBox[{ RowBox[{"Det", "[", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}], "]"}], " ", RowBox[{"(", RowBox[{"c", "-", "d"}], ")"}]}], "-", RowBox[{ RowBox[{"Det", "[", RowBox[{"{", RowBox[{"c", ",", "d"}], "}"}], "]"}], " ", RowBox[{"(", RowBox[{"a", "-", "b"}], ")"}]}]}], RowBox[{"Det", "[", RowBox[{"{", RowBox[{ RowBox[{"a", "-", "b"}], ",", RowBox[{"c", "-", "d"}]}], "}"}], "]"}]]}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"Use", " ", FormBox[ RowBox[{ FormBox[ TagBox[ RowBox[{"\[LeftBracketingBar]", RowBox[{"{", RowBox[{ RowBox[{"a", "-", "b"}], ",", RowBox[{"c", "-", "d"}]}], "}"}], "\[RightBracketingBar]"}], {Det}], TraditionalForm], "\[NotEqual]", "0"}], TraditionalForm], " ", "along", " ", "with", " ", "the", " ", "condition", " ", FormBox[ RowBox[{"0", "\[LessEqual]", "\[Lambda]", "\[LessEqual]", "1"}], TraditionalForm], " ", "to", " ", "determine", " ", "whether", " ", "two", " ", "segments", " ", RowBox[{"intersect", ":"}]}], "*)"}], "\n", RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{ RowBox[{"p1", ":", RowBox[{"{", RowBox[{"a_", ",", "b_"}], "}"}]}], ",", RowBox[{"p2", ":", RowBox[{"{", RowBox[{"c_", ",", "d_"}], "}"}]}]}], "}"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"roundoff", "=", "0.0000001"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Chop", "@", RowBox[{"Det", "[", RowBox[{"{", RowBox[{ RowBox[{"a", "-", "b"}], ",", RowBox[{"c", "-", "d"}]}], "}"}], "]"}]}], "\[Equal]", "0"}], ",", "False", ",", "\[IndentingNewLine]", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"p", "=", RowBox[{"Round", "[", RowBox[{ RowBox[{"LineIntersectionPoint", "[", RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}], "]"}], ",", "roundoff"}], "]"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"0", "<", RowBox[{ RowBox[{"\[Lambda]", "[", "p1", "]"}], "[", "p", "]"}], "<", "1"}], ")"}], " ", "&&", RowBox[{"(", RowBox[{"0", "<", RowBox[{ RowBox[{"\[Lambda]", "[", "p2", "]"}], "[", "p", "]"}], "<", "1"}], ")"}], "&&", " ", RowBox[{"Not", "@", RowBox[{"(", RowBox[{ RowBox[{"p", "\[Equal]", " ", RowBox[{"Round", "[", RowBox[{"a", ",", "roundoff"}], "]"}]}], "||", " ", RowBox[{"p", "\[Equal]", " ", RowBox[{"Round", "[", RowBox[{"b", " ", ",", "roundoff"}], "]"}]}], "||", " ", RowBox[{"p", "\[Equal]", " ", RowBox[{"Round", "[", RowBox[{"c", ",", "roundoff"}], "]"}]}], "||", " ", RowBox[{"p", "\[Equal]", RowBox[{"Round", "[", RowBox[{"d", ",", "roundoff"}], "]"}]}]}], ")"}]}]}], ")"}]}], " ", "]"}]}], "]"}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"distSortCond", "[", RowBox[{"line_", ",", "l1_", ",", "l2_", ",", "point_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "=", RowBox[{"EuclideanDistance", "[", RowBox[{ RowBox[{"LineIntersectionPoint", "[", RowBox[{"Chop", "@", RowBox[{"{", RowBox[{"line", ",", "l1"}], "}"}]}], "]"}], ",", "point"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"EuclideanDistance", "[", RowBox[{ RowBox[{"LineIntersectionPoint", "[", RowBox[{"Chop", "@", RowBox[{"{", RowBox[{"line", ",", "l2"}], "}"}]}], "]"}], ",", "point"}], "]"}]}]}], "}"}], ",", RowBox[{"a", "<", "b"}]}], "]"}]}], "\n", RowBox[{"(*", RowBox[{ "True", " ", "if", " ", "w2", " ", "is", " ", "interior", " ", "vertex", " ", "from", " ", RowBox[{"p", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"intersectInteriorQRev2", "[", RowBox[{"p_", ",", RowBox[{"{", RowBox[{"w1_", ",", "w2_", ",", "w3_"}], "}"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "=", RowBox[{"getClockwiseAngle", "[", RowBox[{"w1", ",", "w2", ",", "w3"}], "]"}]}], ",", RowBox[{"b", "=", " ", RowBox[{"getClockwiseAngle", "[", RowBox[{"p", ",", "w2", ",", "w3"}], "]"}]}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"b", "\[Equal]", "0"}], ",", RowBox[{"b", "=", "6.28319"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"a", ">", "b"}]}]}], "]"}]}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Clockwise", " ", "angle", " ", "bwtween", " ", "two", " ", "vectors"}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"https", ":"}], "//", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"adndevblog", ".", "typepad", ".", "com"}], "/", "manufacturing"}], "/", "2012"}], "/", "07"}], "/", "finding"}], "-", "the", "-", "angle", "-", "between", "-", "two", "-", "vectors", "-", "along", "-", "a", "-", "given", "-", "direction", "-", "anti", "-", "clockwise", "-", "or", "-", RowBox[{"clockwise", ".", "html"}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"getClockwiseAngle", "[", RowBox[{"p1_", ",", "p2_", ",", "p3_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"a", "=", RowBox[{"(", RowBox[{"p3", "-", "p2"}], ")"}]}], ",", RowBox[{"b", "=", RowBox[{"(", RowBox[{"p1", "-", "p2"}], ")"}]}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"AppendTo", "[", RowBox[{"a", ",", "0"}], "]"}], ";", RowBox[{"AppendTo", "[", RowBox[{"b", ",", "0"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Cross", "[", RowBox[{"a", ",", "b"}], "]"}], "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}], ")"}], "<", " ", "0"}], ",", RowBox[{"Chop", "@", RowBox[{"(", RowBox[{ RowBox[{"2", "Pi"}], " ", "-", RowBox[{"VectorAngle", "[", RowBox[{"a", ",", "b"}], "]"}]}], ")"}]}], ",", RowBox[{"Chop", "@", RowBox[{"VectorAngle", "[", RowBox[{"a", ",", "b"}], "]"}]}]}], "]"}]}]}], "]"}]}], "\n", RowBox[{ RowBox[{"pointOnSegmentQ", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x1_", ",", "y1_"}], "}"}], ",", RowBox[{"{", RowBox[{"x2_", ",", "y2_"}], "}"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x3_", ",", "y3_"}], "}"}]}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"ABv", " ", "=", RowBox[{"{", RowBox[{ RowBox[{"x2", "-", "x1"}], ",", RowBox[{"y2", "-", "y1"}], ",", "0"}], "}"}]}], ",", RowBox[{"ACv", "=", RowBox[{"{", RowBox[{ RowBox[{"x3", "-", "x1"}], ",", RowBox[{"y3", "-", "y1"}], ",", "0"}], "}"}]}], ",", "Kac", ",", "Kab"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"And", "@@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"Chop", "@", "#"}], "\[Equal]", "0"}], ")"}], "&"}], "/@", RowBox[{"Cross", "[", RowBox[{"ABv", ",", "ACv"}], "]"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"Kac", "=", RowBox[{"(", RowBox[{"ABv", ".", "ACv"}], ")"}]}], ";", "\[IndentingNewLine]", RowBox[{"Kab", "=", RowBox[{"(", RowBox[{"ABv", ".", "ABv"}], ")"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Kac", "<", " ", "0"}], ",", "False", ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"Kac", ">", "Kab"}], ",", "False", ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"0", "<", " ", "Kac", "<", "Kab"}], ",", "True", ",", "False"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], "]"}]}], ",", "False"}], "]"}]}], "]"}]}], "\n", RowBox[{ RowBox[{"glancingBlow", "[", RowBox[{"a_", ",", RowBox[{"{", RowBox[{"p1_", ",", "p2_", ",", "p3_"}], "}"}]}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Xor", "[", RowBox[{ RowBox[{"reflex", "[", RowBox[{"p1", ",", "p2", ",", "a"}], "]"}], ",", " ", RowBox[{"reflex", "[", RowBox[{"p3", ",", "p2", ",", "a"}], "]"}]}], "]"}]}], "\n", RowBox[{"(*", RowBox[{ RowBox[{ "Function", " ", "gives", " ", "whether", " ", "a", " ", "point", " ", "is", " ", "reflex", " ", "or", " ", "not"}], ",", " ", RowBox[{ "Chop", " ", "is", " ", "used", " ", "to", " ", "round", " ", "off", " ", "to", " ", "the", " ", "nearest", " ", RowBox[{"integer", ".", " ", "From"}], " ", "Motion", " ", "Plannning", " ", "Book", " ", "by", " ", "Steven", " ", RowBox[{"M", ".", "LaValle"}]}]}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"reflex", "[", RowBox[{ RowBox[{"{", RowBox[{"x1_", ",", "y1_"}], "}"}], ",", RowBox[{"{", RowBox[{"x2_", ",", "y2_"}], "}"}], ",", RowBox[{"{", RowBox[{"x3_", ",", "y3_"}], "}"}]}], "]"}], ":=", RowBox[{ RowBox[{"Chop", "[", RowBox[{"Det", "[", RowBox[{"(", "\[NoBreak]", GridBox[{ {"1", "x1", "y1"}, {"1", "x2", "y2"}, {"1", "x3", "y3"} }], "\[NoBreak]", ")"}], "]"}], "]"}], ">", " ", "0"}]}], "\n", RowBox[{ RowBox[{"extendedLine", "[", RowBox[{"p1_", ",", "p2_"}], "]"}], ":=", RowBox[{"{", RowBox[{"p1", ",", RowBox[{"(", RowBox[{"p1", "+", RowBox[{"40", RowBox[{"(", RowBox[{"Normalize", "@", RowBox[{"(", RowBox[{"(", RowBox[{"p2", "-", "p1"}], ")"}], ")"}]}], ")"}]}]}], ")"}]}], "}"}]}], "\n", RowBox[{"(*", RowBox[{ "returns", " ", "True", " ", "if", " ", "the", " ", "point", " ", "p", " ", "lies", " ", "on", " ", "the", " ", "right", " ", "side", " ", "else", " ", "False"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"leftOrRight", "[", RowBox[{ RowBox[{"a", ":", RowBox[{"{", RowBox[{"x1_", ",", "y1_"}], "}"}]}], ",", RowBox[{"b", ":", RowBox[{"{", RowBox[{"x2_", ",", "y2_"}], "}"}]}], ",", RowBox[{"p", ":", RowBox[{"{", RowBox[{"x_", ",", "y_"}], "}"}]}]}], "]"}], ":=", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"x", "\[Minus]", "x1"}], ")"}], RowBox[{"(", RowBox[{"y2", "\[Minus]", "y1"}], ")"}]}], "\[Minus]", RowBox[{ RowBox[{"(", RowBox[{"y", "\[Minus]", "y1"}], ")"}], RowBox[{"(", RowBox[{"x2", "\[Minus]", "x1"}], ")"}]}]}], ")"}], "\[GreaterEqual]", " ", "0"}]}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Function", " ", "returns", " ", "False", " ", "if", " ", "the", " ", "line", " ", "formed", " ", "by", " ", "points", " ", "p1", " ", "and", " ", "p2", " ", "intersect", " ", "any", " ", "of", " ", "the", " ", "lines", " ", "in", " ", "linelist", " ", "else", " ", "returns", " ", RowBox[{"True", "."}]}], "*)"}], "\n", RowBox[{ RowBox[{"noIntersection", "[", RowBox[{"p1_", ",", "p2_", ",", "linelist_"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"Nor", "@@", RowBox[{"(", RowBox[{ RowBox[{ RowBox[{"SegmentIntersectionQ", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"p1", ",", "p2"}], "}"}], ",", "#"}], "}"}], "]"}], "&"}], "/@", "linelist"}], ")"}]}]}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Returns", " ", "a", " ", "normal", " ", "vector", " ", "for", " ", "a", " ", "line", " ", "between", " ", "two", " ", RowBox[{"points", "."}]}], "*)"}], "\n", RowBox[{ RowBox[{"normalVector", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"x2_", ",", "y2_"}], "}"}], ",", RowBox[{"{", RowBox[{"x1_", ",", "y1_"}], "}"}]}], "}"}], "]"}], ":=", RowBox[{"Normalize", "[", RowBox[{"{", RowBox[{ RowBox[{"(", RowBox[{ RowBox[{"-", "y2"}], "+", "y1"}], ")"}], ",", RowBox[{"x2", "-", "x1"}]}], "}"}], " ", "]"}]}]}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{{3.7698005042478313`*^9, 3.7698005067611156`*^9}, { 3.769800663565995*^9, 3.7698007120902953`*^9}, { 3.769800821544349*^9, 3.769800821762767*^9}, { 3.7698008895525713`*^9, 3.769800889827838*^9}, { 3.769800922992238*^9, 3.769800928805654*^9}, { 3.7698010094042263`*^9, 3.769801146391124*^9}, { 3.769801183869901*^9, 3.7698012085657644`*^9}, { 3.769801251149911*^9, 3.769801289881386*^9}, {3.769801325189013*^9, 3.769801652264784*^9}, {3.7698016951422124`*^9, 3.7698017424078417`*^9}, {3.769801787714773*^9, 3.7698018140434303`*^9}, {3.7698018558725963`*^9, 3.7698018589433875`*^9}, {3.7698062809785786`*^9, 3.769806289132785*^9}, {3.7699087285928154`*^9, 3.769908737056224*^9}, 3.769961379154033*^9, {3.769961439559438*^9, 3.7699614408390155`*^9}, {3.770400006911172*^9, 3.770400012242868*^9}, {3.770400042389982*^9, 3.7704000442729673`*^9}, {3.7704009994268675`*^9, 3.7704010943336606`*^9}, {3.7704036818987455`*^9, 3.7704036913076196`*^9}, {3.7711627139377656`*^9, 3.7711627349076447`*^9}, {3.7711627790203915`*^9, 3.771162814516395*^9}, 3.771162850380498*^9, { 3.7711629060574417`*^9, 3.7711629438797865`*^9}, { 3.771162978839809*^9, 3.7711630033203006`*^9}, { 3.7711632945606613`*^9, 3.771163322274009*^9}, { 3.7711645614492736`*^9, 3.77116471732237*^9}, { 3.771164770309903*^9, 3.7711647706395025`*^9}, { 3.771777646430233*^9, 3.771777957480303*^9}, 3.7717784613571343`*^9, {3.7717821585367117`*^9, 3.7717822358102427`*^9}, {3.77178364221205*^9, 3.771783644424407*^9}, 3.7717836760468683`*^9, { 3.771783734087491*^9, 3.7717838015425777`*^9}, { 3.7717838388101234`*^9, 3.7717838745449905`*^9}, { 3.7717839363766108`*^9, 3.7717839462750535`*^9}, { 3.7717839776811614`*^9, 3.7717839807928267`*^9}, { 3.7717840114852448`*^9, 3.771784076598447*^9}, { 3.771784167174958*^9, 3.7717843507775545`*^9}, { 3.7717844037619424`*^9, 3.7717844590921974`*^9}, { 3.771784509672432*^9, 3.7717845437822413`*^9}, { 3.7717845859756308`*^9, 3.771784630014027*^9}, { 3.7717846622415733`*^9, 3.7717846931467*^9}, { 3.7717847879360185`*^9, 3.771784790476824*^9}, { 3.771785128256211*^9, 3.771785153447566*^9}, 3.771794969612465*^9, {3.7717950242776937`*^9, 3.771795256392707*^9}, {3.7717952921361847`*^9, 3.771795353558486*^9}, {3.7717961515105257`*^9, 3.77179619045815*^9}, {3.7717963679262133`*^9, 3.771796462239355*^9}, {3.771796511240015*^9, 3.771796573897749*^9}, {3.771842898089777*^9, 3.7718429403457904`*^9}, {3.7719610986286545`*^9, 3.771961244604424*^9}, {3.771961284837776*^9, 3.771961313040526*^9}, {3.7719613440237694`*^9, 3.7719613462439384`*^9}, {3.7719614154548655`*^9, 3.771961451749844*^9}, {3.7719614906548386`*^9, 3.7719615102169437`*^9}, {3.7719615678921137`*^9, 3.771961573627469*^9}, {3.771961658105631*^9, 3.7719617764410768`*^9}, {3.771962223139771*^9, 3.771962312151781*^9}, {3.7719623546938057`*^9, 3.7719624070716114`*^9}, {3.771962465499015*^9, 3.7719624875279465`*^9}, {3.771962524690345*^9, 3.7719625653849564`*^9}, {3.771962603390987*^9, 3.7719626062154503`*^9}, 3.7722206247259855`*^9, { 3.7722206862467413`*^9, 3.77222076189198*^9}, { 3.772221007386054*^9, 3.7722211098525457`*^9}, { 3.7722211828174453`*^9, 3.7722211884926105`*^9}, { 3.7722212237095065`*^9, 3.7722212625295534`*^9}, { 3.7722213190006304`*^9, 3.772221423190547*^9}, { 3.772221463128175*^9, 3.7722214637182617`*^9}, { 3.772221505624196*^9, 3.7722219936266375`*^9}, { 3.772223341815149*^9, 3.7722233677641225`*^9}, { 3.7722247755103445`*^9, 3.7722247894744368`*^9}, { 3.7722251018338804`*^9, 3.7722251048833895`*^9}, { 3.7729842957160206`*^9, 3.772984304955039*^9}, 3.772985541507193*^9, {3.7729855772117596`*^9, 3.772985584887515*^9}, {3.7729858878335037`*^9, 3.772985900062381*^9}, {3.7729860345526695`*^9, 3.7729860627806644`*^9}, 3.772988070017886*^9, { 3.7729885642031775`*^9, 3.7729885657989197`*^9}, { 3.7729886245817733`*^9, 3.772988630947749*^9}, { 3.7729889277339997`*^9, 3.7729889374466968`*^9}, { 3.7729898006937017`*^9, 3.772989831448451*^9}, { 3.772995741022297*^9, 3.772995803540862*^9}, { 3.7729960200413637`*^9, 3.7729960204841747`*^9}, { 3.7729962070387707`*^9, 3.772996215211237*^9}, { 3.772996732350994*^9, 3.7729967495962696`*^9}, { 3.772997077538068*^9, 3.7729970910558977`*^9}, { 3.7729971876676226`*^9, 3.772997211822091*^9}, { 3.772997322168092*^9, 3.772997331829231*^9}, 3.7729975984414873`*^9, {3.7735155936014524`*^9, 3.7735156097023816`*^9}, 3.773515926743907*^9, { 3.773516036212731*^9, 3.773516049052164*^9}, {3.773516122734087*^9, 3.773516141146262*^9}, 3.773516255806281*^9, { 3.773516287452095*^9, 3.7735163216217113`*^9}, { 3.773516537093948*^9, 3.773516568612083*^9}, { 3.7735166215440383`*^9, 3.7735166311529646`*^9}, { 3.7735166770084105`*^9, 3.7735166978540845`*^9}, { 3.7735168597340975`*^9, 3.773516912094287*^9}, { 3.7735169438252535`*^9, 3.7735169737922707`*^9}, { 3.773517006591273*^9, 3.773517042473402*^9}, {3.773517072874154*^9, 3.773517098851974*^9}, {3.7735171321908913`*^9, 3.7735171845972853`*^9}, {3.7735172195584974`*^9, 3.773517229294261*^9}, 3.7735173421243277`*^9, 3.7735173895243964`*^9, {3.773517461204486*^9, 3.7735175025345583`*^9}, {3.77359640482654*^9, 3.7735965235475984`*^9}, {3.7735965625221033`*^9, 3.773596566680029*^9}, 3.773596629556552*^9, { 3.7735967072127934`*^9, 3.7735967732281427`*^9}, { 3.7735968241985817`*^9, 3.7735968287683873`*^9}, 3.773596862657117*^9, {3.7735969203154545`*^9, 3.7735969207610817`*^9}, {3.773597015629098*^9, 3.773597091934434*^9}, 3.773597188675688*^9, {3.773597478510667*^9, 3.773597509749444*^9}, {3.7735987347413545`*^9, 3.7735987367194576`*^9}, {3.7736322743439236`*^9, 3.773632399704029*^9}, 3.773632901468319*^9, {3.773634730436205*^9, 3.773634743493744*^9}, {3.773635555129939*^9, 3.773635570417782*^9}, {3.773635617819194*^9, 3.773635621592131*^9}, {3.7736356625363865`*^9, 3.773635666597662*^9}, {3.773635699609984*^9, 3.773635758298592*^9}, 3.7736592455045614`*^9, 3.77462698006672*^9, 3.77533726033313*^9, {3.7753374847496605`*^9, 3.775337514071699*^9}, {3.77533754547904*^9, 3.7753375568919363`*^9}, {3.775337588553842*^9, 3.7753376151412396`*^9}, {3.7753377414486885`*^9, 3.775337865695151*^9}, {3.7753379215588946`*^9, 3.7753379838571925`*^9}, 3.7753382409706306`*^9, 3.775339412652478*^9, {3.7753394812889957`*^9, 3.775339896387873*^9}, {3.7753399450887775`*^9, 3.775339996742114*^9}, {3.775499354288939*^9, 3.775499355143386*^9}, {3.7754997073175163`*^9, 3.7754998872708817`*^9}, {3.7755004830761967`*^9, 3.7755004915204*^9}, 3.779703222532461*^9}, CellID->1882239073], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"poly1", "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "+", "#"}], ")"}], "&"}], "/@", RowBox[{"CirclePoints", "[", "4", "]"}]}]}], ",", RowBox[{"poly2", "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], "+", "#"}], ")"}], "&"}], "/@", RowBox[{"CirclePoints", "[", "3", "]"}]}]}], RowBox[{"(*", RowBox[{ "polyi", " ", "are", " ", "moveable", " ", "obstacles"}], "*)"}], "\[IndentingNewLine]", ",", RowBox[{"bound", "=", RowBox[{"(", RowBox[{"5", "*", RowBox[{"CirclePoints", "@", "4"}]}], ")"}]}], ",", RowBox[{"invisiblePoly", "=", RowBox[{"(", RowBox[{"7", "*", RowBox[{"CirclePoints", "@", "4"}]}], ")"}]}], RowBox[{"(*", RowBox[{ "boundaries", " ", "of", " ", "the", " ", "workspace"}], "*)"}], "\[IndentingNewLine]", ",", " ", RowBox[{"cval", " ", "=", " ", RowBox[{"ColorData", "[", RowBox[{"100", ",", "\"\\""}], "]"}]}], " ", RowBox[{"(*", RowBox[{ "Colors", " ", "for", " ", "robots", " ", "and", " ", "the", " ", "visible", " ", "regions"}], "*)"}], "\[IndentingNewLine]", ",", "listofPoly"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "Only", " ", "recalculate", " ", "the", " ", "visible", " ", "region", " ", "if", " ", "a", " ", "point", " ", "moves", " ", RowBox[{"(", RowBox[{ "or", " ", "a", " ", "moveable", " ", "obstacle", " ", "moves"}], ")"}], "\[IndentingNewLine]", "or", " ", "for", " ", "a", " ", "new", " ", "point", " ", "added"}], "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"listofPoly", "=", RowBox[{"N", "@", RowBox[{"(", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "\[Equal]", "\"\\""}], ",", RowBox[{"{", RowBox[{ "poly1", ",", "poly2", ",", "bound", ",", "invisiblePoly"}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "\[Equal]", "\"\\""}], ",", RowBox[{"{", RowBox[{"irregularPoly", ",", "invisiblePoly"}], "}"}], ",", RowBox[{"{", RowBox[{"cubiclePoly", ",", "invisiblePoly"}], "}"}]}], "]"}]}], "]"}], ")"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Table", "[", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[NotEqual]", " ", RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "||", RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "\[NotEqual]", " ", RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "||", RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], "\[NotEqual]", " ", RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}], "||", " ", RowBox[{"sOld", "<", RowBox[{"i", "-", "2"}]}], "||", RowBox[{"prevReg", "\[NotEqual]", "reg"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"visibleRegion", "\[LeftDoubleBracket]", RowBox[{"i", "-", "2"}], "\[RightDoubleBracket]"}], "=", RowBox[{"visiblePolys", "[", RowBox[{"listofPoly", ",", RowBox[{ "pts", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{ RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "=", RowBox[{ "pts", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}]}]}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "3", ",", RowBox[{"s", "+", "2"}]}], "}"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"update", " ", "the", " ", "Old", " ", "variables"}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", " ", RowBox[{ RowBox[{ RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "\[NotEqual]", " ", RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], "||", RowBox[{ RowBox[{ "pts", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], "\[NotEqual]", " ", RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "=", RowBox[{ "pts", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}], ";", RowBox[{ RowBox[{ "ptsOld", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}], "=", RowBox[{ "pts", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"sOld", "=", "s"}], ";", "\[IndentingNewLine]", RowBox[{"prevReg", "=", "reg"}], ";", "\[IndentingNewLine]", RowBox[{"Graphics", "[", RowBox[{ RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"Table", "[", " ", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ "cval", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{"Opacity", "[", "0.3", "]"}], ",", RowBox[{"Polygon", "@", RowBox[{ "visibleRegion", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}]}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", "1", ",", "s"}], "}"}]}], "]"}], " ", RowBox[{"(*", RowBox[{"visible", " ", "regions"}], "*)"}], "\[IndentingNewLine]", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "\[Equal]", "\"\\""}], ",", RowBox[{"(*", RowBox[{"Ideal", " ", "Environment", " ", "obstacles"}], "*)"}], RowBox[{"{", RowBox[{"{", RowBox[{"Transparent", ",", RowBox[{"EdgeForm", "[", "Thin", "]"}], ",", RowBox[{"{", RowBox[{"Polygon", "@", "bound"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"Polygon", "@", "poly1"}], ",", RowBox[{"Polygon", "@", "poly2"}]}], "}"}]}], "}"}], "}"}]}], "]"}], " ", "\[IndentingNewLine]", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "\[Equal]", "\"\\""}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"Transparent", ",", RowBox[{"EdgeForm", "[", "Thin", "]"}], ",", RowBox[{"Polygon", "@", "irregularPoly"}]}], "}"}], ",", RowBox[{"{", RowBox[{"EdgeForm", "[", RowBox[{"{", RowBox[{"Thin", ",", "Black"}], "}"}], "]"}], "}"}]}], "}"}]}], "]"}], RowBox[{"(*", RowBox[{"Non", "-", RowBox[{"Ideal", " ", "Envir"}]}], "*)"}], "\[IndentingNewLine]", ",", RowBox[{"If", "[", RowBox[{ RowBox[{"reg", "\[Equal]", "\"\\""}], ",", RowBox[{"{", RowBox[{"{", RowBox[{"Transparent", ",", RowBox[{"EdgeForm", "[", RowBox[{"{", RowBox[{ RowBox[{"Opacity", "[", "0.7", "]"}], ",", "Gray", ",", "Thick"}], "}"}], "]"}], ",", RowBox[{"Polygon", "@", "cubiclePoly"}]}], "}"}], "}"}]}], "]"}], RowBox[{"(*", RowBox[{"Complex", " ", "Envir"}], "*)"}], "\[IndentingNewLine]", ",", RowBox[{"Table", "[", " ", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ "cval", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], ",", RowBox[{"EdgeForm", "[", RowBox[{"{", RowBox[{"Thin", ",", "Black"}], "}"}], "]"}], ",", RowBox[{"Disk", "[", RowBox[{ RowBox[{"pts", "\[LeftDoubleBracket]", RowBox[{"i", "+", "2"}], "\[RightDoubleBracket]"}], ",", "0.1"}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{"i", ",", "1", ",", "s"}], "}"}]}], "]"}]}], " ", RowBox[{"(*", "guards", "*)"}], "\[IndentingNewLine]", "}"}], ",", RowBox[{"PlotRange", "\[Rule]", " ", RowBox[{"4", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "}"}]}]}], "\[IndentingNewLine]", ",", RowBox[{"ImageSize", "\[Rule]", RowBox[{"{", RowBox[{"450", ",", "450"}], "}"}]}]}], "]"}]}]}], "]"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"s", ",", "1", ",", "\"\\""}], "}"}], ",", RowBox[{"Range", "@", "8"}], ",", RowBox[{"ControlType", "\[Rule]", "Setter"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ "reg", ",", "\"\\"", ",", "\"\\""}], "}"}], ",", RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\"", ",", "\"\\""}], "}"}], ",", RowBox[{"ControlType", "\[Rule]", "Setter"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"prevReg", ",", "\"\<\>\""}], "}"}], ",", " ", RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"sOld", ",", RowBox[{"-", "1"}]}], "}"}], ",", " ", RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"visibleRegion", ",", RowBox[{"ConstantArray", "[", RowBox[{"10", ",", RowBox[{"{", RowBox[{"8", ",", "2", ",", "2"}], "}"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"irregularPoly", "\[IndentingNewLine]", ",", RowBox[{"Reverse", "@", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "1.2"}], ",", RowBox[{"-", "2.8"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3.5"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "2.3"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3.3"}], ",", "3.2"}], "}"}], ",", RowBox[{"{", RowBox[{"0.75", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.9"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.3"}], ",", "1.35"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.2"}], ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"0.5", ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{"2.6", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"2.1", ",", RowBox[{"-", "2.7"}]}], "}"}]}], "}"}]}]}], "}"}], ",", RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"cubiclePoly", "\[IndentingNewLine]", ",", RowBox[{"Reverse", "@", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "2"}], ",", RowBox[{"-", "3.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2"}], ",", RowBox[{"-", "2"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3.5"}], ",", RowBox[{"-", "2"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3.5"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.5"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.5"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3.5"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "3.5"}], ",", "3.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.5"}], ",", "3.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.5"}], ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"0.5", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"0.5", ",", "2.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "2.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "3.5"}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", "3.5"}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", "2.5"}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", "2.5"}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", RowBox[{"-", "0.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", RowBox[{"-", "0.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", RowBox[{"-", "1.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", RowBox[{"-", "1.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"3.5", ",", RowBox[{"-", "3.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", RowBox[{"-", "3.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", RowBox[{"-", "3"}]}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", RowBox[{"-", "3"}]}], "}"}], ",", RowBox[{"{", RowBox[{"1.5", ",", RowBox[{"-", "3.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.5"}], ",", RowBox[{"-", "3.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.5"}], ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "0.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "0.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "3.5"}]}], "}"}]}], "}"}]}]}], "}"}], ",", RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"ptsOld", ",", RowBox[{"ConstantArray", "[", RowBox[{ RowBox[{"-", "10"}], ",", RowBox[{"{", RowBox[{"10", ",", "2"}], "}"}]}], "]"}]}], "}"}], ",", " ", RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"pts", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "2"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "1.5"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2"}], ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.5"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "0.6"}], ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2.5"}], ",", "0.5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "2"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1.25"}], ",", "3"}], "}"}]}], "}"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"4", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "1"}]}], "}"}]}], ",", RowBox[{"4", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}], ",", "Locator", ",", RowBox[{"Appearance", "\[Rule]", "None"}]}], "}"}], "\[IndentingNewLine]", ",", RowBox[{"FrameMargins", "\[Rule]", RowBox[{"-", "5"}]}], ",", RowBox[{"SaveDefinitions", "\[Rule]", "True"}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.7746270117450037`*^9, {3.774627051407606*^9, 3.7746270844612417`*^9}, {3.77462746822684*^9, 3.7746274783447523`*^9}, 3.7753372554676123`*^9, { 3.775353418396277*^9, 3.775353477776383*^9}, 3.775410208848353*^9, {3.7754106331023436`*^9, 3.7754106397724*^9}, {3.7754999371683064`*^9, 3.775499945535524*^9}, {3.775499977367278*^9, 3.7754999783907557`*^9}, {3.775500013071024*^9, 3.775500017742591*^9}, {3.775500054993601*^9, 3.7755000990990467`*^9}, {3.7755001606153603`*^9, 3.775500176724958*^9}, 3.7761829690313234`*^9, 3.7761831209827247`*^9, 3.77970322252146*^9}], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`cubiclePoly$$ = {{-1, -3.5}, {-1, \ -0.5}, {0, -0.5}, {0, -1}, {-0.5, -1}, {-0.5, -3.5}, {1.5, -3.5}, { 1.5, -3}, {2, -3}, {2, -3.5}, {3.5, -3.5}, {3.5, -1}, {2, -1}, { 2, -1.5}, {1.5, -1.5}, {1.5, -0.5}, {3.5, -0.5}, {3.5, 2}, { 1.5, 2}, {1.5, 2.5}, {3.5, 2.5}, {3.5, 3.5}, {-1, 3.5}, {-1, 2.5}, {0.5, 2.5}, { 0.5, 2}, {-1.5, 2}, {-1.5, 3.5}, {-3.5, 3.5}, {-3.5, 0.5}, {-1.5, 0.5}, {-1.5, 0}, {-3.5, 0}, {-3.5, -2}, {-2, -2}, {-2, -3.5}}, \ $CellContext`irregularPoly$$ = {{2.1, -2.7}, {2.6, 1}, {0.5, 0.5}, {-1.2, -1}, {-1.3, 1.35}, {-0.9, 1}, {0.75, 3}, {-3.3, 3.2}, {-1, 2.3}, {-3.5, 0.5}, {-1.2, -2.8}}, $CellContext`prevReg$$ = "cubicle", $CellContext`pts$$ = {{1, 0}, {2, 2}, {0, 0}, { 0, -1.5}, {-2, -1}, {-1.5, 0.5}, {-0.6, -1}, {-2.5, 0.5}, {-2, 1}, {-1.25, 3}}, $CellContext`ptsOld$$ = {{1, 0}, {2, 2}, {0, 0}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, -10}, \ {-10, -10}, {-10, -10}}, $CellContext`reg$$ = "cubicle", $CellContext`s$$ = 1, $CellContext`sOld$$ = 1, $CellContext`visibleRegion$$ = {CompressedData[" 1:eJxTTMoPSmViYGCQBGIQDQE8DlAGlP5hj53P4nD2DAjAxGH63tij8h+g698P 4zOCKdYDqOp5MPirV4HAJ3tU/Q/Q+AwMjFD1R/w5S+vKf+xDNe8PVN0HmH64 Phj/8u9j1+dFCtkzouiD+Redz3EA1V8cB8DOXMUEd7f6Zf7N7/5zO/wHA240 /TB3w/gw98DDbT8AVU5KkQ== "], {{10, 10}, {10, 10}}, {{10, 10}, { 10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}}, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`s$$], 1, "number of guards"}, {1, 2, 3, 4, 5, 6, 7, 8}}, {{ Hold[$CellContext`reg$$], "cubicle", "environment"}, { "movable obstacles", "irregular", "cubicle"}}, {{ Hold[$CellContext`prevReg$$], "cubicle"}}, {{ Hold[$CellContext`sOld$$], 1}}, {{ Hold[$CellContext`visibleRegion$$], {CompressedData[" 1:eJxTTMoPSmViYGCQBGIQDQE8DlAGlP5hj53P4nD2DAjAxGH63tij8h+g698P 4zOCKdYDqOp5MPirV4HAJ3tU/Q/Q+AwMjFD1R/w5S+vKf+xDNe8PVN0HmH64 Phj/8u9j1+dFCtkzouiD+Redz3EA1V8cB8DOXMUEd7f6Zf7N7/5zO/wHA240 /TB3w/gw98DDbT8AVU5KkQ== "], {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{ 10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}}}}, {{ Hold[$CellContext`irregularPoly$$], {{2.1, -2.7}, {2.6, 1}, { 0.5, 0.5}, {-1.2, -1}, {-1.3, 1.35}, {-0.9, 1}, { 0.75, 3}, {-3.3, 3.2}, {-1, 2.3}, {-3.5, 0.5}, {-1.2, -2.8}}}}, {{ Hold[$CellContext`cubiclePoly$$], {{-1, -3.5}, {-1, -0.5}, { 0, -0.5}, {0, -1}, {-0.5, -1}, {-0.5, -3.5}, {1.5, -3.5}, { 1.5, -3}, {2, -3}, {2, -3.5}, {3.5, -3.5}, {3.5, -1}, { 2, -1}, {2, -1.5}, {1.5, -1.5}, {1.5, -0.5}, {3.5, -0.5}, { 3.5, 2}, {1.5, 2}, {1.5, 2.5}, {3.5, 2.5}, {3.5, 3.5}, {-1, 3.5}, {-1, 2.5}, {0.5, 2.5}, { 0.5, 2}, {-1.5, 2}, {-1.5, 3.5}, {-3.5, 3.5}, {-3.5, 0.5}, {-1.5, 0.5}, {-1.5, 0}, {-3.5, 0}, {-3.5, -2}, {-2, -2}, {-2, -3.5}}}}, {{ Hold[$CellContext`ptsOld$$], {{1, 0}, {2, 2}, {0, 0}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, \ -10}, {-10, -10}, {-10, -10}}}}, {{ Hold[$CellContext`pts$$], {{1, 0}, {2, 2}, {0, 0}, { 0, -1.5}, {-2, -1}, {-1.5, 0.5}, {-0.6, -1}, {-2.5, 0.5}, {-2, 1}, {-1.25, 3}}}, {-4, -4}, {4, 4}}}, Typeset`size$$ = { 450., {223., 227.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = False, $CellContext`s$804189$$ = 0, $CellContext`reg$804190$$ = 0, $CellContext`pts$804191$$ = {0, 0}}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`cubiclePoly$$ = {{-1, -3.5}, {-1, \ -0.5}, {0, -0.5}, {0, -1}, {-0.5, -1}, {-0.5, -3.5}, {1.5, -3.5}, { 1.5, -3}, {2, -3}, {2, -3.5}, {3.5, -3.5}, {3.5, -1}, { 2, -1}, {2, -1.5}, {1.5, -1.5}, {1.5, -0.5}, {3.5, -0.5}, { 3.5, 2}, {1.5, 2}, {1.5, 2.5}, {3.5, 2.5}, {3.5, 3.5}, {-1, 3.5}, {-1, 2.5}, {0.5, 2.5}, { 0.5, 2}, {-1.5, 2}, {-1.5, 3.5}, {-3.5, 3.5}, {-3.5, 0.5}, {-1.5, 0.5}, {-1.5, 0}, {-3.5, 0}, {-3.5, -2}, {-2, -2}, {-2, -3.5}}, \ $CellContext`irregularPoly$$ = {{2.1, -2.7}, {2.6, 1}, {0.5, 0.5}, {-1.2, -1}, {-1.3, 1.35}, {-0.9, 1}, {0.75, 3}, {-3.3, 3.2}, {-1, 2.3}, {-3.5, 0.5}, {-1.2, -2.8}}, $CellContext`prevReg$$ = "cubicle", $CellContext`pts$$ = {{1, 0}, {2, 2}, {0, 0}, { 0, -1.5}, {-2, -1}, {-1.5, 0.5}, {-0.6, -1}, {-2.5, 0.5}, {-2, 1}, {-1.25, 3}}, $CellContext`ptsOld$$ = {{1, 0}, {2, 2}, {0, 0}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, \ -10}, {-10, -10}, {-10, -10}}, $CellContext`reg$$ = "cubicle", $CellContext`s$$ = 1, $CellContext`sOld$$ = 1, $CellContext`visibleRegion$$ = {CompressedData[" 1:eJxTTMoPSmViYGCQBGIQDQE8DlAGlP5hj53P4nD2DAjAxGH63tij8h+g698P 4zOCKdYDqOp5MPirV4HAJ3tU/Q/Q+AwMjFD1R/w5S+vKf+xDNe8PVN0HmH64 Phj/8u9j1+dFCtkzouiD+Redz3EA1V8cB8DOXMUEd7f6Zf7N7/5zO/wHA240 /TB3w/gw98DDbT8AVU5KkQ== "], {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}}}, "ControllerVariables" :> { Hold[$CellContext`s$$, $CellContext`s$804189$$, 0], Hold[$CellContext`reg$$, $CellContext`reg$804190$$, 0], Hold[$CellContext`pts$$, $CellContext`pts$804191$$, {0, 0}]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> Module[{$CellContext`poly1$ = Map[Part[$CellContext`pts$$, 1] + #& , CirclePoints[4]], $CellContext`poly2$ = Map[Part[$CellContext`pts$$, 2] + #& , CirclePoints[3]], $CellContext`bound$ = 5 CirclePoints[4], $CellContext`invisiblePoly$ = 7 CirclePoints[4], $CellContext`cval$ = ColorData[ 100, "ColorList"], $CellContext`listofPoly$}, \ $CellContext`listofPoly$ = N[ If[$CellContext`reg$$ == "movable obstacles", {$CellContext`poly1$, \ $CellContext`poly2$, $CellContext`bound$, \ $CellContext`invisiblePoly$}, If[$CellContext`reg$$ == "irregular", {$CellContext`irregularPoly$$, \ $CellContext`invisiblePoly$}, {$CellContext`cubiclePoly$$, \ $CellContext`invisiblePoly$}]]]; Table[ If[ Or[ Part[$CellContext`pts$$, $CellContext`i] != Part[$CellContext`ptsOld$$, $CellContext`i], Part[$CellContext`pts$$, 1] != Part[$CellContext`ptsOld$$, 1], Part[$CellContext`pts$$, 2] != Part[$CellContext`ptsOld$$, 2], $CellContext`sOld$$ < $CellContext`i - 2, $CellContext`prevReg$$ != $CellContext`reg$$], Part[$CellContext`visibleRegion$$, $CellContext`i - 2] = $CellContext`visiblePolys[$CellContext`listofPoly$, Part[$CellContext`pts$$, $CellContext`i]]; Part[$CellContext`ptsOld$$, $CellContext`i] = Part[$CellContext`pts$$, $CellContext`i]], \ {$CellContext`i, 3, $CellContext`s$$ + 2}]; If[ Or[ Part[$CellContext`pts$$, 1] != Part[$CellContext`ptsOld$$, 1], Part[$CellContext`pts$$, 2] != Part[$CellContext`ptsOld$$, 2]], Part[$CellContext`ptsOld$$, 1] = Part[$CellContext`pts$$, 1]; Part[$CellContext`ptsOld$$, 2] = Part[$CellContext`pts$$, 2]]; $CellContext`sOld$$ = $CellContext`s$$; \ $CellContext`prevReg$$ = $CellContext`reg$$; Graphics[{ Table[{ Part[$CellContext`cval$, $CellContext`i], Opacity[0.3], Polygon[ Part[$CellContext`visibleRegion$$, $CellContext`i]]}, \ {$CellContext`i, 1, $CellContext`s$$}], If[$CellContext`reg$$ == "movable obstacles", {{Transparent, EdgeForm[Thin], { Polygon[$CellContext`bound$]}, { Polygon[$CellContext`poly1$], Polygon[$CellContext`poly2$]}}}], If[$CellContext`reg$$ == "irregular", {{Transparent, EdgeForm[Thin], Polygon[$CellContext`irregularPoly$$]}, { EdgeForm[{Thin, Black}]}}], If[$CellContext`reg$$ == "cubicle", {{Transparent, EdgeForm[{ Opacity[0.7], Gray, Thick}], Polygon[$CellContext`cubiclePoly$$]}}], Table[{ Part[$CellContext`cval$, $CellContext`i], EdgeForm[{Thin, Black}], Disk[ Part[$CellContext`pts$$, $CellContext`i + 2], 0.1]}, {$CellContext`i, 1, $CellContext`s$$}]}, PlotRange -> 4 {{-1, 1}, {-1, 1}}, ImageSize -> {450, 450}]], "Specifications" :> {{{$CellContext`s$$, 1, "number of guards"}, {1, 2, 3, 4, 5, 6, 7, 8}, ControlType -> Setter}, {{$CellContext`reg$$, "cubicle", "environment"}, { "movable obstacles", "irregular", "cubicle"}, ControlType -> Setter}, {{$CellContext`prevReg$$, "cubicle"}, ControlType -> None}, {{$CellContext`sOld$$, 1}, ControlType -> None}, {{$CellContext`visibleRegion$$, {CompressedData[" 1:eJxTTMoPSmViYGCQBGIQDQE8DlAGlP5hj53P4nD2DAjAxGH63tij8h+g698P 4zOCKdYDqOp5MPirV4HAJ3tU/Q/Q+AwMjFD1R/w5S+vKf+xDNe8PVN0HmH64 Phj/8u9j1+dFCtkzouiD+Redz3EA1V8cB8DOXMUEd7f6Zf7N7/5zO/wHA240 /TB3w/gw98DDbT8AVU5KkQ== "], {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}, {{10, 10}, {10, 10}}}}, ControlType -> None}, {{$CellContext`irregularPoly$$, {{2.1, -2.7}, { 2.6, 1}, {0.5, 0.5}, {-1.2, -1}, {-1.3, 1.35}, {-0.9, 1}, { 0.75, 3}, {-3.3, 3.2}, {-1, 2.3}, {-3.5, 0.5}, {-1.2, -2.8}}}, ControlType -> None}, {{$CellContext`cubiclePoly$$, {{-1, -3.5}, {-1, \ -0.5}, {0, -0.5}, {0, -1}, {-0.5, -1}, {-0.5, -3.5}, {1.5, -3.5}, { 1.5, -3}, {2, -3}, {2, -3.5}, {3.5, -3.5}, {3.5, -1}, { 2, -1}, {2, -1.5}, {1.5, -1.5}, {1.5, -0.5}, {3.5, -0.5}, { 3.5, 2}, {1.5, 2}, {1.5, 2.5}, {3.5, 2.5}, {3.5, 3.5}, {-1, 3.5}, {-1, 2.5}, {0.5, 2.5}, { 0.5, 2}, {-1.5, 2}, {-1.5, 3.5}, {-3.5, 3.5}, {-3.5, 0.5}, {-1.5, 0.5}, {-1.5, 0}, {-3.5, 0}, {-3.5, -2}, {-2, -2}, {-2, -3.5}}}, ControlType -> None}, {{$CellContext`ptsOld$$, {{1, 0}, {2, 2}, {0, 0}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, -10}, {-10, \ -10}, {-10, -10}, {-10, -10}}}, ControlType -> None}, {{$CellContext`pts$$, {{1, 0}, {2, 2}, {0, 0}, { 0, -1.5}, {-2, -1}, {-1.5, 0.5}, {-0.6, -1}, {-2.5, 0.5}, {-2, 1}, {-1.25, 3}}}, {-4, -4}, {4, 4}, ControlType -> Locator, Appearance -> None}}, "Options" :> {FrameMargins -> -5}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{471., {267., 273.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, Initialization:>({$CellContext`visiblePolys[ Pattern[$CellContext`polys, Blank[]], Pattern[$CellContext`pm, { Pattern[$CellContext`x, Blank[]], Pattern[$CellContext`y, Blank[]]}]] := Module[{$CellContext`p, $CellContext`listofAllLines, \ $CellContext`infiniteLine, $CellContext`length = Length[$CellContext`polys], $CellContext`orderedList, \ $CellContext`sortedList, $CellContext`jList = {}, \ $CellContext`visibleList = {}, $CellContext`wi = False, $CellContext`wip = False, $CellContext`lvLine, $CellContext`a, $CellContext`b, \ $CellContext`c, $CellContext`abcList, $CellContext`ba, \ $CellContext`bc, $CellContext`pb, $CellContext`pbaAngle, \ $CellContext`pbcAngle, $CellContext`startJlistInt, $CellContext`m, \ $CellContext`bcVisiInt, $CellContext`gLine, $CellContext`giList, \ $CellContext`giPoint, $CellContext`giLine, $CellContext`abNotGlaInt, \ $CellContext`abNotVisInt, $CellContext`bcNotVisInt, $CellContext`i = 1, $CellContext`prevA, $CellContext`prevB, \ $CellContext`prevC, $CellContext`postA, $CellContext`postB, \ $CellContext`postC, $CellContext`tb, $CellContext`index, \ $CellContext`theta, $CellContext`gFlag = False, $CellContext`pprevbAngle, $CellContext`pbAngle}, \ $CellContext`p = $CellContext`pm; Table[ Map[If[ $CellContext`pointOnSegmentQ[#, $CellContext`pm], \ $CellContext`p = $CellContext`pm - 0.00001 $CellContext`normalVector[#]]& , $CellContext`lineList[ Part[$CellContext`polys, $CellContext`k]]], \ {$CellContext`k, 1, $CellContext`length}]; If[ Apply[Or, Table[ Apply[Or, Map[($CellContext`index = Flatten[ Position[ Part[$CellContext`polys, $CellContext`k], #]]; \ $CellContext`pm == #)& , Part[$CellContext`polys, $CellContext`k]]], \ {$CellContext`k, 1, $CellContext`length}]], $CellContext`p = \ $CellContext`pm + 0.00001 (Flatten[ Part[$CellContext`polys, 1, $CellContext`index - 1]] + Flatten[ Part[$CellContext`polys, 1, $CellContext`index + 1]])]; $CellContext`infiniteLine = {$CellContext`p, { 0.11, 0} + { Part[ MaximalBy[ Flatten[$CellContext`polys, 1], First], 1, 1], $CellContext`y}}; $CellContext`orderedList = Table[ If[ $CellContext`testpoint[ Part[$CellContext`polys, $CellContext`i], \ $CellContext`p], Reverse[ Part[$CellContext`polys, $CellContext`i]], Part[$CellContext`polys, $CellContext`i]], \ {$CellContext`i, 1, Length[$CellContext`polys], 1}]; $CellContext`listofAllLines = Flatten[ Join[ Map[$CellContext`lineList[#]& , \ $CellContext`orderedList]], 1]; $CellContext`sortedList = Sort[ Flatten[ Join[ Map[$CellContext`vertexList[ N[#]]& , $CellContext`orderedList]], 1], $CellContext`angleSortCond[$CellContext`p, #, #2]& ]; \ $CellContext`m = Length[$CellContext`sortedList]; Map[If[ $CellContext`SegmentIntersectionQ[{$CellContext`\ infiniteLine, #}], AppendTo[$CellContext`jList, Reverse[#]]]& , $CellContext`listofAllLines]; \ $CellContext`jList = Sort[$CellContext`jList, \ $CellContext`distSortCond[$CellContext`infiniteLine, #, #2, \ $CellContext`p]& ]; $CellContext`lvLine = First[$CellContext`jList]; Table[ If[ $CellContext`SegmentIntersectionQ[{$CellContext`lvLine, Part[$CellContext`jList, $CellContext`i]}], \ $CellContext`startJlistInt = N[ $CellContext`LineIntersectionPoint[{$CellContext`\ lvLine, Part[$CellContext`jList, $CellContext`i]}]]; If[ $CellContext`noIntersection[$CellContext`p, \ $CellContext`startJlistInt, $CellContext`listofAllLines], AppendTo[$CellContext`visibleList, \ $CellContext`startJlistInt]; If[Part[$CellContext`startJlistInt, 2] > Part[$CellContext`p, 2], $CellContext`lvLine = Part[$CellContext`jList, $CellContext`i]]]], \ {$CellContext`i, 1, Length[$CellContext`jList]}]; For[$CellContext`i = 1, $CellContext`i <= $CellContext`m, Increment[$CellContext`i], {$CellContext`a, \ $CellContext`b, $CellContext`c} = Part[$CellContext`sortedList, $CellContext`i, Span[ 1, 3]]; {$CellContext`prevA, $CellContext`prevB, \ $CellContext`prevC} = If[$CellContext`i != 1, Part[$CellContext`sortedList, $CellContext`i - 1, Span[1, 3]], Part[$CellContext`sortedList, $CellContext`m, Span[ 1, 3]]]; {$CellContext`postA, $CellContext`postB, \ $CellContext`postC} = If[$CellContext`i != $CellContext`m, Part[$CellContext`sortedList, $CellContext`i + 1, Span[1, 3]], Part[$CellContext`sortedList, 1, Span[ 1, 3]]]; $CellContext`pbAngle = \ $CellContext`getAngle[{$CellContext`p, $CellContext`b}]; \ $CellContext`pprevbAngle = $CellContext`getAngle[{$CellContext`p, \ $CellContext`prevB}]; $CellContext`tb = N[ If[ $CellContext`pointOnSegmentQ[{$CellContext`p, \ $CellContext`postB}, $CellContext`b], If[ Or[$CellContext`postB == $CellContext`a, \ $CellContext`pbaAngle <= Pi/3], $CellContext`b + 0.00001 $CellContext`normalVector[{$CellContext`a, \ $CellContext`p}], $CellContext`b - 0.00001 \ $CellContext`normalVector[{$CellContext`postB, $CellContext`p}]], \ $CellContext`b]]; $CellContext`abcList = {$CellContext`a, \ $CellContext`tb, $CellContext`c}; $CellContext`ba = {$CellContext`b, \ $CellContext`a}; $CellContext`bc = {$CellContext`b, $CellContext`c}; \ $CellContext`pb = {$CellContext`p, $CellContext`b}; \ $CellContext`pbaAngle = Re[ $CellContext`getClockwiseAngle[$CellContext`p, \ $CellContext`b, $CellContext`a]]; $CellContext`pbcAngle = Re[ $CellContext`getClockwiseAngle[$CellContext`p, \ $CellContext`b, $CellContext`c]]; If[ $CellContext`intersectInteriorQRev2[$CellContext`p, \ $CellContext`abcList], $CellContext`wi = False, If[ Or[$CellContext`i == 1, Not[ $CellContext`pointOnSegmentQ[$CellContext`pb, \ $CellContext`a]]], If[ $CellContext`noIntersection[$CellContext`p, \ $CellContext`b, $CellContext`jList], If[$CellContext`i != 1, If[$CellContext`pbAngle != $CellContext`pprevbAngle, \ $CellContext`wi = True, If[ Or[$CellContext`b == $CellContext`prevA, \ $CellContext`b == $CellContext`prevC, $CellContext`b == \ $CellContext`postA, $CellContext`b == $CellContext`postC, \ $CellContext`gFlag], $CellContext`wi = True, $CellContext`wi = False]], $CellContext`wi = True], $CellContext`wi = False], If[$CellContext`wip, If[ $CellContext`noIntersection[$CellContext`b, \ $CellContext`a, $CellContext`jList], $CellContext`wi = True, $CellContext`wi = False], $CellContext`wi = False]]]; If[$CellContext`wi, If[ $CellContext`SegmentIntersectionQ[{$CellContext`lvLine,\ $CellContext`bc}], $CellContext`bcVisiInt = N[ $CellContext`LineIntersectionPoint[{$CellContext`\ lvLine, $CellContext`bc}]]; If[ $CellContext`noIntersection[$CellContext`p, \ $CellContext`bcVisiInt, $CellContext`listofAllLines], AppendTo[$CellContext`visibleList, \ $CellContext`bcVisiInt]]]; If[ $CellContext`glancingBlow[$CellContext`p, \ $CellContext`abcList], $CellContext`gFlag = False, $CellContext`gFlag = True]; If[ And[$CellContext`gFlag, Not[ $CellContext`pointOnSegmentQ[$CellContext`pb, \ $CellContext`prevB]]], $CellContext`gLine = \ $CellContext`extendedLine[$CellContext`p, $CellContext`tb]; \ $CellContext`giList = Sort[ DeleteCases[ Map[If[ Or[ $CellContext`SegmentIntersectionQ[{$CellContext`\ gLine, #}], And[$CellContext`b != Part[#, 2], $CellContext`pointOnSegmentQ[$CellContext`gLine, Part[#, 2]]], And[$CellContext`b != Part[#, 1], $CellContext`pointOnSegmentQ[$CellContext`gLine, Part[#, 1]]]], If[ $CellContext`SegmentIntersectionQ[{$CellContext`\ gLine, #}], { N[ $CellContext`LineIntersectionPoint[{$CellContext`\ gLine, #}]], #}, If[ And[$CellContext`b != Part[#, 2], $CellContext`pointOnSegmentQ[$CellContext`gLine, Part[#, 2]]], { Part[#, 2], #}, If[ And[$CellContext`b != Part[#, 1], $CellContext`pointOnSegmentQ[$CellContext`gLine, Part[#, 1]]], { Part[#, 1], #}]]]]& , DeleteCases[ DeleteCases[$CellContext`listofAllLines, \ {$CellContext`b, Blank[]}], { Blank[], $CellContext`b}]], Null], EuclideanDistance[$CellContext`p, Part[#, 1]] < EuclideanDistance[$CellContext`p, Part[#2, 1]]& ]; If[$CellContext`giList != {}, $CellContext`giPoint = Part[$CellContext`giList, 1, 1]; $CellContext`giLine = Part[$CellContext`giList, 1, 2]; If[ Or[ And[ $CellContext`pointOnSegmentQ[$CellContext`lvLine, \ $CellContext`giPoint], Chop[ $CellContext`getAngle[$CellContext`pb]] != 0], And[$CellContext`i == 1, $CellContext`pbaAngle <= Pi/2], And[ $CellContext`SegmentIntersectionQ[{$CellContext`\ gLine, $CellContext`lvLine}], \ $CellContext`LineIntersectionPoint[{$CellContext`gLine, \ $CellContext`lvLine}] == $CellContext`giPoint], $CellContext`giPoint == Part[$CellContext`lvLine, 2]], $CellContext`visibleList = Join[$CellContext`visibleList, \ {$CellContext`giPoint, $CellContext`b}]; $CellContext`lvLine = \ $CellContext`ba, $CellContext`visibleList = Join[$CellContext`visibleList, {$CellContext`b, \ $CellContext`giPoint}]; $CellContext`lvLine = $CellContext`giLine]], If[$CellContext`pbAngle != $CellContext`pprevbAngle, AppendTo[$CellContext`visibleList, $CellContext`b]]; \ $CellContext`lvLine = $CellContext`ba; Table[ If[ $CellContext`SegmentIntersectionQ[{$CellContext`ba, Part[$CellContext`jList, $CellContext`i]}], \ $CellContext`abNotGlaInt = N[ $CellContext`LineIntersectionPoint[{$CellContext`\ ba, Part[$CellContext`jList, $CellContext`i]}]]; If[ $CellContext`noIntersection[$CellContext`p, \ $CellContext`abNotGlaInt, $CellContext`listofAllLines], AppendTo[$CellContext`visibleList, \ $CellContext`abNotGlaInt]; $CellContext`lvLine = Part[$CellContext`jList, $CellContext`i]]], \ {$CellContext`i, 1, Length[$CellContext`jList], 1}]; Null], If[ $CellContext`SegmentIntersectionQ[{$CellContext`pb, \ $CellContext`lvLine}], If[$CellContext`pbaAngle < $CellContext`pbcAngle, If[ Not[ $CellContext`leftOrRight[$CellContext`p, \ $CellContext`b, $CellContext`a]], If[ $CellContext`SegmentIntersectionQ[{$CellContext`\ lvLine, $CellContext`ba}], $CellContext`abNotVisInt = N[ $CellContext`LineIntersectionPoint[{$CellContext`\ lvLine, $CellContext`ba}]]; If[ $CellContext`noIntersection[$CellContext`p, \ $CellContext`abNotVisInt, $CellContext`listofAllLines], AppendTo[$CellContext`visibleList, \ $CellContext`abNotVisInt]; $CellContext`lvLine = $CellContext`ba]]]]; If[$CellContext`pbcAngle < $CellContext`pbaAngle, If[ Not[ $CellContext`leftOrRight[$CellContext`p, \ $CellContext`b, $CellContext`c]], If[ $CellContext`SegmentIntersectionQ[{$CellContext`\ lvLine, $CellContext`bc}], $CellContext`bcNotVisInt = N[ $CellContext`LineIntersectionPoint[{$CellContext`\ lvLine, $CellContext`bc}]]; If[ $CellContext`noIntersection[$CellContext`p, \ $CellContext`bcNotVisInt, $CellContext`listofAllLines], AppendTo[$CellContext`visibleList, \ $CellContext`bcNotVisInt]; $CellContext`lvLine = $CellContext`bc]]]], Map[If[ $CellContext`SegmentIntersectionQ[{#, \ $CellContext`lvLine}], AppendTo[$CellContext`visibleList, $CellContext`LineIntersectionPoint[{#, \ $CellContext`lvLine}]]; $CellContext`lvLine = #]& , \ $CellContext`jList]]; Null]; $CellContext`wip = $CellContext`wi; If[$CellContext`pbaAngle < Pi, AppendTo[$CellContext`jList, $CellContext`ba]]; If[$CellContext`pbcAngle < Pi, AppendTo[$CellContext`jList, $CellContext`bc]]; \ $CellContext`jList = DeleteCases[$CellContext`jList, { Blank[], $CellContext`b}]; Null]; $CellContext`visibleList], \ $CellContext`pointOnSegmentQ[{{ Pattern[$CellContext`x1, Blank[]], Pattern[$CellContext`y1, Blank[]]}, { Pattern[$CellContext`x2, Blank[]], Pattern[$CellContext`y2, Blank[]]}}, { Pattern[$CellContext`x3, Blank[]], Pattern[$CellContext`y3, Blank[]]}] := Module[{$CellContext`ABv = {$CellContext`x2 - $CellContext`x1, \ $CellContext`y2 - $CellContext`y1, 0}, $CellContext`ACv = {$CellContext`x3 - \ $CellContext`x1, $CellContext`y3 - $CellContext`y1, 0}, $CellContext`Kac, $CellContext`Kab}, If[ Apply[And, Map[Chop[#] == 0& , Cross[$CellContext`ABv, $CellContext`ACv]]], \ $CellContext`Kac = Dot[$CellContext`ABv, $CellContext`ACv]; $CellContext`Kab = Dot[$CellContext`ABv, $CellContext`ABv]; If[$CellContext`Kac < 0, False, If[$CellContext`Kac > $CellContext`Kab, False, If[ 0 < $CellContext`Kac < $CellContext`Kab, True, False]]], False]], $CellContext`normalVector[{{ Pattern[$CellContext`x2, Blank[]], Pattern[$CellContext`y2, Blank[]]}, { Pattern[$CellContext`x1, Blank[]], Pattern[$CellContext`y1, Blank[]]}}] := Normalize[{-$CellContext`y2 + $CellContext`y1, $CellContext`x2 - \ $CellContext`x1}], $CellContext`lineList[ Pattern[$CellContext`list, Blank[]]] := Partition[ Append[$CellContext`list, First[$CellContext`list]], 2, 1], $CellContext`testpoint[ Pattern[$CellContext`poly, Blank[]], Pattern[$CellContext`pt, Blank[]]] := Round[Total[ Mod[ (# - RotateRight[#]& )[ Map[ Apply[ArcTan, $CellContext`pt - #]& , \ $CellContext`poly]], 2 Pi, -Pi]]/(2 Pi)] != 0, $CellContext`vertexList[ Pattern[$CellContext`list, Blank[]]] := Partition[ Join[$CellContext`list, Part[$CellContext`list, Span[1, 2]]], 3, 1], $CellContext`angleSortCond[ Pattern[$CellContext`point, Blank[]], Pattern[$CellContext`l1, Blank[]], Pattern[$CellContext`l2, Blank[]]] := Module[{$CellContext`a = \ $CellContext`getAngle[{$CellContext`point, Part[$CellContext`l1, 2]}], $CellContext`b = \ $CellContext`getAngle[{$CellContext`point, Part[$CellContext`l2, 2]}], $CellContext`c = Norm[$CellContext`point - Part[$CellContext`l1, 2]], $CellContext`d = Norm[$CellContext`point - Part[$CellContext`l2, 2]]}, Or[$CellContext`a < $CellContext`b, And[$CellContext`a == $CellContext`b, $CellContext`c < \ $CellContext`d]]], $CellContext`getAngle[{{ Pattern[$CellContext`x1, Blank[]], Pattern[$CellContext`y1, Blank[]]}, { Pattern[$CellContext`x2, Blank[]], Pattern[$CellContext`y2, Blank[]]}}] := Mod[ ArcTan[$CellContext`x2 - $CellContext`x1, $CellContext`y2 - \ $CellContext`y1], 2 Pi], $CellContext`SegmentIntersectionQ[{ Pattern[$CellContext`p1, { Pattern[$CellContext`a, Blank[]], Pattern[$CellContext`b, Blank[]]}], Pattern[$CellContext`p2, { Pattern[$CellContext`c, Blank[]], Pattern[$CellContext`d, Blank[]]}]}] := Module[{$CellContext`roundoff = 1.*^-7}, If[Chop[ Det[{$CellContext`a - $CellContext`b, $CellContext`c - \ $CellContext`d}]] == 0, False, Module[{$CellContext`p = Round[ $CellContext`LineIntersectionPoint[{$CellContext`p1, \ $CellContext`p2}], $CellContext`roundoff]}, And[ 0 < $CellContext`\[Lambda][$CellContext`p1][$CellContext`p]\ < 1, 0 < $CellContext`\[Lambda][$CellContext`p2][$CellContext`p] < 1, Not[ Or[$CellContext`p == Round[$CellContext`a, $CellContext`roundoff], \ $CellContext`p == Round[$CellContext`b, $CellContext`roundoff], \ $CellContext`p == Round[$CellContext`c, $CellContext`roundoff], \ $CellContext`p == Round[$CellContext`d, $CellContext`roundoff]]]]]]], \ $CellContext`LineIntersectionPoint[{{ Pattern[$CellContext`a, Blank[]], Pattern[$CellContext`b, Blank[]]}, { Pattern[$CellContext`c, Blank[]], Pattern[$CellContext`d, Blank[]]}}] := ( Det[{$CellContext`a, $CellContext`b}] ($CellContext`c - \ $CellContext`d) - Det[{$CellContext`c, $CellContext`d}] ($CellContext`a - \ $CellContext`b))/ Det[{$CellContext`a - $CellContext`b, $CellContext`c - \ $CellContext`d}], $CellContext`\[Lambda][{ Pattern[$CellContext`a, Blank[]], Pattern[$CellContext`b, Blank[]]}][ Pattern[$CellContext`p, Blank[]]] := Dot[$CellContext`a - $CellContext`p, $CellContext`a - \ $CellContext`b]/ Dot[$CellContext`a - $CellContext`b, $CellContext`a - \ $CellContext`b], $CellContext`distSortCond[ Pattern[$CellContext`line, Blank[]], Pattern[$CellContext`l1, Blank[]], Pattern[$CellContext`l2, Blank[]], Pattern[$CellContext`point, Blank[]]] := Module[{$CellContext`a = EuclideanDistance[ $CellContext`LineIntersectionPoint[ Chop[{$CellContext`line, $CellContext`l1}]], \ $CellContext`point], $CellContext`b = EuclideanDistance[ $CellContext`LineIntersectionPoint[ Chop[{$CellContext`line, $CellContext`l2}]], \ $CellContext`point]}, $CellContext`a < $CellContext`b], \ $CellContext`noIntersection[ Pattern[$CellContext`p1, Blank[]], Pattern[$CellContext`p2, Blank[]], Pattern[$CellContext`linelist, Blank[]]] := Apply[Nor, Map[$CellContext`SegmentIntersectionQ[{{$CellContext`p1, \ $CellContext`p2}, #}]& , $CellContext`linelist]], \ $CellContext`getClockwiseAngle[ Pattern[$CellContext`p1, Blank[]], Pattern[$CellContext`p2, Blank[]], Pattern[$CellContext`p3, Blank[]]] := Module[{$CellContext`a = $CellContext`p3 - $CellContext`p2, \ $CellContext`b = $CellContext`p1 - $CellContext`p2}, AppendTo[$CellContext`a, 0]; AppendTo[$CellContext`b, 0]; If[Part[ Cross[$CellContext`a, $CellContext`b], 3] < 0, Chop[2 Pi - VectorAngle[$CellContext`a, $CellContext`b]], Chop[ VectorAngle[$CellContext`a, $CellContext`b]]]], \ $CellContext`intersectInteriorQRev2[ Pattern[$CellContext`p, Blank[]], { Pattern[$CellContext`w1, Blank[]], Pattern[$CellContext`w2, Blank[]], Pattern[$CellContext`w3, Blank[]]}] := Module[{$CellContext`a = \ $CellContext`getClockwiseAngle[$CellContext`w1, $CellContext`w2, \ $CellContext`w3], $CellContext`b = \ $CellContext`getClockwiseAngle[$CellContext`p, $CellContext`w2, \ $CellContext`w3]}, If[$CellContext`b == 0, $CellContext`b = 6.28319]; $CellContext`a > $CellContext`b], \ $CellContext`glancingBlow[ Pattern[$CellContext`a, Blank[]], { Pattern[$CellContext`p1, Blank[]], Pattern[$CellContext`p2, Blank[]], Pattern[$CellContext`p3, Blank[]]}] := Xor[ $CellContext`reflex[$CellContext`p1, $CellContext`p2, \ $CellContext`a], $CellContext`reflex[$CellContext`p3, $CellContext`p2, \ $CellContext`a]], $CellContext`reflex[{ Pattern[$CellContext`x1, Blank[]], Pattern[$CellContext`y1, Blank[]]}, { Pattern[$CellContext`x2, Blank[]], Pattern[$CellContext`y2, Blank[]]}, { Pattern[$CellContext`x3, Blank[]], Pattern[$CellContext`y3, Blank[]]}] := Chop[ Det[{{1, $CellContext`x1, $CellContext`y1}, { 1, $CellContext`x2, $CellContext`y2}, { 1, $CellContext`x3, $CellContext`y3}}]] > 0, $CellContext`extendedLine[ Pattern[$CellContext`p1, Blank[]], Pattern[$CellContext`p2, Blank[]]] := {$CellContext`p1, $CellContext`p1 + 40 Normalize[$CellContext`p2 - $CellContext`p1]}, \ $CellContext`leftOrRight[ Pattern[$CellContext`a, { Pattern[$CellContext`x1, Blank[]], Pattern[$CellContext`y1, Blank[]]}], Pattern[$CellContext`b, { Pattern[$CellContext`x2, Blank[]], Pattern[$CellContext`y2, Blank[]]}], Pattern[$CellContext`p, { Pattern[$CellContext`x, Blank[]], Pattern[$CellContext`y, Blank[]]}]] := ($CellContext`x - $CellContext`x1) \ ($CellContext`y2 - $CellContext`y1) - ($CellContext`y - \ $CellContext`y1) ($CellContext`x2 - $CellContext`x1) >= 0, Attributes[PlotRange] = {ReadProtected}}; Typeset`initDone$$ = True), SynchronousInitialization->True, UndoTrackedVariables:>{Typeset`show$$, Typeset`bookmarkMode$$}, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.7797032225217457`*^9}, CellID->1678307939] }, {4}]]