GithubHelp home page GithubHelp logo

vb6hobbyst7 / contourmap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fogleman/contourmap

0.0 1.0 0.0 177 KB

Compute contour lines (isolines) for any 2D data in Go.

License: MIT License

Go 100.00%

contourmap's Introduction

contourmap

Compute contour lines (isolines) for any 2D data in Go.

Installation

go get -u github.com/fogleman/contourmap

Documentation

https://godoc.org/github.com/fogleman/contourmap

Example Usage

Creating a ContourMap

A new ContourMap can be generated in many different ways, depending on what type of data you have.

Use FromFloat64s if you have an array of numbers. The length of the array must equal width * height. The two-dimensional data is stored in a flat array in row-major order.

m := contourmap.FromFloat64s(width, height, data)

Use FromImage if you have an image.Image, such as a grayscale heightmap.

m := contourmap.FromImage(im)

Use FromFunction to specify an arbitrary function that will provide a Z for any given X, Y coordinate. The function will be called for all points x = [0, w) and y = [0, h) to determine the Z value at each point in the grid.

var f func(x, y int) float64
...
m := contourmap.FromFunction(width, height, f)

Finding Contour Lines

Once your ContourMap is created, you can use the Contours function to find isolines at any given Z height. This function returns a list of contours where each contour is a list of X, Y points. A Contour may be open or closed. Closed contours have c[0] == c[len(c)-1].

contours := m.Contours(z)
for _, contour := range contours {
    for _, point := range contour {
        // do something with points...
        fmt.Println(point.X, point.Y)
    }
}

Closing Contours at the Grid Perimeter

Contours may end at the edge of the grid data, forming open contours. If you want to force all contours to be closed by following the perimeter of the grid, you can use ContourMap.Closed which will generate a new ContourMap that can be used for this purpose:

m = m.Closed() // now all contours will be closed paths

Examples

Some examples are included to help you get started.

$ cd go/src/github.com/fogleman/contourmap/examples
$ go run iceland.go iceland.jpg

Iceland Example

$ go run examples/function.go

Function Example

contourmap's People

Contributors

fogleman 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.