Documentation ¶
Overview ¶
Package geom defines a two-dimensional coordinate system.
Index ¶
- Constants
- func Centroid(points ...[2]float64) (x, y float64)
- func Distance(x1, y1, x2, y2 float64) float64
- func DistanceSq(x1, y1, x2, y2 float64) float64
- type Circle
- type Ellipse
- type Matrix
- type Point
- type Polygon
- func (p *Polygon) AbsoluteOrigin() Point
- func (p *Polygon) Area() float64
- func (p *Polygon) GetX() float64
- func (p *Polygon) GetY() float64
- func (p *Polygon) Model() []Point
- func (p *Polygon) Origin() *Point
- func (p *Polygon) SetX(x float64)
- func (p *Polygon) SetY(y float64)
- func (p *Polygon) Transform(matrix Matrix)
- func (p *Polygon) Vertices() []Point
- type PolygonShape
- type Rect
- type Shape
- type Transform
- type TransformMatrixElement
- type Transformable
- type Transformer
- type Vector
- func (v *Vector) Add(x, y float64) *Vector
- func (v *Vector) AddVec(add Vector) *Vector
- func (v *Vector) AddXY(add XYGetter) *Vector
- func (v Vector) Angle() float64
- func (v Vector) Clone() *Vector
- func (v Vector) Cross(target Vector) float64
- func (v Vector) Dist(target Vector) float64
- func (v Vector) DistSq(target Vector) float64
- func (v *Vector) Div(div Vector) *Vector
- func (v Vector) Dot(target Vector) float64
- func (v Vector) Equals(target Vector) bool
- func (v *Vector) FromPolar(angle, length float64) *Vector
- func (v Vector) GetX() float64
- func (v Vector) GetY() float64
- func (v Vector) Length() float64
- func (v Vector) LengthSq() float64
- func (v *Vector) Lerp(target Vector, t float64) *Vector
- func (v *Vector) LerpRound(target Vector, t, e float64) *Vector
- func (v *Vector) Limit(length float64) *Vector
- func (v *Vector) MulVec(mul Vector) *Vector
- func (v *Vector) Negate() *Vector
- func (v Vector) Normalize() Vector
- func (v Vector) Point() Point
- func (v *Vector) Rotate(angle float64) *Vector
- func (v *Vector) Scale(scale float64) *Vector
- func (v *Vector) SetAngle(angle float64) *Vector
- func (v *Vector) SetLength(l float64) *Vector
- func (v *Vector) SetX(x float64)
- func (v *Vector) SetY(y float64)
- func (v Vector) String() string
- func (v *Vector) SubVec(sub Vector) *Vector
- func (v *Vector) SubXY(sub XYGetter) *Vector
- func (v *Vector) Zero() *Vector
- type XY
- type XYGetter
- type XYSetter
Constants ¶
const ( ME_A TransformMatrixElement = 0 ME_B = 3 ME_C = 1 ME_D = 4 ME_TX = 2 ME_TY = 5 )
Variables ¶
This section is empty.
Functions ¶
func DistanceSq ¶
DistanceSq calculates the squared distance between the points [x1 y1] and [x2 y2].
Types ¶
type Ellipse ¶
Ellipse cannot be transformed. https://g6auc.me.uk/ellipses/index.html
type Matrix ¶
type Matrix [9]float64
Matrix is a 3x3 matrix of float64 values.
func IdentityMatrix ¶
func IdentityMatrix() Matrix
IdentityMatrix creates a Matrix with values that cause no transformation to the target.
func RotationMatrix ¶
RotationMatrix creates a Matrix which rotates the target by an angle, measured in radians. https://en.wikipedia.org/wiki/Rotation_matrix
func ScaleMatrix ¶
func SkewMatrix ¶
SkewMatrix creates a Matrix which progressively slides the target in a direction parallel to the x or y axis.
func TransformMatrix ¶
TransformMatrix creates a Matrix with the following elements:
[ a, c, tx, b, d, ty, u, v, w ]
The elements A and D affect the positioning of pixels along the x and y axis when scaling or rotating. B and C are the elements that affect the positioning of pixels along the x and y axis when rotating or skewing. TX and TY are the distances by which to translate each point along the x and y axis. The Matrix operates in 2D space so it always assumes that the (last three) elements u and v are 0.0, and w is 1.0. https://en.wikipedia.org/wiki/Transformation_matrix https://www.tutorialspoint.com/computer_graphics/2d_transformation.htm
type Point ¶
type Point struct {
X, Y float64
}
func PointFromInt ¶
PointFromInt creates a new Point from int32 values.
func PointFromXY ¶
PointFromXY creates a new Point from a XYGetter.
func (Point) InFRect ¶
InFRect returns a bool indicating whether the X and Y values of Point are within the sdl.FRect.
type Polygon ¶
type Polygon struct {
// X and Y indicate the absolute position of the Polygon.
X, Y float64
// contains filtered or unexported fields
}
https://en.wikipedia.org/wiki/Simple_polygon https://en.wikipedia.org/wiki/Polygon
func NewPolygon ¶
func NewQuad ¶
NewQuad creates a new polygon where all angles are 90 degrees. It differs from a Rect in the fact it can be rotated, scaled and skewed using a Matrix.
func NewRegularPolygon ¶
NewRegularPolygon creates a new regular polygon where all angles are equal in measure and all sides have the same length. Value cr is the circumradius between the center of the Polygon and any vertex (edge point). Value n indicates the amount of vertices (edges) the polygon has, 3 for a triangle, 4 for a quad etc. This value cannot be lower than 3. See https://en.wikipedia.org/wiki/Regular_polygon for additional information about regular polygons.
func (*Polygon) AbsoluteOrigin ¶
type PolygonShape ¶
type Rect ¶
type Rect struct {
X, Y,
W, H float64
}
A Rect is an axis-aligned rectangle where X Y is its center point. It cannot be transformed using a Transform or Matrix. It can however change position and change its width and height. Use NewQuad instead to create a four-sided polygon if you need a rectangular shape that needs to be rotated, sheared or transformed in any other way.
type Transform ¶
type Transform struct { Rotation, ScaleX, ScaleY, SkewX, SkewY, TranslateX, TranslateY float64 }
Transform calculates various transformations and merges them to a Matrix which can be applied to a Transformable.
type TransformMatrixElement ¶
type TransformMatrixElement int
type Transformable ¶
A Transformable is any shape that can be transformed using a transform Matrix.
type Transformer ¶
type Transformer interface { Reset() Matrix() Matrix }
type Vector ¶
type Vector struct {
X, Y float64
}
func VectorFromInt ¶
VectorFromInt creates a new Vector from int32 values.
func VectorFromXY ¶
VectorFromXY creates a new Vector from an XYGetter.
func (Vector) Clone ¶
Clone returns a pointer to a new Vector with the same X and Y values as the source Vector.
func (Vector) DistSq ¶
DistSq calculates the squared distance between the Vector and the target Vector.
func (Vector) Equals ¶
Equals compares the X and Y values of the Vector and the target Vector, and returns true when they are equal.
func (*Vector) FromPolar ¶
FromPolar sets the X and Y values according to the provided angle (in radians) and length.
func (*Vector) Lerp ¶
Lerp linearly interpolates this Vector towards the target Vector. Value t is the interpolation percentage between 0 and 1.
func (*Vector) Negate ¶
Negate the X and Y values of this Vector, meaning negative numbers becoming positive and positive becoming negative.
func (Vector) Normalize ¶
Norm normalizes the Vector by making the length a magnitude of 1 in the same direction. It does not alter the source Vector.
func (*Vector) Scale ¶
Scale this Vector by the given scale value, where 1 is equal to the Vector's current value.