mathUtil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

math 的增强功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

int 类型取绝对值

func AbsInt16

func AbsInt16(x int16) int16

int 类型取绝对值

func AntiClockwise

func AntiClockwise(v1 Vector2, v2 Vector2) bool

AntiClockwise 是否为逆时针方向

func Between

func Between(x int, start int, end int) bool

判断当前数字是否在范围中,前包后不包 eg between(1,1,3) true eg between(3,1,3) false

func BetweenInt16

func BetweenInt16(x int16, start int16, end int16) bool

判断当前数字是否在范围中,前包后不包 eg between(1,1,3) true eg between(3,1,3) false

func DegAngle

func DegAngle(v1 Vector2, v2 Vector2) float64

DegAngle 计算角度

func GetDistance

func GetDistance(a Vector3, b Vector3) float64

GetDistance 求两点间距离

Types

type Axis

type Axis int

Axis enumerates the 3 axes of ℝ³.

const (
	XAxis Axis = iota
	YAxis
	ZAxis
)

The three axes of ℝ³.

type Vector2

type Vector2 struct {
	X float64
	Y float64
}

func Deg2Vector

func Deg2Vector(deg float64) Vector2

Deg2Vector 角度转为向量

func Rad2Vector

func Rad2Vector(rad float64) Vector2

Rad2Vector 弧度转向量

func (Vector2) Norm

func (v Vector2) Norm() float64

func (Vector2) VectorDegAngle

func (v Vector2) VectorDegAngle() float64

VectorDegAngle 计算基于水平线的角度

type Vector3

type Vector3 struct {
	X, Y, Z float64
}

Vector3 represents a point in ℝ³.

func Normalize3

func Normalize3(a Vector3) Vector3

Normalize3 返回:单位化向量

func (Vector3) Abs

func (v Vector3) Abs() Vector3

Abs returns the Vector3 with nonnegative components.

func (Vector3) Add

func (v Vector3) Add(ov Vector3) Vector3

Add returns the standard Vector3 sum of v and ov.

func (Vector3) Angle

func (v Vector3) Angle(ov Vector3) s1.Angle

Angle returns the angle between v and ov.

func (Vector3) ApproxEqual

func (v Vector3) ApproxEqual(ov Vector3) bool

ApproxEqual reports whether v and ov are equal within a small epsilon.

func (*Vector3) Clone

func (v *Vector3) Clone() Vector3

Clone 三维向量:拷贝

func (Vector3) Cmp

func (v Vector3) Cmp(ov Vector3) int

Cmp compares v and ov lexicographically and returns:

-1 if v <  ov
 0 if v == ov
+1 if v >  ov

This method is based on C++'s std::lexicographical_compare. Two entities are compared element by element with the given operator. The first mismatch defines which is less (or greater) than the other. If both have equivalent values they are lexicographically equal.

func (Vector3) Cross

func (v Vector3) Cross(ov Vector3) Vector3

Cross returns the standard cross product of v and ov.

func (Vector3) Distance

func (v Vector3) Distance(ov Vector3) float64

Distance returns the Euclidean distance between v and ov.

func (Vector3) Dot

func (v Vector3) Dot(ov Vector3) float64

Dot returns the standard dot product of v and ov.

func (Vector3) IsUnit

func (v Vector3) IsUnit() bool

IsUnit returns whether this Vector3 is of approximately unit length.

func (Vector3) LargestComponent

func (v Vector3) LargestComponent() Axis

LargestComponent returns the axis that represents the largest component in this Vector3.

func (Vector3) Mul

func (v Vector3) Mul(m float64) Vector3

Mul returns the standard scalar product of v and m.

func (Vector3) Norm

func (v Vector3) Norm() float64

Norm returns the Vector3's norm.

func (Vector3) Norm2

func (v Vector3) Norm2() float64

Norm2 returns the square of the norm.

func (Vector3) Normalize

func (v Vector3) Normalize() Vector3

Normalize returns a unit Vector3 in the same direction as v.

func (Vector3) Ortho

func (v Vector3) Ortho() Vector3

Ortho returns a unit Vector3 that is orthogonal to v. Ortho(-v) = -Ortho(v) for all v.

func (Vector3) SmallestComponent

func (v Vector3) SmallestComponent() Axis

SmallestComponent returns the axis that represents the smallest component in this Vector3.

func (Vector3) String

func (v Vector3) String() string

func (Vector3) Sub

func (v Vector3) Sub(ov Vector3) Vector3

Sub returns the standard Vector3 difference of v and ov.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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