Documentation ¶
Index ¶
- func AngleBetweenVectors(v1, v2 Vector) float64
- func AssertLineSegmentValid(lineSegments ...LineSegment)
- func AssertPointValid(points ...Point)
- func AssertPolygonValid(polygons ...Polygon)
- func AssertVector2Valid(vectors ...Vector2)
- func AssertVector3Valid(vectors ...Vector3)
- func CalcAngleDifference[T constraints.Number](a, b T) float64
- func CalcAngleWithDirection2D(direction Direction2D) float64
- func CalcLineSegmentCollinearWithEpsilon[T constraints.Number](line1, line2 LineSegment, epsilon T) bool
- func CalcLineSegmentDistanceToPoint(line LineSegment, point Point) float64
- func CalcPolygonCircumscribedCircleRadius(polygon Polygon) float64
- func CalcTriangleAreaTwice(a, b, c Vector2) float64
- type Circle
- func (c Circle) Contains(point Vector2) bool
- func (c Circle) GetArea() float64
- func (c Circle) GetCenter() Vector2
- func (c Circle) GetCenterDistance(c2 Circle) float64
- func (c Circle) GetCircumference() float64
- func (c Circle) GetDiameter() float64
- func (c Circle) GetIntersectionPoints(c2 Circle) (Vector2, Vector2)
- func (c Circle) GetRadius() float64
- func (c Circle) Intersect(c2 Circle) bool
- func (c Circle) Overlap(c2 Circle) bool
- type Direction2D
- func CalcDirection2DWithAngle[T constraints.Number](angle T) Direction2D
- func CalcOppositionDirection2D(direction Direction2D) Direction2D
- func Direction2D4() []Direction2D
- func Direction2D8() []Direction2D
- func Direction2DDown() Direction2D
- func Direction2DLeft() Direction2D
- func Direction2DLeftDown() Direction2D
- func Direction2DLeftUp() Direction2D
- func Direction2DRight() Direction2D
- func Direction2DRightDown() Direction2D
- func Direction2DRightUp() Direction2D
- func Direction2DUnknown() Direction2D
- func Direction2DUp() Direction2D
- type FloorPlan
- type Line
- func (l Line) IsPointAbove(point Point) bool
- func (l Line) IsPointBelow(point Point) bool
- func (l Line) IsPointLeft(point Point) bool
- func (l Line) IsPointOn(point Point) bool
- func (l Line) IsPointOnOrAbove(point Point) bool
- func (l Line) IsPointOnOrBelow(point Point) bool
- func (l Line) IsPointRight(point Point) bool
- type LineSegment
- type Point
- func CalcLineSegmentPointProjection(line LineSegment, point Point) Point
- func CalcLineSegmentPointProjectionDistance(line LineSegment, point Point) (projection Point, distance float64)
- func CalcPolygonCentroid(polygon Polygon) Point
- func CalcPolygonCircumscribedCircleCenter(polygon Polygon) Point
- func CalcPolygonPointProjection(polygon Polygon, point Point) (projection Point, distance float64)
- func CalcPolygonVerticesCentroid(polygon Polygon) Point
- func CalcRectangleVerticesCentroid(rectangle Polygon) Point
- func NewPoint[V constraints.Number](x, y V) Point
- type Polygon
- func (p Polygon) Centroid() Point
- func (p Polygon) CircumscribedCircleCenter() Point
- func (p Polygon) CircumscribedCircleRadius() float64
- func (p Polygon) CircumscribedCircleRadiusWithVerticesCentroid() float64
- func (p Polygon) GetEdges() []LineSegment
- func (p Polygon) IsPointInside(point Point) bool
- func (p Polygon) IsPointOnEdge(point Point) bool
- func (p Polygon) VerticesCentroid() Point
- type Position
- type PreviewBoard2D
- type Vector
- func (v Vector) Add(v2 Vector) Vector
- func (v Vector) Angle(v2 Vector) float64
- func (v Vector) Clone() Vector
- func (v Vector) Cross3D(v2 Vector3) Vector
- func (v Vector) Div(scalar float64) Vector
- func (v Vector) Dot(v2 Vector) float64
- func (v Vector) Equal(v2 Vector) bool
- func (v Vector) IsOrthogonal(v2 Vector) bool
- func (v Vector) IsZero() bool
- func (v Vector) Key() string
- func (v Vector) Length() float64
- func (v Vector) Mul(scalar float64) Vector
- func (v Vector) Normalize() Vector
- func (v Vector) ProjectTo(v2 Vector) Vector
- func (v Vector) ReflectBy(normal Vector) Vector
- func (v Vector) RejectFrom(v2 Vector) Vector
- func (v Vector) Sub(v2 Vector) Vector
- type Vector2
- func (v Vector2) Cross2D(v2 Vector2) float64
- func (v Vector2) Distance2D(v2 Vector2) float64
- func (v Vector2) DistanceSquared2D(v2 Vector2) float64
- func (v Vector2) GetX() float64
- func (v Vector2) GetXY() (x, y float64)
- func (v Vector2) GetY() float64
- func (v Vector2) PolarAngle(v2 Vector2) float64
- func (v Vector2) Quadrant() int
- type Vector3
- type Vector4
- type Vector5
- type Vector6
- type Vector7
- type Vector8
- type Vector9
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AngleBetweenVectors ¶
AngleBetweenVectors 计算两个向量之间的夹角
func AssertLineSegmentValid ¶
func AssertLineSegmentValid(lineSegments ...LineSegment)
AssertLineSegmentValid 断言检查线段是否有效
func AssertPolygonValid ¶
func AssertPolygonValid(polygons ...Polygon)
AssertPolygonValid 断言检查多边形是否有效
func AssertVector2Valid ¶
func AssertVector2Valid(vectors ...Vector2)
AssertVector2Valid 断言检查二维向量是否有效
func AssertVector3Valid ¶
func AssertVector3Valid(vectors ...Vector3)
AssertVector3Valid 断言检查三维向量是否有效
func CalcAngleDifference ¶
func CalcAngleDifference[T constraints.Number](a, b T) float64
CalcAngleDifference 计算两个极角之间的最小角度差。 结果在 -180 到 180 度之间,适用于极角、方位角或其他类似场景。
func CalcAngleWithDirection2D ¶
func CalcAngleWithDirection2D(direction Direction2D) float64
CalcAngleWithDirection2D 计算二维方向的角度
func CalcLineSegmentCollinearWithEpsilon ¶
func CalcLineSegmentCollinearWithEpsilon[T constraints.Number](line1, line2 LineSegment, epsilon T) bool
CalcLineSegmentCollinearWithEpsilon 计算两条线段是否共线,允许一定的误差来包容浮点数计算的误差
func CalcLineSegmentDistanceToPoint ¶
func CalcLineSegmentDistanceToPoint(line LineSegment, point Point) float64
CalcLineSegmentDistanceToPoint 计算点到线段的距禂
- 如果点在线段上,则距离为 0
- 如果点在线段的延长线上,则距离为点到线段两个端点的最小距离
- 否则,计算点到线段的投影点,然后计算点到投影点的距离
- 参考:https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
func CalcPolygonCircumscribedCircleRadius ¶
CalcPolygonCircumscribedCircleRadius 计算多边形外接圆的半径
func CalcTriangleAreaTwice ¶
CalcTriangleAreaTwice 计算三角形面积的两倍
Types ¶
type Circle ¶
func (Circle) GetCenterDistance ¶
GetCenterDistance 计算两个圆心之间的距离
func (Circle) GetIntersectionPoints ¶
GetIntersectionPoints 获取两个圆的交点,如果没有交点则返回两个零向量
type Direction2D ¶
type Direction2D = Vector2
Direction2D 二维方向
func CalcDirection2DWithAngle ¶
func CalcDirection2DWithAngle[T constraints.Number](angle T) Direction2D
CalcDirection2DWithAngle 通过角度计算二维方向
func CalcOppositionDirection2D ¶
func CalcOppositionDirection2D(direction Direction2D) Direction2D
CalcOppositionDirection2D 计算二维方向的反方向
type FloorPlan ¶
type FloorPlan []string
FloorPlan 平面图
func (FloorPlan) IsInBounds ¶
IsInBounds 检查位置是否在边界内
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line 直线是由一个点和斜率定义的
func (Line) IsPointOnOrAbove ¶
IsPointOnOrAbove 判断点是否在直线上或者在直线上方
func (Line) IsPointOnOrBelow ¶
IsPointOnOrBelow 判断点是否在直线上或者在直线下方
type LineSegment ¶
type LineSegment []Point
LineSegment 由至少两个点组成的线段
func CalcLineSegmentOverlap ¶
func CalcLineSegmentOverlap(line1, line2 LineSegment) (overlap LineSegment, isOverlap bool)
CalcLineSegmentOverlap 通过对点进行排序来检查两条共线线段是否重叠,返回重叠线段
func (LineSegment) ClosestPoint ¶
func (l LineSegment) ClosestPoint(point Point) Point
ClosestPoint 计算一个点到该线段的最近的点
func (LineSegment) IsPointOnSegment ¶
func (l LineSegment) IsPointOnSegment(point Point) bool
IsPointOnSegment 判断一个给定的点是否在该线段上,允许一定的误差来包容浮点数计算的误差,但不允许点超出线段的范围
type Point ¶
type Point = Vector2
Point 由二维向量组成的点
func CalcLineSegmentPointProjection ¶
func CalcLineSegmentPointProjection(line LineSegment, point Point) Point
CalcLineSegmentPointProjection 计算点在线段上的投影
- 根据向量的投影公式计算点在线段上的投影,然后将点投影到线段上,得到投影点
- 参考:https://en.wikipedia.org/wiki/Vector_projection
func CalcLineSegmentPointProjectionDistance ¶
func CalcLineSegmentPointProjectionDistance(line LineSegment, point Point) (projection Point, distance float64)
CalcLineSegmentPointProjectionDistance 计算点到线段的投影点以及点到投影点的距离
func CalcPolygonCentroid ¶
CalcPolygonCentroid 计算多边形质心
func CalcPolygonCircumscribedCircleCenter ¶
CalcPolygonCircumscribedCircleCenter 计算多边形外接圆的圆心
func CalcPolygonPointProjection ¶
CalcPolygonPointProjection 给定一个点和一个多边形,计算多边形边界上与该点距离最短的点,并返回投影点和距离
func CalcPolygonVerticesCentroid ¶
CalcPolygonVerticesCentroid 基于多边形的顶点的平均值计算质心
func CalcRectangleVerticesCentroid ¶
CalcRectangleVerticesCentroid 基于矩形的顶点的平均值计算质心
type Polygon ¶
type Polygon []Point
Polygon 由至少三个点组成的多边形
func (Polygon) CircumscribedCircleCenter ¶
CircumscribedCircleCenter 计算多边形外接圆的圆心
func (Polygon) CircumscribedCircleRadius ¶
CircumscribedCircleRadius 计算多边形外接圆的半径
func (Polygon) CircumscribedCircleRadiusWithVerticesCentroid ¶
CircumscribedCircleRadiusWithVerticesCentroid 基于多边形的顶点平均值计算的质心计算多边形外接圆的半径
func (Polygon) IsPointInside ¶
IsPointInside 判断点是否在多边形内
func (Polygon) IsPointOnEdge ¶
IsPointOnEdge 判断点是否在多边形的边上
func (Polygon) VerticesCentroid ¶
VerticesCentroid 基于多边形的顶点的平均值计算质心
type PreviewBoard2D ¶
type PreviewBoard2D struct {
// contains filtered or unexported fields
}
PreviewBoard2D 用于调试等行为的预览画板,该画板生成一个简单的 HTML 页面,该页面包含一个 canvas 元素,可以在该画板上绘制图形。 另外也会根据 EventStream 的事件流来试试更新画板上的图形
func NewPreviewBoard2D ¶
func NewPreviewBoard2D(fps, width, height int) *PreviewBoard2D
NewPreviewBoard2D 创建一个 2D 预览画板
func (*PreviewBoard2D) Start ¶
func (b *PreviewBoard2D) Start(addr string) error
func (*PreviewBoard2D) Stop ¶
func (b *PreviewBoard2D) Stop()
func (*PreviewBoard2D) Update ¶
func (b *PreviewBoard2D) Update(vec2 ...Vector)
type Vector2 ¶
type Vector2 = Vector
func CalcOffsetInDirection2D ¶
func CalcOffsetInDirection2D[T constraints.Number](vector Vector2, direction Direction2D, offset T) Vector2
CalcOffsetInDirection2D 计算特定方向上按照指定距离偏移后的坐标
func Vector2Zero ¶
func Vector2Zero() Vector2
func (Vector2) PolarAngle ¶
PolarAngle 极坐标角度,即点在极坐标系中的角度