GithubHelp home page GithubHelp logo

be-water-myfriend / catmullrom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fzipp/catmullrom

0.0 0.0 0.0 45 KB

A Catmull-Rom spline implementation.

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%

catmullrom's Introduction

catmullrom

Package catmullrom implements the centripetal Catmull-Rom spline and calculates points of a 2D spline curve given a series of control points.

Add it to a module as a dependency via:

go get github.com/fzipp/catmullrom

Documentation

Package documentation can be found on pkg.go.dev.

Example usage

Spline chain

package main

import (
	"fmt"

	"github.com/fzipp/catmullrom"
)

func main() {

	controlPoints := []catmullrom.Point{
		{X: 0, Y: 2.5},
		{X: 2, Y: 4},
		{X: 3, Y: 2},
		{X: 4, Y: 1.5},
		{X: 5, Y: 6},
		{X: 6, Y: 5},
		{X: 7, Y: 3},
		{X: 9, Y: 1},
		{X: 10, Y: 2.5},
		{X: 11, Y: 7},
		{X: 9, Y: 5},
		{X: 8, Y: 6},
		{X: 7, Y: 5.5},
	}

	curve := catmullrom.SplineChain(controlPoints, 100, 0.5)

	for _, point := range curve {
		fmt.Printf("%v\t%v\n", point.X, point.Y)
	}
}

Catmull-Rom spline chain

Single spline

package main

import (
	"fmt"

	"github.com/fzipp/catmullrom"
)

func main() {

	p := []catmullrom.Point{
		{X: 0, Y: 2.5},
		{X: 2, Y: 4},
		{X: 3, Y: 2},
		{X: 4, Y: 1.5},
	}

	curve := catmullrom.Spline(p[0], p[1], p[2], p[3], 100, 0.5)

	for _, point := range curve {
		fmt.Printf("%v\t%v\n", point.X, point.Y)
	}
}

License

This project is free and open source software licensed under the BSD 3-Clause License.

catmullrom's People

Contributors

fzipp avatar frzschneide 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.