geom

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVecAngle

func GetVecAngle(a, b *Vector) float64

获取2个相交向量的角度, cosθ = a x b / |a| |b|

func IntMax

func IntMax(x, y int) int

func IntMin

func IntMin(x, y int) int

Types

type Circle

type Circle struct {
	Center Point // 中心点
	Radius int   // 半径
}

圆形

func NewCircle

func NewCircle(center Point, radius int) Circle

func (*Circle) CrossPoint

func (c *Circle) CrossPoint(point Point) Point

点到圆心的线段和圆的交点

func (*Circle) SurroundRect

func (c *Circle) SurroundRect() Rectangle

获取包围矩形

type Point

type Point struct {
	X, Y int
}

func NewPoint

func NewPoint(x, y int) *Point

func (*Point) Distance

func (a *Point) Distance(b *Point) float64

两点之间的距离

func (*Point) Equal

func (a *Point) Equal(b *Point) bool

type Rectangle

type Rectangle struct {
	Point             // 左下角原点
	Width, Height int // 宽度、高度
}

四边形

func NewRectangle

func NewRectangle(x, y, w, h int) Rectangle

func RectIntersect

func RectIntersect(a *Rectangle, b *Rectangle) Rectangle

矩形相交区域

func RectUnion

func RectUnion(a *Rectangle, b *Rectangle) Rectangle

矩形结合区域

func (*Rectangle) Contains

func (r *Rectangle) Contains(x, y int) bool

点是否在矩形内

func (*Rectangle) ContainsPoint

func (r *Rectangle) ContainsPoint(pt Point) bool

点是否在矩形内

func (*Rectangle) ContainsRegion

func (r *Rectangle) ContainsRegion(rec *Rectangle) bool

是否包含

func (*Rectangle) GetVertexes

func (r *Rectangle) GetVertexes() [4]Point

四个顶点

func (*Rectangle) Inflate

func (r *Rectangle) Inflate(width, height int)

展开或者收缩矩形

func (*Rectangle) IsIntersectsWith

func (r *Rectangle) IsIntersectsWith(rec *Rectangle) bool

是否相交

type Vector

type Vector struct {
	X, Y int
}

二维向量

func NewVectorFrom

func NewVectorFrom(a, b Point) Vector

func (*Vector) Add

func (a *Vector) Add(b *Vector) Vector

加法

func (*Vector) Cross

func (a *Vector) Cross(b *Vector) int64

叉积(cross product)

func (*Vector) Dot

func (a *Vector) Dot(b *Vector) int64

点积(dot product)

func (*Vector) Length

func (a *Vector) Length() float64

向量长度

func (*Vector) Mul

func (a *Vector) Mul(m float64) Vector

乘法

func (*Vector) Normalize

func (a *Vector) Normalize() Vector

单位向量

func (*Vector) Rotate

func (a *Vector) Rotate(angle float64) Vector

向量按照角度逆时针旋转获得新的向量,如果需要顺时针旋转,angle传入负值 对于任意两个不同点A和B,A绕B旋转θ角度后的坐标为: (Δx*cosθ- Δy * sinθ+ xB, Δy*cosθ + Δx * sinθ+ yB )

func (*Vector) Sub

func (a *Vector) Sub(b *Vector) Vector

减法

func (Vector) ToPoint

func (a Vector) ToPoint(start Point) Point

转换成坐标

func (*Vector) Trunc

func (a *Vector) Trunc(ratio float64) Vector

按比例截断

Jump to

Keyboard shortcuts

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