geom

package
v0.0.0-...-648403e Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2013 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package geom provides geometric primitives for 2-dimensional Euclidean space.

Index

Constants

View Source
const (
	// K is the number of dimensions of the geometric primitives.
	K = 2

	// Threshold is the amount by which two floating points must differ
	// to be considered different by the equality rountines in this package.
	//
	// The current value is the square root of the IEEE 64-bit floating point
	// epsilon value.  This is the value recommended in Numerical
	// Recipes.
	Threshold = 1.4901161193847656e-08
)

Variables

This section is empty.

Functions

func NearEqual

func NearEqual(a, b float64) bool

NearEqual returns true if the two floating point numbers are close enough to be considered equal.

func NearZero

func NearZero(f float64) bool

NearZero returns true if the value is close enough to zero to be considered zero.

Types

type Canvas

type Canvas interface {
	Size() (int, int)
	StrokeLine(c color.Color, x0, y0, x1, y1 int)
	FillCircle(c color.Color, x, y, r int)
}

The Canvas interface encapsulates the functions used to draw geometric primitives. The canvas should be oriented such that the lower left corner is the point 0,0, up is positive Y and right is positive X.

type Circle

type Circle Sphere

A Circle is a 2-dimensional sphere.

func (Circle) Draw

func (cir Circle) Draw(cv Canvas, cl color.Color)

Draw draws a circle on the canvas.

type Ellipse

type Ellipse Ellipsoid

An Ellipse is a 2-dimensional ellipsoid.

func (Ellipse) Draw

func (e Ellipse) Draw(cv Canvas, cl color.Color)

Draw draws an ellipse on the canvas.

type Ellipsoid

type Ellipsoid struct {
	Center Point
	Radii  Vector
}

An Ellipsoid is like a sphere, but it has one radius for each axis.

type ImageCanvas

type ImageCanvas struct {
	draw.Image
}

An ImageCanvas implements the Canvas interface using the image/draw package from the Go standard library.

func (ImageCanvas) FillCircle

func (img ImageCanvas) FillCircle(c color.Color, x, y, r int)

FillCircle fills a colored circle on the canvas.

func (ImageCanvas) Size

func (img ImageCanvas) Size() (int, int)

Size returns the size of the canvas in pixels.

func (ImageCanvas) StrokeLine

func (img ImageCanvas) StrokeLine(c color.Color, x0, y0, x1, y1 int)

StrokeLine draws a colored line on the canvas.

type Line

type Line Plane

A Line is a 2-dimensional Plane.

func (Line) Direction

func (l Line) Direction() Vector

Direction returns a vector along the direction of the line.

func (Line) Draw

func (l Line) Draw(cv Canvas, cl color.Color)

Draw draws a line on the canvas.

func (Line) LineIntersection

func (a Line) LineIntersection(b Line) (Point, bool)

LineIntersection returns the point at which two lines intersect. The second return value is true if they do intersect, and it is false if they do not intersect.

type Plane

type Plane struct {
	Origin Point
	// Normal is the unit vector perpendicular to the plane.
	Normal Vector
}

A Plane represented by a point and its normal vector.

type Point

type Point [K]float64

A Point is a location in K-space.

func (*Point) Add

func (p *Point) Add(v Vector)

Add adds a vector to a point.

func (Point) Distance

func (a Point) Distance(b Point) float64

Distance returns the distance between two points.

func (Point) Draw

func (pt Point) Draw(cv Canvas, cl color.Color)

Draw draws a point on the canvas.

func (Point) Minus

func (a Point) Minus(b Point) Vector

Minus returns the difference between two points.

func (Point) NearZero

func (p Point) NearZero() bool

NearZero returns true if the point is close enough to the zero point to be considered the zero point.

func (Point) NearlyEquals

func (a Point) NearlyEquals(b Point) bool

NearlyEquals returns true if the points are close enough to be considered equal.

func (Point) Plus

func (p Point) Plus(v Vector) Point

Plus returns the sum a point and a vector.

func (Point) SquaredDistance

func (a Point) SquaredDistance(b Point) float64

SquaredDistance returns the squared distance between two points.

func (Point) Times

func (p Point) Times(v Vector) Point

Times returns the component-wise product of a point and a vector.

type Ray

type Ray struct {
	Origin Point
	// Direction is the unit vector giving the direction of the ray.
	Direction Vector
}

A Ray is an origin point and a direction vector.

func (Ray) Draw

func (ray Ray) Draw(cv Canvas, cl color.Color)

Draw draws a ray on the canvas.

func (Ray) PlaneIntersection

func (r Ray) PlaneIntersection(p Plane) (float64, bool)

PlaneIntersection returns the distance along the ray at which it intersects a plane. The second return value is true if they do intersect, and it is false if they do not intersect.

func (Ray) SphereIntersection

func (r Ray) SphereIntersection(s Sphere) (float64, bool)

SphereIntersection returns the distance along the ray at which it intersects a. sphere. The second return value is true if they do intersect, and it is false if they do not intersect.

type Rectangle

type Rectangle struct {
	Min  Point
	Size Vector
}

A Rectangle represents a rectangular region of space.

func (*Rectangle) Center

func (r *Rectangle) Center() Point

Center returns the point in the center of the rectangle.

func (Rectangle) Draw

func (r Rectangle) Draw(cv Canvas, cl color.Color)

Draw draws a rectangle on the canvas.

func (*Rectangle) Max

func (r *Rectangle) Max() Point

Max returns the point on the rectangle with the maximum x and y values.

type Segment

type Segment [2]Point

A Segment is the portion of a line between and including two points.

func (Segment) Center

func (s Segment) Center() Point

Center returns the point at the center of the face.

func (Segment) Draw

func (s Segment) Draw(cv Canvas, cl color.Color)

Draw draws the segment on the canvas.

func (Segment) Length

func (s Segment) Length() float64

Length returns the length of the face.

func (Segment) Line

func (s Segment) Line() Line

Line returns the line containing the segment.

func (Segment) NearestPoint

func (s Segment) NearestPoint(p Point) Point

NearestPoint returns the point on the face nearest to p.

func (Segment) Normal

func (s Segment) Normal() Vector

Normal returns the normal vector of the segment.

type Sphere

type Sphere struct {
	Center Point
	Radius float64
}

A Sphere is the set of all points at a fixed distance from a center point.

type Vector

type Vector [K]float64

A Vector is a direction and magnitude in K-space.

func (*Vector) Add

func (a *Vector) Add(b Vector)

Add adds a vector to the receiver vector.

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

Dot returns the dot product of two vectors.

func (Vector) DrawAt

func (v Vector) DrawAt(cv Canvas, cl color.Color, p Point)

DrawAt draws the vector extending from a given point.

func (Vector) Inverse

func (v Vector) Inverse() Vector

Inverse returns the vector point in the opposite direction.

func (Vector) Magnitude

func (v Vector) Magnitude() float64

Magnitude returns the magnitude of the vector.

func (Vector) Minus

func (a Vector) Minus(b Vector) Vector

Minus returns the difference between two vectors.

func (Vector) NearZero

func (v Vector) NearZero() bool

NearZero returns true if the vector is close enough to the zero vector to be considered the zero vector.

func (Vector) NearlyEquals

func (a Vector) NearlyEquals(b Vector) bool

NearlyEquals returns true if the vectors are close enough to be considered equal.

func (Vector) Plus

func (a Vector) Plus(b Vector) Vector

Plus returns the sum of two vectors.

func (Vector) ScaledBy

func (v Vector) ScaledBy(k float64) Vector

ScaledBy returns the product of a vector and a scalar.

func (Vector) SquaredMagnitude

func (v Vector) SquaredMagnitude() float64

SquaredMagnitude returns the squared magnitude of the vector.

func (*Vector) Subtract

func (a *Vector) Subtract(b Vector)

Subtract subtracts a vector from the receiver

func (Vector) Times

func (a Vector) Times(b Vector) Vector

Times returns the component-wise product of two vectors.

func (Vector) Unit

func (v Vector) Unit() Vector

Unit returns the normalized unit form of the vector.

Jump to

Keyboard shortcuts

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