planar

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 4 Imported by: 0

README

orb/planar Godoc Reference

The geometries defined in the orb package are generic 2d geometries. Depending on what projection they're in, e.g. lon/lat or flat on the plane, area and distance calculations are different. This package implements methods that assume the planar or Euclidean context.

Examples

Area of 3-4-5 triangle:

r := orb.Ring{{0, 0}, {3, 0}, {0, 4}, {0, 0}}
a := planar.Area(r)

fmt.Println(a)
// Output:
// 6

Distance between two points:

d := planar.Distance(orb.Point{0, 0}, orb.Point{3, 4})

fmt.Println(d)
// Output:
// 5

Length/circumference of a 3-4-5 triangle:

r := orb.Ring{{0, 0}, {3, 0}, {0, 4}, {0, 0}}
l := planar.Length(r)

fmt.Println(l)
// Output:
// 12

Documentation

Overview

Package planar computes properties on geometries assuming they are in 2d euclidean space.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Area

func Area(g orb.Geometry) float64

Area returns the area of the geometry in the 2d plane.

Example
package main

import (
	"fmt"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/planar"
)

func main() {
	// +
	// |\
	// | \
	// |  \
	// +---+

	r := orb.Ring{{0, 0}, {3, 0}, {0, 4}, {0, 0}}
	a := planar.Area(r)

	fmt.Println(a)
}
Output:

6

func CentroidArea

func CentroidArea(g orb.Geometry) (orb.Point, float64)

CentroidArea returns both the centroid and the area in the 2d plane. Since the area is need for the centroid, return both. Polygon area will always be >= zero. Ring area my be negative if it has a clockwise winding orider.

func Distance

func Distance(p1, p2 orb.Point) float64

Distance returns the distance between two points in 2d euclidean geometry.

Example
package main

import (
	"fmt"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/planar"
)

func main() {
	d := planar.Distance(orb.Point{0, 0}, orb.Point{3, 4})

	fmt.Println(d)
}
Output:

5

func DistanceFrom

func DistanceFrom(g orb.Geometry, p orb.Point) float64

DistanceFrom returns the distance from the boundary of the geometry in the units of the geometry.

func DistanceFromSegment

func DistanceFromSegment(a, b, point orb.Point) float64

DistanceFromSegment returns the point's distance from the segment [a, b].

func DistanceFromSegmentSquared

func DistanceFromSegmentSquared(a, b, point orb.Point) float64

DistanceFromSegmentSquared returns point's squared distance from the segement [a, b].

func DistanceFromWithIndex

func DistanceFromWithIndex(g orb.Geometry, p orb.Point) (float64, int)

DistanceFromWithIndex returns the minimum euclidean distance from the boundary of the geometry plus the index of the sub-geometry that was the match.

func DistanceSquared

func DistanceSquared(p1, p2 orb.Point) float64

DistanceSquared returns the square of the distance between two points in 2d euclidean geometry.

func Length

func Length(g orb.Geometry) float64

Length returns the length of the boundary of the geometry using 2d euclidean geometry.

Example
package main

import (
	"fmt"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/planar"
)

func main() {
	// +
	// |\
	// | \
	// |  \
	// +---+

	r := orb.Ring{{0, 0}, {3, 0}, {0, 4}, {0, 0}}
	l := planar.Length(r)

	fmt.Println(l)
}
Output:

12

func MultiPolygonContains

func MultiPolygonContains(mp orb.MultiPolygon, point orb.Point) bool

MultiPolygonContains checks if the point is within the multi-polygon. Points on the boundary are considered in.

func PolygonContains

func PolygonContains(p orb.Polygon, point orb.Point) bool

PolygonContains checks if the point is within the polygon. Points on the boundary are considered in.

func RingContains

func RingContains(r orb.Ring, point orb.Point) bool

RingContains returns true if the point is inside the ring. Points on the boundary are considered in.

Types

This section is empty.

Jump to

Keyboard shortcuts

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