geom

package
v0.0.0-...-35cf6ad Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package geom provides geometric primitives and containers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board struct {
	// real primitives
	Points    *hashset.HashSet
	Lines     *hashset.HashSet
	Circles   *hashset.HashSet
	HalfLines *hashset.HashSet
	Segments  *hashset.HashSet
	// contains filtered or unexported fields
}

Board is a geometry board containing all geometry objects

func NewBoard

func NewBoard() *Board

NewBoard creates an empty geometry board

func (*Board) AddCircle

func (gb *Board) AddCircle(c *Circle)

AddCircle adds a circle and calculates its intersections with existing objects

func (*Board) AddCircleTrace

func (gb *Board) AddCircleTrace(c *Circle)

AddCircleTrace adds a circle and calculates its intersections with existing objects, adding it to highlight sequence

func (*Board) AddHalfLine

func (gb *Board) AddHalfLine(h *HalfLine)

AddHalfLine adds a half line and its end point, do nothing else

func (*Board) AddLine

func (gb *Board) AddLine(l *Line)

AddLine adds a line and calculates its intersections with existing objects

func (*Board) AddLineTrace

func (gb *Board) AddLineTrace(l *Line)

AddLineTrace adds a line and calculates its intersections with existing objects, adding it to highlight sequence

func (*Board) AddPoint

func (gb *Board) AddPoint(pt *Point)

AddPoint adds a point, do nothing else

func (*Board) AddSegment

func (gb *Board) AddSegment(s *Segment)

AddSegment adds a segment and its end points, do nothing else

func (*Board) Clone

func (gb *Board) Clone() *Board

Clone deep copies a geometry board

func (*Board) GeneratePlot

func (gb *Board) GeneratePlot(folderName string) error

GeneratePlot creates a folder of plots showing steps of the construction

func (*Board) GenerateRandomPoints

func (gb *Board) GenerateRandomPoints() []*Point

GenerateRandomPoints returns a set of random points, from each geometry object

func (*Board) GenerateSinglePlot

func (gb *Board) GenerateSinglePlot(fileName string, highlight bool) error

GenerateSinglePlot creates a plot file with fileName

func (*Board) RemoveLastGeometryObject

func (gb *Board) RemoveLastGeometryObject()

RemoveLastGeometryObject removes the last line or circle in the output sequence

type Circle

type Circle struct {
	hashset.Serializable
	// contains filtered or unexported fields
}

Circle is a circle is uniquely determined by its center point and radius

func NewCircleByPoint

func NewCircleByPoint(center, onSide *Point) *Circle

NewCircleByPoint creates a circle by its center and a point on its side

func NewCircleByRadius

func NewCircleByRadius(center *Point, r float64) *Circle

NewCircleByRadius creates a circle by its center and its radius

func (*Circle) ContainsPoint

func (c *Circle) ContainsPoint(pt *Point) bool

ContainsPoint checks if a point is on the circle

func (*Circle) GetCenter

func (c *Circle) GetCenter() *Point

GetCenter returns the center of the circle

func (*Circle) GetRadius

func (c *Circle) GetRadius() float64

GetRadius returns the radius of the circle

func (*Circle) GetRandomPoint

func (c *Circle) GetRandomPoint() *Point

GetRandomPoint returns a random point on the circle

func (*Circle) IntersectCircle

func (c *Circle) IntersectCircle(c2 *Circle) *Intersection

IntersectCircle returns the intersections with another circle

func (*Circle) IntersectHalfLine

func (c *Circle) IntersectHalfLine(h *HalfLine) *Intersection

IntersectHalfLine returns intersections with a half line

func (*Circle) IntersectLine

func (c *Circle) IntersectLine(l *Line) *Intersection

IntersectLine returns the intersections with a line

func (*Circle) IntersectSegment

func (c *Circle) IntersectSegment(s *Segment) *Intersection

IntersectSegment returns intersections with a segment

func (*Circle) Serialize

func (c *Circle) Serialize() interface{}

Serialize returns the hash of the circle

type HalfLine

type HalfLine struct {
	hashset.Serializable
	// contains filtered or unexported fields
}

HalfLine is determined uniquely by its starting point and normalized direction vector

func NewHalfLineFromDirection

func NewHalfLineFromDirection(pt *Point, direction *Vector2D) *HalfLine

NewHalfLineFromDirection creates a half line from its end point and a direction

func NewHalfLineFromTwoPoints

func NewHalfLineFromTwoPoints(source *Point, direction *Point) *HalfLine

NewHalfLineFromTwoPoints creates a half line from two points, with source as end point

func (*HalfLine) ContainsPoint

func (h *HalfLine) ContainsPoint(pt *Point) bool

ContainsPoint checks if a point is on the half line

func (*HalfLine) GetEndPoint

func (h *HalfLine) GetEndPoint() *Point

GetEndPoint returns its end point

func (*HalfLine) GetRandomPoint

func (h *HalfLine) GetRandomPoint() *Point

GetRandomPoint returns a random point on the half line

func (*HalfLine) IntersectCircle

func (h *HalfLine) IntersectCircle(c *Circle) *Intersection

IntersectCircle returns intersections with a circle

func (*HalfLine) IntersectHalfLine

func (h *HalfLine) IntersectHalfLine(h2 *HalfLine) *Intersection

IntersectHalfLine returns intersections with another half line

func (*HalfLine) IntersectLine

func (h *HalfLine) IntersectLine(l *Line) *Intersection

IntersectLine returns intersections with a line

func (*HalfLine) IntersectSegment

func (h *HalfLine) IntersectSegment(s *Segment) *Intersection

IntersectSegment returns intersections with a segment

func (*HalfLine) PointInRange

func (h *HalfLine) PointInRange(pt *Point) bool

PointInRange checks if a point is in the coordinates of a half line

func (*HalfLine) Serialize

func (h *HalfLine) Serialize() interface{}

Serialize returns the hash of the half line

type Intersection

type Intersection struct {
	SolutionNumber int
	Solutions      []*Point
}

Intersection is a type that stores the resulting intersections of two geometry objects

func NewIntersection

func NewIntersection(pts ...*Point) *Intersection

NewIntersection return a new Intersection object

type Line

type Line struct {
	hashset.Serializable
	// contains filtered or unexported fields
}

Line is a line represented as ax+by+c==0, it is unique when the max coefficient is normalized to a fixed number, and a being non-negative.

func NewLineAsAngleBisector

func NewLineAsAngleBisector(pt1, pt2, pt3 *Point) *Line

NewLineAsAngleBisector returns a line as angle bisector of pt1,pt2,pt3

func NewLineFromCoefficients

func NewLineFromCoefficients(a, b, c float64) *Line

NewLineFromCoefficients creates a line from coefficients

func NewLineFromDirection

func NewLineFromDirection(pt *Point, v *Vector2D) *Line

NewLineFromDirection creates a line from a point and a vector as direction

func NewLineFromHalfLine

func NewLineFromHalfLine(h *HalfLine) *Line

NewLineFromHalfLine creates a line from a half line

func NewLineFromSegment

func NewLineFromSegment(s *Segment) *Line

NewLineFromSegment creates a line from a segment

func NewLineFromTwoPoints

func NewLineFromTwoPoints(pt1, pt2 *Point) *Line

NewLineFromTwoPoints creates a line from two points

func (*Line) ContainsPoint

func (l *Line) ContainsPoint(pt *Point) bool

ContainsPoint checks whether a point is on the line

func (*Line) GetNormalVector

func (l *Line) GetNormalVector() *Vector2D

GetNormalVector returns a normal vector of the line, length not specified

func (*Line) GetParallelLineWithPoint

func (l *Line) GetParallelLineWithPoint(pt *Point) *Line

GetParallelLineWithPoint returns a parallel line through a point

func (*Line) GetParallelVector

func (l *Line) GetParallelVector() *Vector2D

GetParallelVector returns a parallel vector of the line, length not specified

func (*Line) GetRandomPoint

func (l *Line) GetRandomPoint() *Point

GetRandomPoint returns a random point on the line

func (*Line) GetTangentLineWithPoint

func (l *Line) GetTangentLineWithPoint(pt *Point) *Line

GetTangentLineWithPoint returns a tangent line through a point

func (*Line) IntersectCircle

func (l *Line) IntersectCircle(c *Circle) *Intersection

IntersectCircle returns intersections with a circle

func (*Line) IntersectHalfLine

func (l *Line) IntersectHalfLine(h *HalfLine) *Intersection

IntersectHalfLine returns intersections with a half line

func (*Line) IntersectLine

func (l *Line) IntersectLine(l2 *Line) *Intersection

IntersectLine returns intersections with another line

func (*Line) IntersectSegment

func (l *Line) IntersectSegment(s *Segment) *Intersection

IntersectSegment returns intersections with a segment

func (*Line) Serialize

func (l *Line) Serialize() interface{}

Serialize returns the hash of a line

type Point

type Point struct {
	hashset.Serializable
	// contains filtered or unexported fields
}

Point is a object containing its two coordinates

func NewPoint

func NewPoint(x, y float64) *Point

NewPoint creates a point from coordinates

func (*Point) DistanceToLine

func (pt *Point) DistanceToLine(l *Line) float64

DistanceToLine calculates the distance from the point to a line

func (*Point) Equal

func (pt *Point) Equal(pt2 *Point) bool

Equal checks equality of two points with tolerance

func (*Point) GetCoords

func (pt *Point) GetCoords() (float64, float64)

GetCoords returns its coordinates, should be only used for debugging

func (*Point) InHalfLineRange

func (pt *Point) InHalfLineRange(h *HalfLine) bool

InHalfLineRange checks if the point in the coordinate range of a half line. This function should only be used when the point is guaranteed to be on the line which the half line belong to

func (*Point) InSegmentRange

func (pt *Point) InSegmentRange(s *Segment) bool

InSegmentRange checks if the point in the coordinate range of a segment. This function should only be used when the point is guaranteed to be on the line which the segment belong to

func (*Point) OnCircle

func (pt *Point) OnCircle(c *Circle) bool

OnCircle checks if the point is on a circle

func (*Point) OnHalfLine

func (pt *Point) OnHalfLine(h *HalfLine) bool

OnHalfLine checks if the point is on a half line

func (*Point) OnLine

func (pt *Point) OnLine(l *Line) bool

OnLine checks if the point is on a line

func (*Point) OnSegment

func (pt *Point) OnSegment(s *Segment) bool

OnSegment checks if the point is on a segment

func (*Point) Serialize

func (pt *Point) Serialize() interface{}

Serialize returns the hash of a point

type Segment

type Segment struct {
	hashset.Serializable
	// contains filtered or unexported fields
}

Segment is uniquely determined by its sorted endpoints

func NewSegment

func NewSegment(pt1, pt2 *Point) *Segment

NewSegment creates a segment from two points

func NewSegmentFromDirection

func NewSegmentFromDirection(start *Point, direction *Vector2D, length float64) *Segment

NewSegmentFromDirection creates a segment with one point, a direction and length

func (*Segment) Bisector

func (s *Segment) Bisector() *Line

Bisector returns a line as the bisector of the segment

func (*Segment) ContainsPoint

func (s *Segment) ContainsPoint(pt *Point) bool

ContainsPoint checks if a point is on the segment

func (*Segment) GetEndPoints

func (s *Segment) GetEndPoints() (*Point, *Point)

GetEndPoints returns both end points of a segment

func (*Segment) GetRandomPoint

func (s *Segment) GetRandomPoint() *Point

GetRandomPoint returns a random point on the segment

func (*Segment) IntersectCircle

func (s *Segment) IntersectCircle(c *Circle) *Intersection

IntersectCircle returns intersections with a circle

func (*Segment) IntersectHalfLine

func (s *Segment) IntersectHalfLine(h *HalfLine) *Intersection

IntersectHalfLine returns intersections with a half line

func (*Segment) IntersectLine

func (s *Segment) IntersectLine(l *Line) *Intersection

IntersectLine returns intersections with a line

func (*Segment) IntersectSegment

func (s *Segment) IntersectSegment(s2 *Segment) *Intersection

IntersectSegment returns intersections with a segment

func (*Segment) Length

func (s *Segment) Length() float64

Length returns the length of the segment

func (*Segment) PointInRange

func (s *Segment) PointInRange(pt *Point) bool

PointInRange checks whether a point is in the coordinates range of the segment

func (*Segment) Serialize

func (s *Segment) Serialize() interface{}

Serialize returns the hash of the segment

type Vector2D

type Vector2D struct {
	// contains filtered or unexported fields
}

Vector2D is a 2D vector object

func NewVector2D

func NewVector2D(x, y float64) *Vector2D

NewVector2D creates a 2D vector from its components

func NewVector2DFromTwoPoints

func NewVector2DFromTwoPoints(pt1, pt2 *Point) *Vector2D

NewVector2DFromTwoPoints creates a 2D vector from two points, pt1 to pt2

func (*Vector2D) Clone

func (v *Vector2D) Clone() *Vector2D

Clone returns a copy of the vector, since a vector can be modified

func (*Vector2D) Length

func (v *Vector2D) Length() float64

Length returns the norm of a vector

func (*Vector2D) NormalVector

func (v *Vector2D) NormalVector() *Vector2D

NormalVector gets a new normal vector by rotating Pi/2 counter clockwise

func (*Vector2D) Normalize

func (v *Vector2D) Normalize()

Normalize sets the length of vector to 1, reserving its direction

func (*Vector2D) SetLength

func (v *Vector2D) SetLength(l float64)

SetLength sets the length of vector to a certain value

Jump to

Keyboard shortcuts

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