(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 12.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 11596, 266] NotebookOptionsPosition[ 11064, 249] NotebookOutlinePosition[ 11411, 264] CellTagsIndexPosition[ 11368, 261] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Distance from a point to the segment in the plane", "Subsubsection", CellChangeTimes->{{3.6799959272424545`*^9, 3.6799959714925165`*^9}, { 3.680187880725844*^9, 3.6801878813658447`*^9}, {3.6801879133558893`*^9, 3.6801879169258947`*^9}, {3.680188161286237*^9, 3.6801881618662376`*^9}, { 3.680188252966365*^9, 3.6801882616863775`*^9}, {3.6801883076464415`*^9, 3.680188367706526*^9}, {3.68018854232677*^9, 3.680188555186788*^9}, { 3.680188645956915*^9, 3.6801887056379986`*^9}, {3.6801889273883095`*^9, 3.680188930058313*^9}, {3.680189244018752*^9, 3.6801892847288094`*^9}, { 3.6801893580589123`*^9, 3.680189359168914*^9}, {3.680189420118999*^9, 3.6801894397690268`*^9}, {3.6801894730990734`*^9, 3.6801895437291718`*^9}, {3.6801900734149265`*^9, 3.680190086304945*^9}, { 3.6801901868050857`*^9, 3.6801903182252693`*^9}, {3.6801903981653814`*^9, 3.6801904303854265`*^9}, {3.680190477125492*^9, 3.6801906342057123`*^9}, { 3.680190665865756*^9, 3.6801906674757586`*^9}, {3.680191007020167*^9, 3.680191145620361*^9}, {3.680191176980405*^9, 3.6801912085004487`*^9}, { 3.680191325810613*^9, 3.680191412160734*^9}, {3.680191481260831*^9, 3.6801914918608456`*^9}, {3.6801915407409143`*^9, 3.6801916609210825`*^9}, {3.680191718901163*^9, 3.680191724661172*^9}, { 3.680191798661275*^9, 3.6801918474213433`*^9}, {3.6801920336116037`*^9, 3.680192064282647*^9}, {3.680192966581046*^9, 3.680193025731129*^9}, { 3.680193071341193*^9, 3.680193073591196*^9}, {3.6801931694413304`*^9, 3.6801931716413336`*^9}, {3.680193204341379*^9, 3.680193221921404*^9}, { 3.6801932521514463`*^9, 3.680193327011551*^9}, {3.6801934502717237`*^9, 3.680193456331732*^9}, {3.6801935486538625`*^9, 3.68019367538404*^9}, { 3.6802229763031774`*^9, 3.6802230363632617`*^9}, {3.6802233314036746`*^9, 3.680223369553728*^9}, {3.6802234540458508`*^9, 3.6802234659658675`*^9}, { 3.680223573446018*^9, 3.6802236119760723`*^9}, 3.6802245810804358`*^9, { 3.680224788350726*^9, 3.680224788880727*^9}, {3.68022576742412*^9, 3.68022578184414*^9}, 3.680225916668332*^9, {3.6802259495283785`*^9, 3.680225953498384*^9}, {3.680226611300305*^9, 3.6802266283203287`*^9}, 3.6807540138389945`*^9, {3.81062018635697*^9, 3.8106202074909267`*^9}},ExpressionUUID->"99b3be41-1c7d-4efb-9c0f-\ b7e6646fae69"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{"Input", ":", " ", RowBox[{ RowBox[{"point", " ", "T"}], " ", "\[Element]", " ", SuperscriptBox["\[DoubleStruckCapitalR]", "2"]}]}], ",", " ", RowBox[{ RowBox[{"segment", " ", "[", RowBox[{"\[Mu]", ",", "\[Nu]"}], "]"}], ";", " ", "\[IndentingNewLine]", RowBox[{"Output", ":", " ", "distance"}], ";", "\[IndentingNewLine]", RowBox[{"Submodules", ":", " ", RowBox[{"none", " ", "needed"}]}]}]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", StyleBox[ RowBox[{ RowBox[{ RowBox[{"dist", "[", RowBox[{"t_", ",", "Seg_"}], "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"lam", ",", RowBox[{"a", "=", RowBox[{"Seg", "[", RowBox[{"[", "1", "]"}], "]"}]}], ",", RowBox[{"b", "=", RowBox[{"Seg", "[", RowBox[{"[", "2", "]"}], "]"}]}], ",", "t0", ",", "dd"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], ".", RowBox[{"(", RowBox[{"t", "-", "a"}], ")"}]}], "<", "0"}], ",", RowBox[{ RowBox[{"t0", "=", "a"}], ";", RowBox[{"dd", "=", RowBox[{"Norm", "[", RowBox[{"t", "-", "a"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"a", "-", "b"}], ")"}], ".", RowBox[{"(", RowBox[{"t", "-", "b"}], ")"}]}], "<", "0"}], ",", RowBox[{ RowBox[{"t0", "=", "b"}], ";", RowBox[{"dd", "=", RowBox[{"Norm", "[", RowBox[{"t", "-", "b"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"lam", "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], ".", RowBox[{"(", RowBox[{"b", "-", "t"}], ")"}]}], "/", RowBox[{ RowBox[{"Norm", "[", RowBox[{"b", "-", "a"}], "]"}], "^", "2"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"t0", "=", RowBox[{ RowBox[{"lam", " ", "a"}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "lam"}], ")"}], "b"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"dd", "=", RowBox[{"Norm", "[", RowBox[{"t0", "-", "t"}], "]"}]}]}]}], "]"}]}], "]"}], ";", " ", "\[IndentingNewLine]", "dd"}]}], "\[IndentingNewLine]", "]"}]}], ";"}], FontSize->12]}]], "Input", CellChangeTimes->{{3.6799959272424545`*^9, 3.6799959714925165`*^9}, { 3.680187880725844*^9, 3.6801878813658447`*^9}, {3.6801879133558893`*^9, 3.6801879169258947`*^9}, {3.680188161286237*^9, 3.6801881618662376`*^9}, { 3.680188252966365*^9, 3.6801882616863775`*^9}, {3.6801883076464415`*^9, 3.680188367706526*^9}, {3.68018854232677*^9, 3.680188555186788*^9}, { 3.680188645956915*^9, 3.6801887056379986`*^9}, {3.6801889273883095`*^9, 3.680188930058313*^9}, {3.680189244018752*^9, 3.6801892847288094`*^9}, { 3.6801893580589123`*^9, 3.680189359168914*^9}, {3.680189420118999*^9, 3.6801894397690268`*^9}, {3.6801894730990734`*^9, 3.6801895437291718`*^9}, {3.6801900734149265`*^9, 3.680190086304945*^9}, { 3.6801901868050857`*^9, 3.6801903182252693`*^9}, {3.6801903981653814`*^9, 3.6801904303854265`*^9}, {3.680190477125492*^9, 3.6801906342057123`*^9}, { 3.680190665865756*^9, 3.6801906674757586`*^9}, {3.680191007020167*^9, 3.680191145620361*^9}, {3.680191176980405*^9, 3.6801912085004487`*^9}, { 3.680191325810613*^9, 3.680191412160734*^9}, {3.680191481260831*^9, 3.6801914918608456`*^9}, {3.6801915407409143`*^9, 3.6801916609210825`*^9}, {3.680191718901163*^9, 3.680191724661172*^9}, { 3.680191798661275*^9, 3.6801918474213433`*^9}, {3.6801920336116037`*^9, 3.680192064282647*^9}, {3.680192966581046*^9, 3.680193025731129*^9}, { 3.680193071341193*^9, 3.680193073591196*^9}, {3.6801931694413304`*^9, 3.6801931716413336`*^9}, {3.680193204341379*^9, 3.680193221921404*^9}, { 3.6801932521514463`*^9, 3.680193327011551*^9}, {3.6801934502717237`*^9, 3.680193456331732*^9}, {3.6801935486538625`*^9, 3.68019367538404*^9}, { 3.6802229763031774`*^9, 3.6802230363632617`*^9}, {3.6802233314036746`*^9, 3.680223369553728*^9}, {3.6802234540458508`*^9, 3.6802234659658675`*^9}, { 3.680223573446018*^9, 3.6802236119760723`*^9}, 3.6802245810804358`*^9, { 3.680224788350726*^9, 3.680224788880727*^9}, {3.68022576742412*^9, 3.68022578184414*^9}, 3.680225916668332*^9, {3.6802259495283785`*^9, 3.680225953498384*^9}, {3.680226611300305*^9, 3.6802266249203243`*^9}, { 3.6803192562639866`*^9, 3.680319259459597*^9}, {3.680323526767522*^9, 3.680323532564666*^9}, {3.681178043042704*^9, 3.6811780432927375`*^9}, { 3.8106202118283577`*^9, 3.8106202163739934`*^9}, {3.81062025582215*^9, 3.8106203134258823`*^9}, {3.810620365714431*^9, 3.8106203716352015`*^9}, { 3.8106204076250334`*^9, 3.810620442976353*^9}, 3.810643826124235*^9, { 3.822460741689346*^9, 3.8224607707244177`*^9}, {3.82248439614787*^9, 3.8224844031855288`*^9}},ExpressionUUID->"cd705a8e-6091-464f-8c7d-\ 77623549b419"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"Dmn", "[", RowBox[{"t_", ",", "xm_", ",", "ym_", ",", "xn_", ",", "yn_"}], "]"}], ":=", StyleBox[ RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"lam", ",", "a", ",", "b", ",", "t0", ",", "dd"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"a", "=", RowBox[{"{", RowBox[{"xm", ",", "ym"}], "}"}]}], ";", RowBox[{"b", "=", RowBox[{"{", RowBox[{"xn", ",", "yn"}], "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], ".", RowBox[{"(", RowBox[{"t", "-", "a"}], ")"}]}], "<", "0"}], ",", RowBox[{ RowBox[{"t0", "=", "a"}], ";", RowBox[{"dd", "=", RowBox[{"Norm", "[", RowBox[{"t", "-", "a"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"a", "-", "b"}], ")"}], ".", RowBox[{"(", RowBox[{"t", "-", "b"}], ")"}]}], "<", "0"}], ",", RowBox[{ RowBox[{"t0", "=", "b"}], ";", RowBox[{"dd", "=", RowBox[{"Norm", "[", RowBox[{"t", "-", "b"}], "]"}]}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"lam", "=", RowBox[{ RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a"}], ")"}], ".", RowBox[{"(", RowBox[{"b", "-", "t"}], ")"}]}], "/", RowBox[{ RowBox[{"Norm", "[", RowBox[{"b", "-", "a"}], "]"}], "^", "2"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"t0", "=", RowBox[{ RowBox[{"lam", " ", "a"}], "+", RowBox[{ RowBox[{"(", RowBox[{"1", "-", "lam"}], ")"}], "b"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Norm", "[", RowBox[{"t0", "-", "t"}], "]"}]}]}], "]"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], FontSize->12]}], StyleBox[";", FontSize->12]}]], "Input",ExpressionUUID->"44b0e393-2331-47b6-aacd-\ a2f15adfb3fb"] }, Open ]] }, WindowSize->{771, 762}, WindowMargins->{{-1621, Automatic}, {-149, Automatic}}, FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (April 8, 2019)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[580, 22, 2352, 32, 44, "Subsubsection",ExpressionUUID->"99b3be41-1c7d-4efb-9c0f-b7e6646fae69"], Cell[2935, 56, 5681, 119, 238, "Input",ExpressionUUID->"cd705a8e-6091-464f-8c7d-77623549b419"], Cell[8619, 177, 2429, 69, 162, "Input",ExpressionUUID->"44b0e393-2331-47b6-aacd-a2f15adfb3fb"] }, Open ]] } ] *)