Skip to content

Instantly share code, notes, and snippets.

@lucainnocenti
Last active August 29, 2020 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucainnocenti/c92107db0d0c9980839f72c3bc99944b to your computer and use it in GitHub Desktop.
Save lucainnocenti/c92107db0d0c9980839f72c3bc99944b to your computer and use it in GitHub Desktop.
Dynamic visualisation of point-plane duality in convex geometry
DynamicModule[{pts={{1,1}}, activePoint=None},
EventHandler[
Dynamic @ Show[
Graphics[{
PointSize@0.04,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"]]]
]}
]
]
@lucainnocenti
Copy link
Author

lucainnocenti commented Aug 29, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment