My Haskell implementation for some geometric queries, starting from this Geometric Intro problem set by Katherine. Haskell code is in PointsAndLines.hs
, Polygons.hs
and Gradients.hs
.
It also contains a JavaScript visualizer for some of the functions.
Mostly working on gradients for now. Here's what I have so far, although imperfect and sometimes oscillates.
- input a point
p
and a segmentxy
:- move
p
to decrease distance between the two - move
xy
to decrease distance between the two - rotate
xy
around its midpoint to decrease distance
- move
- input a point
p
, a segmentxy
, and a pointc
:- rotate
xy
aroundc
to decrease distance betweenxy
andp
- rotate
- input a point
p
and a pair of segments (call its
for here)- move
p
to decrease distance betweenp
ands
- move
s
to decrease distance betweenp
ands
- move
(note: haven't tried running the binary from a computer without GHC installed.)
From command line, run ./main
to start the server. Then in a browser go to localhost:9200
If any change is made to the Haskell code, need to recompile with ghc --make main.hs
to update the change in visualizer.
Alternatively, load main.hs
into ghci and run the main
function.
p.s. Please don't change any function names in Haskell code.
To make elements: press 1
, 2
or 3
to start recording.
1
: record a point. Click on where to place it.
2
: record a segment. Click twice to specify its endpoints.
3
: record a polygon. Click to specify its vertices in order. When done, press c
(close).
Or can also manually enter elements from the input field at the bottom. Format: points separated by commas, each point in form [x,y]
.
1 point: point;
2 points: segment;
3 or more points: polygon
When not recording, click on an element to toggle selection. If clicked at places where elements overlap, it toggles all elements underneath. Selected elements are listed in order on the left of the canvas.
Press d
to delete selected elements.
Click on a function on top left (whose required arguments are also listed).
Press 0
to feed currently selected list of elements as input to the selected function. Order of arguments matter (otherwise it crashes).
Note: some results show up as new elements added onto the canvas, but some only show as text output in the console.
Click on a function on top left (whose required arguments are also listed).
Press v
to make 1 step of descent.
Press b
to descend until either (1) it converges, or (2) reaches max number of steps (500).
If input is a point and a segment, or a point of two segments, can also press g
to show a rough graph of distance on rotation of segment(s).