Coder Social home page Coder Social logo

icosphere's Introduction

icosphere

This is a fast(ish) way to subdivide the icosahedron to obtain a sphere approximation in C++. It's based on Andreas Kahler's implementation in C# (http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html) with the following adaptations:

  • it does not generate a mesh, but a walkable grid which we can use for performing computations in spherical geometry, such as fictional planet generation. We can quickly find a data value for the nearest point on the grid to given geographical (i.e. spherical) coordinates.

  • it does not therefore keep the triangles as they are generated, but instead saves the vertices and the edges connecting them, throwing the triangles away. We therefore generate the grid progressively not by iterating over the triangles generated in the previous pass, but by recursively subdividing the new triangle until the desired level of detail is reached. (We do still have up to 5% of the total number of triangles in memory at a time because each top-level triangle can't be deleted until all of its children, grandchildren and so on down to the lowest level of detail have been generated).

  • since Andreas wrote his blog post, newer and faster hashmap implementations have become available. I am using this by Martin Ankerl: https://github.com/martinus. With this implementation, there is no slowdown from having all the edges in the edgemap instead of truncating it after each layer, which enables the recurive approach.

On my machine this now generates about 2.5 million vertices in 5 seconds, or 10 million in 20 seconds, but runs out of stack space if further subdivision is attempted (the layered version along the lines of Andreas' solution also breaks at that level, failing to allocate space for the next layer). This is with 16 MB RAM on an i7 processor running Ubuntu 19.04.

icosphere's People

Contributors

chateauferret avatar

Watchers

 avatar

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.