kth-competitive-programming / kactl

KTH Algorithm Competition Template Library (... eller KTHs AC-tillverkande lapp)
2.69k stars 711 forks source link

Potential geometry things to add #137

Open Chillee opened 4 years ago

Chillee commented 4 years ago

I'd like to cram as much geometry as possible into KACTL. Perhaps not necessarily included by default, but some of these things would be nice to have. Taking lots of these from https://github.com/spaghetti-source/algorithm/tree/master/geometry

simonlindholm commented 4 years ago

This a nice goal.

number of lattice points below a line.

We sort of have this in the number theory chapter (modsum).

hockyy commented 11 months ago

Might be useful: https://github.com/hockyy/kactl/blob/main/content/geometry/PolygonStab.h https://github.com/hockyy/kactl/blob/main/content/geometry/AllPairPolygonStab.h https://github.com/hockyy/kactl/blob/main/content/geometry/CircleCover.h https://github.com/hockyy/kactl/blob/main/content/geometry/Visualize.h https://github.com/hockyy/kactl/blob/main/content/geometry/onionDecomposition.h https://github.com/hockyy/kactl/blob/main/content/geometry/RotationalSwap.h https://github.com/hockyy/kactl/blob/main/content/geometry/PolygonCount.h https://github.com/hockyy/kactl/blob/main/content/geometry/PolygonTriangulation.h https://github.com/hockyy/kactl/blob/main/content/geometry/TriangleCount.h https://github.com/hockyy/kactl/blob/main/content/geometry/CircleUnion.h

hockyy commented 11 months ago

Tangent Circle Idea: Signature:

typedef pair<P, P> Line
// Returns the center of the tangent circle
P tangentCircle(Line a, Line b, double r) {
  P o = intersect(a, b);
  double agl = (b - o).angle() - (a - o).angle()
  // Normalize this
  if(agl > PI) agl = 2 * PI - agl;
  P middle = a; middle.rotate(agl);
  // If this method fails, lets just do (a - o).unit() + (b - o).unit()
  middle = middle.unit() * (r / sin(agl / 2));
  return middle;
}