geom

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AngleDegrees

func AngleDegrees(angleRadian float64) float64

func AngleRadian

func AngleRadian(angleDegrees float64) float64

func GaussJordanElimination

func GaussJordanElimination(A [][]float64, b []float64) ([]float64, error)

GaussJordanElimination 高斯-约旦消元法求解线性方程组 Ax = b

func InverseMatrix added in v0.3.5

func InverseMatrix(m [3][3]float64) ([3][3]float64, error)

InverseMatrix 计算 3x3 矩阵的逆

func NormalizeAngleDegrees

func NormalizeAngleDegrees(theta float64) float64

func NormalizeAngleRadian

func NormalizeAngleRadian(theta float64) float64

Types

type AffineMatrix

type AffineMatrix [2][3]float64

定义一个2x3的仿射变换矩阵

func NewAffineMatrix

func NewAffineMatrix(src, dst [3]Point) (AffineMatrix, error)

func NewRotationMat

func NewRotationMat(center Point, angleDeg float64) AffineMatrix

func NewTranslateRotationMat

func NewTranslateRotationMat(pA, pB Point, angleDeg float64) AffineMatrix

NewTranslateRotationMat transforms a point from coordinate system a2 to a1 在数学和计算机图形学中,旋转角度的正负通常遵循右手定则。默认情况下,顺时针方向被认为是负的,而逆时针方向被认为是正的。 O2相对于O1旋转度数

func (AffineMatrix) Transform

func (m AffineMatrix) Transform(p Point) Point

应用仿射变换到点上

type Bounds

type Bounds struct {
	Min Point
	Max Point
}

func BoundsFromImageRect

func BoundsFromImageRect(r image.Rectangle) *Bounds

func NewBounds

func NewBounds(x0, y0, x1, y1 float64) *Bounds

func (*Bounds) ToRect

func (b *Bounds) ToRect() *Rectangle

type Circle

type Circle struct {
	Centre   Point
	Diameter float64
}

func (*Circle) Bounds

func (c *Circle) Bounds() *Bounds

type CircleInt

type CircleInt[T constraints.Integer] struct {
	Center   PointInt[T]
	Diameter T
}

func (*CircleInt[T]) ToFloat64

func (e *CircleInt[T]) ToFloat64(factor float64) *Circle

type CircularArc

type CircularArc struct {
	Circle     Circle
	StartAngle float64
	EndAngle   float64
}

counter clockwise if clockwise ,Start.X,Start.Y <-> endX, endY

func CircularArcFromPoints

func CircularArcFromPoints(center, start, end Point) *CircularArc

func NewCircularArc

func NewCircularArc(circle Circle, startAngle, endAngle float64) *CircularArc

func (*CircularArc) Bounds

func (a *CircularArc) Bounds() *Bounds

func (*CircularArc) Sample

func (a *CircularArc) Sample(samples int) []Point

type CircularArc2

type CircularArc2 struct {
	Center Point
	Start  Point
	End    Point
}

func NewCircularArc2

func NewCircularArc2(center, start, end Point) *CircularArc2

func (*CircularArc2) ToCircularArc

func (a *CircularArc2) ToCircularArc() *CircularArc

type CircularArcInt

type CircularArcInt[T constraints.Integer] struct {
	Circle     CircleInt[T]
	StartAngle float64
	EndAngle   float64
}

func ArcIntFromFloat64

func ArcIntFromFloat64[T constraints.Integer](e *CircularArc, factor float64) *CircularArcInt[T]

func (*CircularArcInt[T]) ToFloat64

func (e *CircularArcInt[T]) ToFloat64(factor float64) *CircularArc

type Contour

type Contour struct {
	Start    Point
	Segments []Segment
}

A Contour is a closed sequence of connected linear or circular segments.

type Coord

type Coord struct{}

func (Coord) GetOuterPoints

func (c Coord) GetOuterPoints(points []Point) [4]Point

type Ellipse

type Ellipse struct {
	Centre    Point
	MajorAxis float64 // Length of the major axis
	MinorAxis float64 // Length of the minor axis
	Angle     float64 // Angle angle in degrees from the x-axis
}

func (*Ellipse) Area

func (e *Ellipse) Area() float64

func (*Ellipse) GetHalfAxes

func (e *Ellipse) GetHalfAxes() (float64, float64)

GetHalfAxes returns the half lengths of the major and minor axes.

func (*Ellipse) Perimeter

func (e *Ellipse) Perimeter() float64

type EllipticalArc

type EllipticalArc struct {
	Ellipse
	StartAngle float64
	EndAngle   float64
}

type GeneralFormLine added in v0.3.5

type GeneralFormLine struct {
	A float64
	B float64
	C float64
}

ax + by + c = 0

func NewGeneralFormLine

func NewGeneralFormLine(a, b, c float64) *GeneralFormLine

func (*GeneralFormLine) ToSlopeInterceptLine added in v0.3.5

func (l *GeneralFormLine) ToSlopeInterceptLine() *SlopeInterceptFormLine

func (*GeneralFormLine) ToStraightLine added in v0.3.5

func (l *GeneralFormLine) ToStraightLine() *StraightLine

type Interpolation

type Interpolation int
const (
	InterpolationCCW Interpolation = iota
	InterpolationClockwise
)

type LineSegment

type LineSegment struct {
	Start Point
	End   Point
}

func NewLineSegment added in v0.3.5

func NewLineSegment(start, end Point) *LineSegment

func (*LineSegment) ContainsPoint added in v0.3.5

func (l *LineSegment) ContainsPoint(p Point) bool

func (*LineSegment) IntersectionLineSegment added in v0.3.5

func (l *LineSegment) IntersectionLineSegment(l2 *LineSegment) (Point, bool)

func (*LineSegment) IntersectionRay added in v0.3.5

func (l *LineSegment) IntersectionRay(r *Ray) (Point, bool)

func (*LineSegment) IntersectionStraightLine added in v0.3.5

func (l *LineSegment) IntersectionStraightLine(sl *StraightLine) (Point, bool)

func (*LineSegment) ToSlopeInterceptFormLine added in v0.3.5

func (l *LineSegment) ToSlopeInterceptFormLine() *SlopeInterceptFormLine

func (*LineSegment) Vector

func (l *LineSegment) Vector() Vector

type LineSegmentInt added in v0.3.5

type LineSegmentInt[T constraints.Integer] struct {
	Start PointInt[T]
	End   PointInt[T]
}

func LineIntFromFloat64

func LineIntFromFloat64[T constraints.Integer](e *LineSegment, factor float64) *LineSegmentInt[T]

func (*LineSegmentInt[T]) ToFloat64 added in v0.3.5

func (l *LineSegmentInt[T]) ToFloat64(factor float64) *LineSegment

type Point

type Point struct {
	X float64
	Y float64
}

Point 结构体用于表示一个点

func Pt

func Pt(x, y float64) Point

func RandomPoint

func RandomPoint(min, max Point) Point

func (Point) Length

func (p Point) Length(p2 Point) float64

PointsLength 计算两点之间的向量长度

func (Point) Mirror

func (p Point) Mirror(line *GeneralFormLine) Point

func (Point) Rotate

func (p Point) Rotate(center Point, angleDeg float64) Point

func (Point) Vector

func (p Point) Vector(point Point) Vector

type Point3D

type Point3D struct {
	X float64
	Y float64
	Z float64
}

type Point3DInt

type Point3DInt[T constraints.Integer] struct {
	X T
	Y T
	Z T
}

func (*Point3DInt[T]) ToFloat64

func (l *Point3DInt[T]) ToFloat64(factor float64) *Point3D

type PointInt

type PointInt[T constraints.Integer] struct {
	X T
	Y T
}

PointInt 结构体用于表示一个点

func (*PointInt[T]) ToFloat64

func (l *PointInt[T]) ToFloat64(factor float64) *Point

type Polygon

type Polygon []Point

func (Polygon) ContainsPoint added in v0.3.5

func (p Polygon) ContainsPoint(point Point) bool

type PolynomialCurve added in v0.3.5

type PolynomialCurve struct {
	Coefficients []float64
	Angle        float64
}

func (*PolynomialCurve) ZeroAngleY added in v0.3.5

func (p *PolynomialCurve) ZeroAngleY(x float64) float64

type Ray added in v0.3.5

type Ray struct {
	Point
	Angle float64
}

func NewRay added in v0.3.5

func NewRay(p Point, angle float64) *Ray

func (*Ray) IntersectRay added in v0.3.5

func (l *Ray) IntersectRay(l2 *Ray) bool

func (*Ray) IntersectionRay added in v0.3.5

func (r *Ray) IntersectionRay(r2 *Ray) (Point, bool)

func (*Ray) IntersectionStraightLine added in v0.3.5

func (r *Ray) IntersectionStraightLine(l *StraightLine) (Point, bool)

func (*Ray) IsOnForwardRange added in v0.3.5

func (r *Ray) IsOnForwardRange(p Point) bool

判断点是否在射线的正向范围内

type Rectangle

type Rectangle struct {
	Center Point
	Width  float64
	Height float64
	Angle  float64
}

func NewRect

func NewRect(center Point, width, height float64, angleDeg float64) *Rectangle

func RectFromCorners

func RectFromCorners(points [4]Point) *Rectangle

func RectFromImageRect

func RectFromImageRect(r image.Rectangle) *Rectangle

func RectNoRotate

func RectNoRotate(x0, y0, x1, y1 float64) *Rectangle

func RectNoRotate2

func RectNoRotate2(ltp, rdp Point) *Rectangle

func (*Rectangle) Bounds

func (rect *Rectangle) Bounds() *Bounds

func (*Rectangle) ContainsPoint

func (rect *Rectangle) ContainsPoint(p Point) bool

图片就是第四象限,角度90+θ

func (*Rectangle) Corners

func (rect *Rectangle) Corners() [4]Point

type RectangleInt

type RectangleInt[T constraints.Integer] struct {
	Center PointInt[T]
	Width  T
	Height T
	Angle  float64
}

func NewRectInt

func NewRectInt[T constraints.Integer](center PointInt[T], width, height T, angle float64) *RectangleInt[T]

func RectIntFromFloat64

func RectIntFromFloat64[T constraints.Integer](e *Rectangle, factor float64) *RectangleInt[T]

func (*RectangleInt[T]) ToFloat64

func (rect *RectangleInt[T]) ToFloat64(factor float64) *Rectangle

type RegularPolygon

type RegularPolygon struct {
	Centre Point
	Radius float64
	Sides  int
}

type Segment

type Segment struct {
	Interpolation Interpolation
	End           Point
	Centre        Point
}

A Segment is a stroked line.

type SineWave added in v0.3.5

type SineWave struct {
	Amplitude     float64
	Frequency     float64
	PhaseShift    float64
	VerticalShift float64
	Angle         float64
}

func (*SineWave) ZeroAngleY added in v0.3.5

func (p *SineWave) ZeroAngleY(x float64) float64

type SlopeInterceptFormLine added in v0.3.5

type SlopeInterceptFormLine struct {
	Slope     float64
	Intercept float64
}

y=mx+b

func NewSlopeInterceptLine

func NewSlopeInterceptLine(m, b float64) *SlopeInterceptFormLine

func (*SlopeInterceptFormLine) IsVertical added in v0.3.5

func (l *SlopeInterceptFormLine) IsVertical() bool

func (*SlopeInterceptFormLine) ToGeneralFormLine added in v0.3.5

func (l *SlopeInterceptFormLine) ToGeneralFormLine() *GeneralFormLine

func (*SlopeInterceptFormLine) ToStraightLine added in v0.3.5

func (l *SlopeInterceptFormLine) ToStraightLine() *StraightLine

type StraightLine

type StraightLine struct {
	Point
	Angle float64
}

func NewStraightLine added in v0.3.5

func NewStraightLine(p Point, angle float64) *StraightLine

func (*StraightLine) ContainsPoint added in v0.3.5

func (l *StraightLine) ContainsPoint(p Point) bool

func (*StraightLine) IntersectStraightLine added in v0.3.5

func (l *StraightLine) IntersectStraightLine(l2 *StraightLine) bool

func (*StraightLine) IntersectionStraightLine added in v0.3.5

func (l *StraightLine) IntersectionStraightLine(l2 *StraightLine) (Point, bool)

func (*StraightLine) ToGeneralFormLine added in v0.3.5

func (l *StraightLine) ToGeneralFormLine() *GeneralFormLine

func (*StraightLine) ToSlopeInterceptLine

func (l *StraightLine) ToSlopeInterceptLine() *SlopeInterceptFormLine

type Triangle

type Triangle struct {
	A, B, C Point
}

type Vector

type Vector struct {
	X float64
	Y float64
}

func NewVector

func NewVector(p1, p2 Point) Vector

func (Vector) Angle

func (v Vector) Angle() float64

func (Vector) AngleWith

func (v Vector) AngleWith(v2 Vector) float64

计算同坐标两个向量之间的角度

func (Vector) CrossProduct added in v0.3.5

func (v Vector) CrossProduct(v2 Vector) float64

func (Vector) Length

func (v Vector) Length() float64

type VectorInt

type VectorInt[T constraints.Integer] struct {
	X T
	Y T
}

func (*VectorInt[T]) ToFloat64

func (l *VectorInt[T]) ToFloat64(factor float64) *Vector

Jump to

Keyboard shortcuts

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