Git Product home page Git Product logo

concavehullgenerator's Introduction

Concave hull generator

Unite all dots under the smallest possible area. It comes with a simple demo for the Unity game engine using just gizmos.

How it works

The program has only two easy steps:

  • Set a convex hull from a set of points (In the program they are the Node objects). It is very important that they all have an unique id value. The hull should be a list of Line objects (each line is defined by two Node objects). If you already have a set of lines you can skip the step (They don't need to form a convex hull)
  • Set a concave hull from a list of Line objects.

You only need to set two constants before running the program:

  • concavity : This sets how sharp you want the concave angles to be. It goes from -1 (not concave at all. in fact, the hull will be left convex) up to +1 (very sharp angles can occur. Setting concavity to +1 might result in 0ΒΊ angles!) concavity is defined as the cosine of the concave angles.
  • scaleFactor : This sets how big is the area where concavities are going to be searched. The bigger, the more sharp the angles can be. Setting it to a very high value might affect the performance of the program. This value should be relative to how close to each other the points to be connected are.

For more info you can check the Init.cs file and follow the demo :)

IMG1

Algorithm

Inspired by Implementation of a fast and efficient concave hull algorith, the concave hull is reached through the iteration of four basic steps:

  1. We find the points close to the longest edge of a hull. The distance is directly related to the value of scaleFactor
  2. We measure the angle (in reality the cosine of this angle) of every point related to this segment.
  3. We will select the point that gives us the widest angle/smallest cosine. If the value of the cosine is superior to the value of concavity we will discard this point.
  4. The newly found point will be used to divide the segment into two new ones. The process will be repeated until no more divisions are made.

IMG2

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.