Plot 3D math equation z=f(x, y) with SVG format.

plot-function-svg

Plot 3D math equation z=f(x, y) with SVG format.

Some codes are referred from https://github.com/adonovan/gopl.io
licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Creative Commons License

APIs

type PlotConfig struct {
	Width       int
	Height      int
	Cells       int
	XYrange     float64
	Xoffset     float64
	Yoffset     float64
	Zscale      float64
	CameraAngle float64
	Color       bool
	RightHand   bool
}

func DefaultPlotConfig() *PlotConfig {
	return &PlotConfig{
		Width:       600,
		Height:      320,
		Cells:       100,
		XYrange:     30.0,
		Xoffset:     0,
		Yoffset:     0,
		Zscale:      0.4,
		CameraAngle: math.Pi / 6,
		Color:       true,
		RightHand:   true,
	}
}

// Draw an SVG to io.Writer. Default w (use nil) is os.Stdout. Default cfg (use nil) is DefaultPlotConfig().
func PlotSVG(f func(x, y float64) float64, w io.Writer, cfg *PlotConfig) 

Right-hand coordinates (default):
    z
     |__ y
x /

Left-hand coordinates:
    z
     |__ x
y /

Examples

Example1:

f := func(x, y float64) float64 {
	r := math.Hypot(x, y)
	return math.Sin(r) / r
}
file, _ := os.Create("example1.svg")
plot.PlotSVG(f, file, nil)

image

Example2:

cfg := &plot.PlotConfig{
	Width:       600,
	Height:      400,
	Cells:       100,
	XYrange:     2,
	Xoffset:     0.4,
	Yoffset:     0.3,
	Zscale:      0.1,
	CameraAngle: math.Pi / 6,
	Color:       true,
	RightHand:   false,
}
f := func(x, y float64) float64 {
	return 2*math.Pow(x, 2) + 0.5*math.Sin(-7*y)
}
file, _ := os.Create("example2.svg")
plot.PlotSVG(f, file, cfg)

image

Similar Resources

A performance oriented 2D/3D math package for Go

Package go3d is a performance oriented vector and matrix math package for 2D and 3D graphics. Every type has its own sub-package and is named T. So ve

Dec 16, 2022

A pure Go 3D math library.

MathGL This is a Go matrix and vector math library specialized for Open GL graphics capabilities. This package is made primarily with code generation

Dec 24, 2022

GoStats is a go library for math statistics mostly used in ML domains, it covers most of the statistical measures functions.

GoStats GoStats is an Open Source Go library for math statistics mostly used in Machine Learning domains, it covers most of the Statistical measures f

Nov 10, 2022

high performance fixed decimal place math library for Go

Summary A fixed place numeric library designed for performance. All numbers have a fixed 7 decimal places, and the maximum permitted value is +- 99999

Dec 6, 2022

Golang-module-references - A reference for how to setup a Golang project with modules - Task Management + Math Examples

Golang Module Project The purpose of this project is to act as a reference for setting up future Golang projects using modules. This project has a mat

Jan 2, 2022

RundQuiz-Game - This is a Go exercise that implements and builds a quiz game from a list of math questions in a CSV file.

Go RundQuiz Game Exercise details This exercise is broken into two parts to help simplify the process of explaining it as well as to make it easier to

Jan 5, 2022

Sunrise/Noon/Sunset math in Go

Sunrise/Noon/Sunset math in Go

Feb 10, 2022

Read metrics from a Message Queue in Json format and expose them in a Prometheus compatible format

mq2prom Read metrics from a Message Queue in Json format and expose them in a Prometheus compatible format. Currently only works for MQTT compatible M

Jan 24, 2022

Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression

NFP (Number Format Parser) Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression. Installatio

Feb 4, 2022

2D rendering for different output (raster, pdf, svg)

2D rendering for different output (raster, pdf, svg)

draw2d Package draw2d is a go 2D vector graphics library with support for multiple outputs such as images (draw2d), pdf documents (draw2dpdf), opengl

Dec 25, 2022

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Nov 1, 2022

Go Language Library for SVG generation

Go Language Library for SVG generation

SVGo: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification (http://www.w3.org/TR/SVG

Jan 6, 2023

Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Dec 25, 2022

gensvg generates SVG to an io.Writer

gensvg generates SVG to an io.Writer

gensvg: A Go library for SVG generation The library generates SVG as defined by the Scalable Vector Graphics 1.1 Specification

Dec 28, 2022

A sample FaaS function that gets a stock quote and 30 day history by symbol and returns a HTML page with a generates SVG sparkline.

faas stonks This uses serverless technology to get a stock quote and 30 day sparkline from Yahoo Finance. Deployment Nimbella account Namespace with o

Sep 23, 2021

Quick and dirty Minecraft player head to SVG converter

Head SVG Quick and dirty Minecraft player head to SVG converter. Can be used to generate player head icons. Usage usage: Head SVG [-h|--help] -n|--nam

May 29, 2022

An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system

An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system

Time-Space Train Planner An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system, in order to see all possible connecti

Dec 17, 2022

🎄 Go code coverage to SVG treemap

🎄 Go cover to Treemap Useful when you have large project with lots of files and packages $ go install github.com/nikolaydubina/go-cover-treemap@lates

Jan 9, 2023

HTML, CSS and SVG static renderer in pure Go

Web render This module implements a static renderer for the HTML, CSS and SVG formats. It consists for the main part of a Golang port of the awesome W

Apr 19, 2022
An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system
An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system

Time-Space Train Planner An SVG-based tool to visualize public transport journeys retrieved from a HAFAS system, in order to see all possible connecti

Dec 17, 2022
Exports Speedtest CLI metrics in the prometheus format, caching the results.
Exports Speedtest CLI metrics in the prometheus format, caching the results.

Exports Speedtest CLI metrics in the prometheus format, caching the results.

Oct 21, 2022
Exports Fast.com metrics in the prometheus format, caching the results.
Exports Fast.com metrics in the prometheus format, caching the results.

fastcom-exporter Exports Fast.com metrics in the prometheus format, caching the results.

Nov 14, 2022
An ordinary differential equation solving library in golang.

ode An ordinary differential equation solving library in golang. Features Multi-dimensional state vector (i.e. extended states) Channel based stopping

Oct 19, 2022
A simple API written in Go that creates badges in SVG format, based on the requested route.

A simple API written in Go that creates badges in SVG format, based on the requested route. Those graphics can be used to style README.md files, or to add tags to webpages.

Jul 2, 2021
Snippit - Creates syntax-highlighted code snippets in png or svg format
Snippit - Creates syntax-highlighted code snippets in png or svg format

snippit creates syntax-highlighted code snippets in png or svg format. Installat

Oct 10, 2022
Generate HTTP load and plot the results in real-time
Generate HTTP load and plot the results in real-time

ali A load testing tool capable of performing real-time analysis, inspired by vegeta and jplot. ali comes with an embedded terminal-based UI where you

Jan 6, 2023
Plot your repository stars over time.

Plot your repository stars over time.

Dec 30, 2022
mass-binding-target is a command line tool for generating binding target list by search plot files from disk.

mass-binding-target mass-binding-target is a command line tool for generating binding target list by search plot files from disk. Build Go 1.13 or new

Nov 5, 2021
Attempt to plot light sensor data from lunarsensor.
Attempt to plot light sensor data from lunarsensor.

lightsensor Attempt to plot light sensor data from lunarsensor. Buy the components, install firmware on Ambient Light Sensor. Build the go app that po

Nov 10, 2022