Last active
August 29, 2020 22:03
-
-
Save lucainnocenti/c92107db0d0c9980839f72c3bc99944b to your computer and use it in GitHub Desktop.
Dynamic visualisation of point-plane duality in convex geometry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DynamicModule[{pts={{1,1}}, activePoint=None}, | |
EventHandler[ | |
Dynamic @ Show[ | |
Graphics[{ | |
[email protected],Dynamic@Point@pts, | |
Circle[], | |
If[activePoint =!= None, | |
{Blue, Point @ pts[[activePoint]]}, {} | |
], | |
InfiniteLine[# / Norm[#]^2, Cross @ #] & /@ pts // Dynamic | |
}, | |
Axes->True,AxesOrigin->{0,0},Frame->False,PlotRange->ConstantArray[{-2,2},2], | |
GridLines->Automatic,AxesStyle->Directive[Large,Black] | |
] | |
], | |
{"MouseClicked":>(AppendTo[pts,MousePosition["Graphics"]]), | |
"MouseDown":>If[activePoint === None && Length @ pts > 0, | |
{#, Norm[MousePosition["Graphics"] - pts[[#]]]} & /@ Range @ Length @ pts // | |
First @* SortBy[Last] // If[ | |
(* if the closest point is close enough *) | |
#[[2]] < 0.1, | |
(* then mark which point we are moving *) | |
Set[activePoint, #[[1]]] | |
]& | |
], | |
"MouseUp":>If[activePoint =!= None, activePoint = None], | |
"MouseDragged":>If[activePoint =!= None, | |
Set[pts, ReplacePart[pts, activePoint -> MousePosition["Graphics"]]] | |
]} | |
] | |
] |
Author
lucainnocenti
commented
Aug 29, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment