GithubHelp home page GithubHelp logo

atyuwen / smallest-k-gon Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 1.0 6 KB

Implementation of Aggarwal's smallest circumscribing k-gon algorithm.

License: MIT License

C++ 100.00%
computational-geometry convex-hull particle-trimming

smallest-k-gon's People

Contributors

atyuwen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tcantenot

smallest-k-gon's Issues

sometimes simplify() doesn't work

hello,

following code produce wrong result (input pts are triangle vertices of ellipse):

build ok.
area 1.56072
after simplify 7.41516e+07
vertices (4):
-1.60482e+09, -7.90275e+07
0.382683, -0.46194
0.55557, -0.415735
0.707107, -0.353553

simplify(8) doesn't work correctly. It's ok after increasing simplify parameter to 18.

#include "convex.h"
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main(int, char**)
{
  ayw::convex hull;

  std::vector<ayw::float2> pts{ayw::float2(0.980785, -0.097545),
                               ayw::float2(0.980785, 0.097545),
                               ayw::float2(1.0, 0.0),
                               ayw::float2(0.92388, -0.191342),
                               ayw::float2(0.980785, 0.097545),
                               ayw::float2(0.980785, -0.097545),
                               ayw::float2(0.92388, -0.191342),
                               ayw::float2(0.92388, 0.191342),
                               ayw::float2(0.980785, 0.097545),
                               ayw::float2(0.83147, -0.277785),
                               ayw::float2(0.92388, 0.191342),
                               ayw::float2(0.92388, -0.191342),
                               ayw::float2(0.83147, -0.277785),
                               ayw::float2(0.83147, 0.277785),
                               ayw::float2(0.92388, 0.191342),
                               ayw::float2(0.707107, -0.353553),
                               ayw::float2(0.83147, 0.277785),
                               ayw::float2(0.83147, -0.277785),
                               ayw::float2(0.707107, -0.353553),
                               ayw::float2(0.707107, 0.353553),
                               ayw::float2(0.83147, 0.277785),
                               ayw::float2(0.55557, -0.415735),
                               ayw::float2(0.707107, 0.353553),
                               ayw::float2(0.707107, -0.353553),
                               ayw::float2(0.55557, -0.415735),
                               ayw::float2(0.55557, 0.415735),
                               ayw::float2(0.707107, 0.353553),
                               ayw::float2(0.382683, -0.46194),
                               ayw::float2(0.55557, 0.415735),
                               ayw::float2(0.55557, -0.415735),
                               ayw::float2(0.382683, -0.46194),
                               ayw::float2(0.382683, 0.46194),
                               ayw::float2(0.55557, 0.415735),
                               ayw::float2(0.19509, -0.490393),
                               ayw::float2(0.382683, 0.46194),
                               ayw::float2(0.382683, -0.46194),
                               ayw::float2(0.19509, -0.490393),
                               ayw::float2(0.19509, 0.490393),
                               ayw::float2(0.382683, 0.46194),
                               ayw::float2(0.0, -0.5),
                               ayw::float2(0.19509, 0.490393),
                               ayw::float2(0.19509, -0.490393),
                               ayw::float2(0.0, -0.5),
                               ayw::float2(0.0, 0.5),
                               ayw::float2(0.19509, 0.490393),
                               ayw::float2(-0.19509, -0.490393),
                               ayw::float2(0.0, 0.5),
                               ayw::float2(0.0, -0.5),
                               ayw::float2(-0.19509, -0.490393),
                               ayw::float2(-0.19509, 0.490393),
                               ayw::float2(0.0, 0.5),
                               ayw::float2(-0.382683, -0.46194),
                               ayw::float2(-0.19509, 0.490393),
                               ayw::float2(-0.19509, -0.490393),
                               ayw::float2(-0.382683, -0.46194),
                               ayw::float2(-0.382683, 0.46194),
                               ayw::float2(-0.19509, 0.490393),
                               ayw::float2(-0.55557, -0.415735),
                               ayw::float2(-0.382683, 0.46194),
                               ayw::float2(-0.382683, -0.46194),
                               ayw::float2(-0.55557, -0.415735),
                               ayw::float2(-0.55557, 0.415735),
                               ayw::float2(-0.382683, 0.46194),
                               ayw::float2(-0.707107, -0.353553),
                               ayw::float2(-0.55557, 0.415735),
                               ayw::float2(-0.55557, -0.415735),
                               ayw::float2(-0.707107, -0.353553),
                               ayw::float2(-0.707107, 0.353553),
                               ayw::float2(-0.55557, 0.415735),
                               ayw::float2(-0.83147, -0.277785),
                               ayw::float2(-0.707107, 0.353553),
                               ayw::float2(-0.707107, -0.353553),
                               ayw::float2(-0.83147, -0.277785),
                               ayw::float2(-0.83147, 0.277785),
                               ayw::float2(-0.707107, 0.353553),
                               ayw::float2(-0.92388, -0.191342),
                               ayw::float2(-0.83147, 0.277785),
                               ayw::float2(-0.83147, -0.277785),
                               ayw::float2(-0.92388, -0.191342),
                               ayw::float2(-0.92388, 0.191342),
                               ayw::float2(-0.83147, 0.277785),
                               ayw::float2(-0.980785, -0.097545),
                               ayw::float2(-0.92388, 0.191342),
                               ayw::float2(-0.92388, -0.191342),
                               ayw::float2(-0.980785, -0.097545),
                               ayw::float2(-0.980785, 0.097545),
                               ayw::float2(-0.92388, 0.191342),
                               ayw::float2(-0.980785, 0.097545),
                               ayw::float2(-0.980785, -0.097545),
                               ayw::float2(-1.0, 0.0)};

  if (hull.build(pts.begin(), pts.end())) {
    printf("build ok.\n");
  }
  printf("area %g\n", hull.area());
  hull.simplify(8);
  printf("after simplify %g\n", hull.area());
  printf("vertices (%d):\n", hull.vertices.size());
  for (const auto& v : hull.vertices) {
    printf("%g, %g\n", v.x, v.y);
  }
  return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.