aego/mathmodule
Absfunction
func Abs(x float) float
Abs returns the absolute value of x.
Example
dist := math.Abs(target - x)
AbsIntfunction
func AbsInt(x int) int
AbsInt returns the absolute value of an int.
Example
steps := math.AbsInt(to - from)
Acosfunction
func Acos(x float) float
Acos returns the angle in radians whose cosine is x, in [0, Pi].
Example
a := math.Acos(math.Dot(u, v))
Anglefunction
func Angle(v Vec2) float
Angle returns the direction of v in radians.
Example
node.SetRotation(math.Angle(velocity))
Asinfunction
func Asin(x float) float
Asin returns the angle in radians whose sine is x, in [-Pi/2, Pi/2].
Example
a := math.Asin(0.5)
Atan2function
func Atan2(y float, x float) float
Atan2 returns the angle in radians of the vector (x, y), in (-Pi, Pi].
Example
angle := math.Atan2(d.Y, d.X)
Ceilfunction
func Ceil(x float) float
Ceil returns the least whole number greater than or equal to x.
Example
pages := math.Ceil(float(count) / 10)
Clampfunction
func Clamp(v float, lo float, hi float) float
Clamp limits v to the range [lo, hi].
Example
x = math.Clamp(x, -10, 10)
ClampIntfunction
func ClampInt(v int, lo int, hi int) int
ClampInt limits an int to the range [lo, hi].
Example
level = math.ClampInt(level, 1, 10)
Cosfunction
func Cos(x float) float
Cos returns the cosine of an angle in radians.
Example
x := math.Cos(angle) * Radius
Crossfunction
func Cross(a Vec2, b Vec2) float
Cross returns the z component of the 3D cross product; its sign tells on which side b lies.
Example
left := math.Cross(forward, toTarget) < 0
Cross3function
func Cross3(a Vec3, b Vec3) Vec3
Cross3 returns a vector perpendicular to a and b.
Example
right := math.Cross3(forward, Vec3{0, 1, 0})
Deg2Radfunction
func Deg2Rad(degrees float) float
Deg2Rad converts degrees to radians.
Example
node.SetRotation(math.Deg2Rad(45))
Distfunction
func Dist(a Vec2, b Vec2) float
Dist returns the distance between two points.
Example
if math.Dist(pos, goal) < 0.1 {
Dist3function
func Dist3(a Vec3, b Vec3) float
Dist3 returns the distance between two 3D points.
Example
near := math.Dist3(a, b) < 2
Dotfunction
func Dot(a Vec2, b Vec2) float
Dot returns the dot product of two Vec2.
Example
facing := math.Dot(forward, toPlayer) > 0
Dot3function
func Dot3(a Vec3, b Vec3) float
Dot3 returns the dot product of two Vec3.
Example
lit := math.Dot3(normal, light) > 0
Expfunction
func Exp(x float) float
Exp returns e raised to the power x.
Example
decay := math.Exp(-dt * Damping)
Floorfunction
func Floor(x float) float
Floor returns the greatest whole number less than or equal to x.
Example
cell := math.Floor(pos.X / 32)
Lengthfunction
func Length(v Vec2) float
Length returns the length of a Vec2.
Example
speed := math.Length(velocity)
Length3function
func Length3(v Vec3) float
Length3 returns the length of a Vec3.
Example
d := math.Length3(velocity)
Lerpfunction
func Lerp(a float, b float, t float) float
Lerp blends from a to b. t = 0 gives a, t = 1 gives b; t is not clamped.
Example
zoom = math.Lerp(zoom, target, 5 * dt)
LerpVec2function
func LerpVec2(a Vec2, b Vec2, t float) Vec2
LerpVec2 blends two Vec2 component-wise.
Example
cam = math.LerpVec2(cam, target, 4 * dt)
LerpVec3function
func LerpVec3(a Vec3, b Vec3, t float) Vec3
LerpVec3 blends two Vec3 component-wise.
Example
p := math.LerpVec3(from, to, t)
Logfunction
func Log(x float) float
Log returns the natural logarithm of x.
Example
octave := math.Log(freq) / math.Log(2)
Maxfunction
func Max(a float, b float) float
Max returns the larger of a and b.
Example
hp := math.Max(hp - damage, 0)
MaxIntfunction
func MaxInt(a int, b int) int
MaxInt returns the larger of two ints.
Example
lives = math.MaxInt(lives - 1, 0)
Minfunction
func Min(a float, b float) float
Min returns the smaller of a and b.
Example
speed := math.Min(speed, MaxSpeed)
MinIntfunction
func MinInt(a int, b int) int
MinInt returns the smaller of two ints.
Example
ammo = math.MinInt(ammo + 10, MaxAmmo)
Normalizefunction
func Normalize(v Vec2) Vec2
Normalize returns v scaled to length 1. A zero vector stays zero.
Example
dir := math.Normalize(target - pos)
Normalize3function
func Normalize3(v Vec3) Vec3
Normalize3 returns v scaled to length 1.
Example
dir := math.Normalize3(target - pos)
Powfunction
func Pow(x float, y float) float
Pow returns x raised to the power y.
Example
ease := math.Pow(t, 3)
QuatAxisAnglefunction
func QuatAxisAngle(axis Vec3, radians float) Quat
QuatAxisAngle builds a rotation of an angle in radians around an axis.
Example
spin := math.QuatAxisAngle(Vec3{0, 1, 0}, Speed * dt)
QuatEulerfunction
func QuatEuler(x float, y float, z float) Quat
QuatEuler builds a rotation from Euler angles in radians, applied as Z·Y·X.
Example
node.SetRotation3(math.QuatEuler(0, math.Pi, 0))
QuatLookDirfunction
func QuatLookDir(dir Vec3) Quat
QuatLookDir returns the rotation that points -Z along d.
Example
node.SetRotation3(math.QuatLookDir(target - pos))
QuatMulfunction
func QuatMul(a Quat, b Quat) Quat
QuatMul combines two rotations: b is applied first, then a.
Example
node.SetRotation3(math.QuatMul(spin, node.Rotation3()))
QuatRotatefunction
func QuatRotate(q Quat, v Vec3) Vec3
QuatRotate rotates a vector by q.
Example
forward := math.QuatRotate(node.Rotation3(), Vec3{0, 0, -1})
QuatSlerpfunction
func QuatSlerp(a Quat, b Quat, t float) Quat
QuatSlerp blends two rotations along the shortest arc.
Example
r := math.QuatSlerp(from, to, 0.5)
Rad2Degfunction
func Rad2Deg(radians float) float
Rad2Deg converts radians to degrees.
Example
log.Info(string(math.Rad2Deg(node.Rotation())))
Rotatefunction
func Rotate(v Vec2, radians float) Vec2
Rotate turns v clockwise by an angle in radians.
Example
offset := math.Rotate(Vec2{1, 0}, node.Rotation())
Roundfunction
func Round(x float) float
Round returns x rounded to the nearest whole number; halves round away from zero.
Example
snapped := math.Round(x)
Signfunction
func Sign(x float) float
Sign returns -1, 0 or 1 depending on the sign of x.
Example
dir := math.Sign(input.Axis("horizontal"))
Sinfunction
func Sin(x float) float
Sin returns the sine of an angle in radians.
Example
y := math.Sin(time.Elapsed() * 2) * Amplitude
Sqrtfunction
func Sqrt(x float) float
Sqrt returns the square root of x. Negative x gives NaN.
Example
d := math.Sqrt(dx*dx + dy*dy)
Tanfunction
func Tan(x float) float
Tan returns the tangent of an angle in radians.
Example
slope := math.Tan(math.Deg2Rad(30))
Truncfunction
func Trunc(x float) float
Trunc drops the fractional part of x.
Example
whole := math.Trunc(-2.7)
Piconst
const Pi float
Pi is the ratio of a circle's circumference to its diameter, about 3.14159.
Tauconst
const Tau float
Tau is a full turn in radians, 2·Pi.