Documentation
¶
Index ¶
- func AbsInt(x int) int
- func CalcPolygonArea(vertexes []Coord) int
- func DistanceOf(a, b Coord) float64
- func IsOnSegment(q, p1, p2 Coord) bool
- func IsSegmentIntersect(p1, q1, p2, q2 Coord) bool
- func MaxInt(x, y int) int
- func MinInt(x, y int) int
- func OrientationOfCoord(p1, p2, p3 Coord) int
- type Circle
- type ConvexPolygon
- type Coord
- type Rectangle
- type Triangle
- type Vector
- func (a *Vector) Add(b *Vector) Vector
- func (a *Vector) Cross(b *Vector) int
- func (a *Vector) Dot(b *Vector) int
- func (a *Vector) GetAngle(b *Vector) float64
- func (a *Vector) Length() float64
- func (a *Vector) Mul(m float64) Vector
- func (a *Vector) Normalize() Vector
- func (a *Vector) Rotate(angle float64) Vector
- func (a *Vector) SquaredLength() int
- func (a *Vector) Sub(b *Vector) Vector
- func (a Vector) ToCoord(start Coord) Coord
- func (a *Vector) Trunc(ratio float64) Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcPolygonArea ¶
func IsSegmentIntersect ¶
线段(p1,q1)与线段(p2,q2)是否相交
- General Case: – (p1, q1, p2) 和 (p1, q1, q2) have different orientations and – (p2, q2, p1) and (p2, q2, q1) have different orientations.
- Special Case – (p1, q1, p2), (p1, q1, q2), (p2, q2, p1), and (p2, q2, q1) are all collinear and – the x-projections of (p1, q1) and (p2, q2) intersect – the y-projections of (p1, q1) and (p2, q2) intersect
func OrientationOfCoord ¶
3个坐标的朝向 0 --> p, q, r 共线 1 --> 顺时针 2 --> 逆时针 Slope of line segment (p1, p2): σ = (y2 - y1)/(x2 - x1) Slope of line segment (p2, p3): τ = (y3 - y2)/(x3 - x2) If σ > τ, the orientation is clockwise (right turn)
Types ¶
type ConvexPolygon ¶
type ConvexPolygon struct {
Vertexes []Coord
}
凸多边形
func (*ConvexPolygon) Contains ¶
func (c *ConvexPolygon) Contains(x, y int) bool
type Coord ¶
坐标
func SegmentIntersectPoint ¶
线段(p1,q1)与线段(p2,q2)的交点,假设两条线段已经相交 当已经确定两个线段AB和CD是相交的时候,我们可以把AB和CD看成一个四边形的两条对角线,它们相交与点O, 我们可以通过三角形面积公式求出ABC和ABD的面积,它们的比值就是OC和OD的比值,然后再用定比分点公式求出O的坐标。 see https://leetcode-cn.com/problems/intersection-lcci/solution/
type Triangle ¶
type Triangle struct {
Vertexes [3]Coord
}
三角形
func NewTriangle ¶
type Vector ¶
type Vector struct {
X, Y int
}
二维向量
func NewVectorFrom ¶
func (*Vector) Rotate ¶
向量按照角度逆时针旋转获得新的向量,如果需要顺时针旋转,angle传入负值 对于任意两个不同点A和B,A绕B旋转θ角度后的坐标为: (Δx*cosθ- Δy * sinθ+ xB, Δy*cosθ + Δx * sinθ+ yB )
func (*Vector) SquaredLength ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.