tri

package
v1.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2021 License: BSD-3-Clause Imports: 5 Imported by: 1

README

Gosl. gm/tri. Mesh generation: triangles

PkgGoDev

The tri package has functions go generate meshes of triangular elements and Delaunay triangulations. The package is a light wrapper to the very efficient Triangle code by Jonathan Shewchuk and available at the Triangle website.

Triangle's licence details are in the triangle_README.txt file.

In addition of being very fast, Triangle can generate meshes with great quality; i.e. it is a quality-mesh triangulator.

Here, the Cartesian coordinates of points are stored in continuous 1D arrays (slices) such as:

X = { x0, x1, x2, ... Npoints }
Y = { y0, y1, y2, ... Npoints }

The topology is simply defined by two slices usually named V for vertices and C for cells (triangles):

V = { { x0, y0 }, { x1, y1 }, { x2, y2 } ... Nvertices }
C = { { id0, id1, id2 }, { id0, id1, id2 } ... Ncellls }

where V is the list of vertices (there are Nvertices vertices) and C is the list of triangles (there are Ncells triangles). The ids (e.g. id0, id1, id2) in C are the indices in V.

Draw mesh

For example, the set of triangles in the above figure are defined (and drawn) with:

// vertices (points)
V := [][]float64{
    {0, 0}, {1, 0},
    {1, 1}, {0, 1},
}

// cells (triangles)
C := [][]int{
    {0, 1, 2},
    {2, 3, 0},
}

Delaunay triangulation

The Delaunay triangulation of a cloud of points in the tri package is easily computed with the Delaunay command that takes as input the Cartesian coordinates.

// fix seed
rnd.Init(1358)

// generate cloud of points
nx, ny := 6, 6
dx := 1.0 / float64(nx-1)
dy := 1.0 / float64(ny-1)
X := make([]float64, nx*ny)
Y := make([]float64, nx*ny)
for j := 0; j < ny; j++ {
    for i := 0; i < nx; i++ {
        n := i + j*nx
        X[n] = float64(i) * (dx * rnd.Float64(0.5, 1.0))
        Y[n] = float64(j) * (dy * rnd.Float64(0.5, 1.0))
    }
}

// generate
V, C := tri.Delaunay(X, Y, false)

API

Please see the documentation here

Documentation

Overview

Package tri wraps Triangle to perform mesh generation a Delaunay triangulation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delaunay

func Delaunay(X, Y []float64, verbose bool) (Verts [][]float64, Cells [][]int)

Delaunay computes 2D Delaunay triangulation using Triangle

Input:
  X = { x0, x1, x2, ... Npoints }
  Y = { y0, y1, y2, ... Npoints }
Ouptut:
  Verts = { { x0, y0 }, { x1, y1 }, { x2, y2 } ... Nvertices }
  Cells = { { id0, id1, id2 }, { id0, id1, id2 } ... Ncellls }

Types

type Cell added in v1.1.0

type Cell struct {
	ID       int   // identifier
	Tag      int   // tag
	V        []int // vertices
	EdgeTags []int // edge tags (2D or 3D)
}

Cell holds cell data

type Hole added in v1.1.0

type Hole struct {
	X float64 // x-coordinate of a point inside hole
	Y float64 // y-coordinate of a point inside hole
}

Hole holds input data defining a "hole"

type Input added in v1.1.0

type Input struct {
	Points   []*Point   // list of points
	Segments []*Segment // list of segments
	Regions  []*Region  // list of regions
	Holes    []*Hole    // list of holes
}

Input holds a Planar Straight Line Graph (PSLG)

func (*Input) Generate added in v1.1.0

func (o *Input) Generate(globalMaxArea, globalMinAngle float64, o2, verbose bool, extraSwitches string) (m *Mesh)

Generate generates unstructured mesh of triangles

globalMaxArea  -- imposes a maximum triangle area constraint; fixed area constraint that applies to every triangle
globalMinAngle -- quality mesh generation with no angles smaller than specified value in degrees
                  globalMinAngle must be in [0, 60]
o2             -- generates quadratic triangles
verbose        -- shows Triangle messages
extraSwitches  -- extra arguments to be passed to Triangle

type Mesh added in v1.1.0

type Mesh struct {
	Verts []*Vertex // vertices
	Cells []*Cell   // cells
}

Mesh defines mesh data

type Point added in v1.1.0

type Point struct {
	Tag int     // tag
	X   float64 // x-coordinate
	Y   float64 // y-coordinate
}

Point holds input data defining a "point"

type Region added in v1.1.0

type Region struct {
	Tag     int     // tag of region
	MaxArea float64 // max area constraint for triangulation of region
	X       float64 // x-coordinate of a point inside region
	Y       float64 // y-coordinate of a point inside region
}

Region holds input data defining a "region"

type Segment added in v1.1.0

type Segment struct {
	Tag int // tag
	L   int // left point
	R   int // right point
}

Segment holds input data defining a "segment"

type Vertex added in v1.1.0

type Vertex struct {
	ID  int       // identifier
	Tag int       // tag
	X   []float64 // coordinates [2]
}

Vertex holds vertex data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL