Documentation ¶
Overview ¶
Package geom provides geometric primitives for 2-dimensional Euclidean space.
Index ¶
- Constants
- func NearEqual(a, b float64) bool
- func NearZero(f float64) bool
- type Canvas
- type Circle
- type Ellipse
- type Ellipsoid
- type ImageCanvas
- type Line
- type Plane
- type Point
- func (p *Point) Add(v Vector)
- func (a Point) Distance(b Point) float64
- func (pt Point) Draw(cv Canvas, cl color.Color)
- func (a Point) Minus(b Point) Vector
- func (p Point) NearZero() bool
- func (a Point) NearlyEquals(b Point) bool
- func (p Point) Plus(v Vector) Point
- func (a Point) SquaredDistance(b Point) float64
- func (p Point) Times(v Vector) Point
- type Ray
- type Rectangle
- type Segment
- type Sphere
- type Vector
- func (a *Vector) Add(b Vector)
- func (a Vector) Dot(b Vector) float64
- func (v Vector) DrawAt(cv Canvas, cl color.Color, p Point)
- func (v Vector) Inverse() Vector
- func (v Vector) Magnitude() float64
- func (a Vector) Minus(b Vector) Vector
- func (v Vector) NearZero() bool
- func (a Vector) NearlyEquals(b Vector) bool
- func (a Vector) Plus(b Vector) Vector
- func (v Vector) ScaledBy(k float64) Vector
- func (v Vector) SquaredMagnitude() float64
- func (a *Vector) Subtract(b Vector)
- func (a Vector) Times(b Vector) Vector
- func (v Vector) Unit() Vector
Constants ¶
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 ¶
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 ImageCanvas ¶
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.
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 ¶
A Point is a location in K-space.
func (Point) NearZero ¶
NearZero returns true if the point is close enough to the zero point to be considered the zero point.
func (Point) NearlyEquals ¶
NearlyEquals returns true if the points are close enough to be considered equal.
func (Point) SquaredDistance ¶
SquaredDistance returns the squared distance between two points.
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) PlaneIntersection ¶
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.
type Rectangle ¶
A Rectangle represents a rectangular region of space.
type Segment ¶
type Segment [2]Point
A Segment is the portion of a line between and including two points.
func (Segment) NearestPoint ¶
NearestPoint returns the point on the face nearest to p.
type Vector ¶
A Vector is a direction and magnitude in K-space.
func (Vector) NearZero ¶
NearZero returns true if the vector is close enough to the zero vector to be considered the zero vector.
func (Vector) NearlyEquals ¶
NearlyEquals returns true if the vectors are close enough to be considered equal.
func (Vector) SquaredMagnitude ¶
SquaredMagnitude returns the squared magnitude of the vector.