Documentation
¶
Overview ¶
StreamForce 2D
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
StreamForce 2D ¶
Copyright (c) 2026 AxleByte Studios. ¶
Created by Ilzr Kr.
Licensed under the BSD 3-Clause License. See LICENSE for details.
Index ¶
- Constants
- func Abs(a float64) float64
- func AbsoluteAngles(v *Vec3) (float64, float64)
- func AngleBetween(v1, v2 *Vec3) float64
- func AnglesBetween(v1, v2 *Vec3) (float64, float64)
- func Atan2(y, x float64) float64
- func BinarySearch(s []float64, target float64) (uint32, bool)
- func BisectAngle(a, b float64) float64
- func CrossPoints(ax, ay, az float64, bx, by, bz float64) (float64, float64, float64)
- func Degrees(radians float64) float64
- func DotPoints(ax, ay, az float64, bx, by, bz float64) float64
- func Hypot(p, q float64) float64
- func Max(a, b float64) float64
- func Min(a, b float64) float64
- func NearlyBetween(min, value, max float64) bool
- func NearlyCompare(a, b float64) types.Result
- func NearlyEqual(a, b float64) bool
- func NearlyGreater(a, b float64) bool
- func NearlyLess(a, b float64) bool
- func NearlyMax(a, b float64) float64
- func NearlyMin(a, b float64) float64
- func NearlyNormal(value float64) bool
- func NearlyZero(a float64) bool
- func NormalizeAngle(angle float64) float64
- func NotZero(value float64) float64
- func PolygonArea2D(poly []*Vec3) float64
- func Radians(degrees float64) float64
- func SubtractPoints(ax, ay, az float64, bx, by, bz float64) (float64, float64, float64)
- type Plane
- type Quaternion
- func AxisAngle(axis *Vec3, angle float64) Quaternion
- func FromAxisAngle(axis *Vec3, angle float64) Quaternion
- func FromEuler(phi, theta, psi float64) Quaternion
- func FromToRotation(from, to *Vec3) Quaternion
- func LookRotation(forward, up *Vec3) Quaternion
- func NewQuaternion(c float64, x, y, z float64) Quaternion
- func QProd(qs ...*Quaternion) Quaternion
- func QSum(qs ...*Quaternion) Quaternion
- func (q *Quaternion) Conjugate() Quaternion
- func (q *Quaternion) Equals(other *Quaternion) bool
- func (q *Quaternion) Euler() (float64, float64, float64)
- func (q *Quaternion) Inverse() Quaternion
- func (q *Quaternion) Negative() Quaternion
- func (q *Quaternion) Norm() float64
- func (q *Quaternion) Norm2() float64
- func (q *Quaternion) RotMat() [3][3]float64
- func (q *Quaternion) Unit() Quaternion
- type Triangle
- type Vec2
- func (v1 *Vec2) Add(v2 *Vec2) Vec2
- func (v1 *Vec2) Copy() Vec2
- func (v1 *Vec2) Cross(v2 *Vec2) float64
- func (v1 *Vec2) Distance(v2 *Vec2) float64
- func (v1 *Vec2) Dot(v2 *Vec2) float64
- func (v1 *Vec2) Equals(v2 *Vec2) bool
- func (v1 *Vec2) Length() float64
- func (v1 *Vec2) Max(v2 *Vec2) Vec2
- func (v1 *Vec2) Min(v2 *Vec2) Vec2
- func (v1 *Vec2) MulScalar(s float64) Vec2
- func (v1 *Vec2) Multiply(v2 *Vec2) Vec2
- func (v1 Vec2) String() string
- func (v1 *Vec2) Sub(v2 *Vec2) Vec2
- func (v1 *Vec2) Unit() Vec2
- type Vec3
- func DirectionFromAngles(yaw, pitch float64) Vec3
- func LineIntersection3D(a, b, c, d *Vec3) (Vec3, bool)
- func NewVec3(x, y, z float64) Vec3
- func OffsetPolygon(poly []*Vec3, distance float64) []*Vec3
- func PointTowards(v1, v2 *Vec3, distance float64) Vec3
- func PolygonNormal(poly []*Vec3) Vec3
- func RotateVec3(q *Quaternion, vec *Vec3) Vec3
- func (v1 *Vec3) Add(v2 *Vec3) Vec3
- func (v1 *Vec3) Copy() Vec3
- func (v1 *Vec3) Cross(v2 *Vec3) Vec3
- func (v1 *Vec3) Distance(v2 *Vec3) float64
- func (v1 *Vec3) Dot(v2 *Vec3) float64
- func (v1 *Vec3) Equals(v2 *Vec3) bool
- func (v1 *Vec3) Length() float64
- func (v1 *Vec3) Max(v2 *Vec3) Vec3
- func (v1 *Vec3) Min(v2 *Vec3) Vec3
- func (v1 *Vec3) MulScalar(s float64) Vec3
- func (v1 *Vec3) Multiply(v2 *Vec3) Vec3
- func (v1 Vec3) String() string
- func (v1 *Vec3) Sub(v2 *Vec3) Vec3
- func (v1 *Vec3) Unit() Vec3
- func (v1 *Vec3) ZDiff(v2 *Vec3) float64
- type Vec4
- func (v1 *Vec4) Add(v2 *Vec4) Vec4
- func (v1 *Vec4) Copy() Vec4
- func (v1 *Vec4) Distance(v2 *Vec4) float64
- func (v1 *Vec4) Dot(v2 *Vec4) float64
- func (v1 *Vec4) Equals(v2 *Vec4) bool
- func (v1 *Vec4) Length() float64
- func (v1 *Vec4) Max(v2 *Vec4) Vec4
- func (v1 *Vec4) Min(v2 *Vec4) Vec4
- func (v1 *Vec4) MulScalar(s float64) Vec4
- func (v1 *Vec4) Multiply(v2 *Vec4) Vec4
- func (v1 Vec4) String() string
- func (v1 *Vec4) Sub(v2 *Vec4) Vec4
- func (v1 *Vec4) Unit() Vec4
- func (v1 *Vec4) ZDiff(v2 *Vec4) float64
Constants ¶
const ( // PI is the value of pi. PI float64 = math.Pi // RIGHT_ANGLE is the right angle, in radians. RIGHT_ANGLE float64 = math.Pi / 2 // CIRCUMFERENCE is the circumference of a circle, in radians. CIRCUMFERENCE float64 = 2 * math.Pi )
const ( // MAX_FLOAT32 is the maximum value of a float32. MAX_FLOAT32 float64 = math.MaxFloat32 )
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
Abs returns the absolute value of x.
Special cases are:
Abs(±Inf) = +Inf Abs(NaN) = NaN
Parameters:
- a: The value to get the absolute value of.
Returns:
- float64: The absolute value of the float64.
func AbsoluteAngles ¶
AbsoluteAngles returns the yaw and pitch angles of a vector, in radians. If the vector is `nil`, the angles are 0.0.
The angles are relative to the CanonicalAway vector.
Parameters:
- v: The vector to calculate the angles of.
Returns:
- float64: The yaw angle of the vector, in radians.
- float64: The pitch angle of the vector, in radians.
func AngleBetween ¶
AngleBetween returns the angle between two vectors, in radians. If either one of them is `nil`, the angle is 0.0.
Parameters:
- v1: The first vector to calculate the angle between.
- v2: The second vector to calculate the angle between.
Returns:
- float64: The angle between the two vectors, in radians.
func AnglesBetween ¶
AnglesBetween returns the yaw and pitch angles between two vectors, in radians. If either vector is `nil`, the angles are 0.0.
Parameters:
- v1: The first vector to calculate the angles between.
- v2: The other vector to calculate the angles between.
Returns:
- float64: The yaw angle between the two vectors, in radians.
- float64: The pitch angle between the two vectors, in radians.
func Atan2 ¶
Atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
Special cases are (in order):
Atan2(y, NaN) = NaN Atan2(NaN, x) = NaN Atan2(+0, x>=0) = +0 Atan2(-0, x>=0) = -0 Atan2(+0, x<=-0) = +PI Atan2(-0, x<=-0) = -PI Atan2(y>0, 0) = +PI/2 Atan2(y<0, 0) = -PI/2 Atan2(+Inf, +Inf) = +PI/4 Atan2(-Inf, +Inf) = -PI/4 Atan2(+Inf, -Inf) = 3PI/4 Atan2(-Inf, -Inf) = -3PI/4 Atan2(y, +Inf) = 0 Atan2(y>0, -Inf) = +PI Atan2(y<0, -Inf) = -PI Atan2(+Inf, x) = +PI/2 Atan2(-Inf, x) = -PI/2
Parameters:
- y: The y component.
- x: The x component.
Returns:
- float64: The arc tangent of y/x.
func BinarySearch ¶
BinarySearch searches for a target in a sorted slice and returns the lastest position where it is found, or the position where it would appear in the sort order.
The slice must be sorted in increasing order for BinarySearch to work. Also, if the slice is too big, then only the first slices.MAX_SLICE_SIZE elements are considered.
Parameters:
- s: The slice to search in.
- target: The target to search for.
Returns:
- uint32: The position where the target is found, or the position where it would appear in the sort order. It is never greater than slices.MAX_SLICE_SIZE.
- bool: `true` if the target is found in the slice, `false` otherwise.
func BisectAngle ¶
BisectAngle returns the angle between two angles, in radians.
Parameters:
- a: The first angle, in radians.
- b: The second angle, in radians.
Returns:
- float64: The angle between the two angles, in radians.
func CrossPoints ¶
CrossPoints is an optimization function that returns the cross product between two points.
Parameters:
- ax: The X coordinate of the first point.
- ay: The Y coordinate of the first point.
- az: The Z coordinate of the first point.
- bx: The X coordinate of the second point.
- by: The Y coordinate of the second point.
- bz: The Z coordinate of the second point.
Returns:
- float64: The resulting X coordinate.
- float64: The resulting Y coordinate.
- float64: The resulting Z coordinate.
func Degrees ¶
Degrees converts radians to degrees.
Parameters:
- radians: The radians to convert.
Returns:
- float64: The converted degrees.
func DotPoints ¶
DotPoints is an optimization function that returns the dot product between two points.
Parameters:
- ax: The X coordinate of the first point.
- ay: The Y coordinate of the first point.
- az: The Z coordinate of the first point.
- bx: The X coordinate of the second point.
- by: The Y coordinate of the second point.
- bz: The Z coordinate of the second point.
Returns:
- float64: The dot product of the two points.
func Hypot ¶ added in v0.1.9
Hypot returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.
Special cases are:
Hypot(±Inf, q) = +Inf Hypot(p, ±Inf) = +Inf Hypot(NaN, q) = NaN Hypot(p, NaN) = NaN
Parameters:
- p: The first value.
- q: The second value.
Returns:
- float64: The hypotenuse.
func Max ¶
Max returns the larger of x or y.
Special cases are:
Max(x, +Inf) = Max(+Inf, x) = +Inf Max(x, NaN) = Max(NaN, x) = NaN Max(+0, ±0) = Max(±0, +0) = +0 Max(-0, -0) = -0
Parameters:
- a: The first value.
- b: The second value.
Returns:
- float64: The maximum of the two values.
func Min ¶
Min returns the smaller of x or y.
Special cases are:
Min(x, -Inf) = Min(-Inf, x) = -Inf Min(x, NaN) = Min(NaN, x) = NaN Min(-0, ±0) = Min(±0, -0) = -0
Parameters:
- a: The first value.
- b: The second value.
Returns:
- float64: The minimum of the two values.
func NearlyBetween ¶
NearlyBetween reports whether the given value is within the given range.
The range is inclusive and, if min > max, min and max are swapped.
Parameters:
- min: The minimum value.
- value: The value to check.
- max: The maximum value.
Returns:
- bool: `true` if the value is within the range, `false` otherwise.
func NearlyCompare ¶
NearlyCompare compares the two given values.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- types.Result: The result of the comparison.
func NearlyEqual ¶
NearlyEqual reports whether the given values are nearly equal.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- bool: `true` if the values are nearly equal, `false` otherwise.
func NearlyGreater ¶
NearlyGreater reports whether the first value is nearly greater than the second value.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- bool: `true` if the first value is greater than the second value, `false` otherwise.
func NearlyLess ¶
NearlyLess reports whether the first value is nearly less than the second value, with respect to the given epsilon value.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- bool: `true` if the first value is less than the second value, `false` otherwise.
func NearlyMax ¶
NearlyMax returns the maximum of the two given values.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- float64: The maximum value.
func NearlyMin ¶
NearlyMin returns the minimum of the two given values.
Parameters:
- a: The first value.
- b: The second value.
Returns:
- float64: The minimum value.
func NearlyNormal ¶
NearlyNormal reports whether the given value is nearly normalized.
A normalized value is between 0 and 1, inclusive.
Parameters:
- value: The value to check.
Returns:
- bool: `true` if the value is normalized, `false` otherwise.
func NearlyZero ¶
NearlyZero is a convenience function to check if a float64 is close to zero.
Parameters:
- a: The value to check.
Returns:
- bool: `true` if the value is close to zero, `false` otherwise.
func NormalizeAngle ¶
NormalizeAngle normalizes an angle to the range 0 to 2π, in radians.
Parameters:
- angle: The angle to normalize, in radians.
Returns:
- float64: The normalized angle.
func NotZero ¶ added in v0.1.9
NotZero returns the given value if it is not zero. If it is, it returns the epsilon value.
Parameters:
- value: The value to check.
Returns:
- float64: The value if it is not zero, the epsilon value otherwise.
func PolygonArea2D ¶
func Radians ¶
Radians converts degrees to radians.
Parameters:
- degrees: The degrees to convert.
Returns:
- float64: The converted radians.
func SubtractPoints ¶
SubtractPoints is an optimization function that returns the difference between two points.
Parameters:
- ax: The X coordinate of the first point.
- ay: The Y coordinate of the first point.
- az: The Z coordinate of the first point.
- bx: The X coordinate of the second point.
- by: The Y coordinate of the second point.
- bz: The Z coordinate of the second point.
Returns:
- float64: The resulting X coordinate.
- float64: The resulting Y coordinate.
- float64: The resulting Z coordinate.
Types ¶
type Plane ¶
type Plane struct {
// contains filtered or unexported fields
}
Plane represents a plane in 3D space.
func NewPlane ¶
NewPlane creates a new plane with the given normal and distance.
Parameters:
- x: The X component of the normal vector.
- y: The Y component of the normal vector.
- z: The Z component of the normal vector.
- d: The distance from the origin to the plane.
Returns:
- Plane: The newly created plane.
func (*Plane) IntersectLine ¶
IntersectLine returns the intersection point of the plane and the line defined by the two given points.
Parameters:
- a: The first point of the line.
- b: The second point of the line.
Returns:
- *Vec3: The intersection point. It is never `nil`.
type Quaternion ¶
type Quaternion struct {
// C is the scalar component.
C float64
// X is the i component.
X float64
// Y is the j component.
Y float64
// Z is the k component.
Z float64
}
Quaternion represents a quaternion in the form W + X*i + Y*j + Z*k.
It uses the RSG cordinate system.
func AxisAngle ¶
func AxisAngle(axis *Vec3, angle float64) Quaternion
AxisAngle returns the quaternion corresponding to the axis-angle rotation.
Parameters:
- axis: The axis of rotation.
- angle: The angle of rotation.
Returns:
- Quaternion: The quaternion corresponding to the axis-angle rotation.
func FromAxisAngle ¶
func FromAxisAngle(axis *Vec3, angle float64) Quaternion
FromAxisAngle returns a Quaternion corresponding to the axis-angle rotation.
Parameters:
- axis: The axis of rotation.
- angle: The angle of rotation.
Returns:
- Quaternion: The newly created quaternion.
func FromEuler ¶
func FromEuler(phi, theta, psi float64) Quaternion
FromEuler returns a Quaternion corresponding to Euler angles phi, theta, psi.
Parameters:
- phi: The phi angle.
- theta: The theta angle.
- psi: The psi angle.
Returns:
- Quaternion: The newly created quaternion.
func FromToRotation ¶
func FromToRotation(from, to *Vec3) Quaternion
FromToRotation returns the quaternion corresponding to the rotation from one vector to another.
Parameters:
- from: The vector to rotate from.
- to: The vector to rotate to.
Returns:
- Quaternion: The quaternion corresponding to the rotation from one vector to another.
func LookRotation ¶
func LookRotation(forward, up *Vec3) Quaternion
LookRotation returns the quaternion corresponding to the rotation from one vector to another.
Parameters:
- forward: The forward vector.
- up: The up vector.
Returns:
- Quaternion: The quaternion corresponding to the rotation from one vector to another.
func NewQuaternion ¶
func NewQuaternion(c float64, x, y, z float64) Quaternion
NewQuaternion creates a new quaternion with the given components.
Parameters:
- c: The scalar component.
- x: The i component.
- y: The j component.
- z: The k component.
Returns:
- Quaternion: The newly created quaternion.
func QProd ¶
func QProd(qs ...*Quaternion) Quaternion
QProd returns the non-commutative product of quaternions.
Quaternions that are `nil` are ignored.
Parameters:
- qs: The quaternions to multiply.
Returns:
- Quaternion: The product of the quaternions.
func QSum ¶
func QSum(qs ...*Quaternion) Quaternion
QSum returns the vectorial summation of quaternions.
Quaternions that are `nil` are ignored.
Parameters:
- qs: The quaternions to sum.
Returns:
- Quaternion: The sum of the quaternions.
func (*Quaternion) Conjugate ¶
func (q *Quaternion) Conjugate() Quaternion
Conjugate returns the conjugate of a Quaternion. If the receiver is `nil`, the zero value is returned.
Returns:
- Quaternion: The conjugate of the receiver.
func (*Quaternion) Equals ¶
func (q *Quaternion) Equals(other *Quaternion) bool
Equals reports whether the two Quaternions are equal. If either one of them is `nil`, the two Quaternions are not equal.
Parameters:
- other: The other Quaternion.
Returns:
- bool: `true` if the Quaternions are equal, `false` otherwise.
func (*Quaternion) Euler ¶
func (q *Quaternion) Euler() (float64, float64, float64)
Euler returns the Eulerian angles phi, theta, psi corresponding to a Quaternion, in radians. If the receiver is `nil`, `(0.0, 0.0, 0.0)` is returned.
Returns:
- float64: The phi angle.
- float64: The theta angle.
- float64: The psi angle.
func (*Quaternion) Inverse ¶
func (q *Quaternion) Inverse() Quaternion
Inverse returns the inverse of a Quaternion. If the receiver is `nil`, the zero value is returned.
Returns:
- Quaternion: The inverse of the receiver.
func (*Quaternion) Negative ¶
func (q *Quaternion) Negative() Quaternion
Negative returns a quaternion with all components negated. If the receiver is `nil`, the zero value is returned.
Returns:
- Quaternion: The negative of the receiver.
func (*Quaternion) Norm ¶
func (q *Quaternion) Norm() float64
Norm returns the L1-Norm of a Quaternion. If the receiver is `nil`, 0.0 is returned.
Returns:
- float64: The L1-Norm of the receiver.
func (*Quaternion) Norm2 ¶
func (q *Quaternion) Norm2() float64
Norm2 returns the L2-Norm of a Quaternion. If the receiver is `nil`, 0.0 is returned.
Returns:
- float64: The L2-Norm of the receiver.
func (*Quaternion) RotMat ¶
func (q *Quaternion) RotMat() [3][3]float64
RotMat returns the rotation matrix corresponding to a Quaternion. If the receiver is `nil`, the identity matrix is returned.
Returns:
- [3][3]float64: The rotation matrix.
func (*Quaternion) Unit ¶
func (q *Quaternion) Unit() Quaternion
Unit returns the Quaternion rescaled to unit-L1-norm. If the receiver is `nil`, the zero value is returned.
Returns:
- Quaternion: The unit quaternion of the receiver.
type Triangle ¶
type Triangle struct {
// A is the first vector of the triangle.
A *Vec3
// B is the second vector of the triangle.
B *Vec3
// C is the third vector of the triangle.
C *Vec3
}
Triangle is a triangle in 3D space.
func NewTriangle ¶
NewTriangle returns a new 3D triangle with the given vectors. No triangle is created if any of the vectors is `nil`.
Parameters:
- a: The first vector of the triangle.
- b: The second vector of the triangle.
- c: The third vector of the triangle.
Returns:
- *Triangle: The newly created triangle.
func (*Triangle) ContainsVector ¶
ContainsVector reports whether the given vector is inside the triangle. If the receiver is `nil`, the triangle contains no vectors.
If the vector is `nil`, it is not inside the triangle.
Parameters:
- v: The vector to check.
Returns:
- bool: `true` if the vector is inside the triangle, `false` otherwise.
type Vec2 ¶
type Vec2 struct {
// X is the x component of the vector.
X float64
// Y is the y component of the vector.
Y float64
}
Vec2 represents a vector in 2D space.
It uses the RSG cordinate system.
func NewVec2 ¶
NewVec2 creates a new vector with the given components.
Parameters:
- x: The x component of the vector.
- y: The y component of the vector.
Returns:
- Vec2: The newly created vector.
func (*Vec2) Add ¶
Add returns the sum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to perform the addition with.
Returns:
- Vec2: The sum of the two vectors.
func (*Vec2) Copy ¶
Copy returns a copy of the vector. If the receiver is `nil`, the zero vector is returned.
Returns:
- Vec2: The copy of the vector.
func (*Vec2) Cross ¶
Cross performs the left-handed cross product between the two vectors. If either one of them is `nil`, the result is 0.0.
Parameters:
- v2: The other vector to perform the cross product with.
Returns:
- float64: The cross product of the two vectors.
func (*Vec2) Distance ¶
Distance returns the distance between the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- float64: The distance between the two vectors.
func (*Vec2) Dot ¶
Dot returns the dot product between the two vectors. If either one of them is `nil`, the dot product is 0.0.
Parameters:
- v2: The other vector to perform the dot product with.
Returns:
- float64: The dot product of the two vectors.
func (*Vec2) Equals ¶
Equals reports whether the given vector is equal to the receiver. If either one of them is `nil`, the two vectors are not equal.
Parameters:
- v2: The other vector to compare with.
Returns:
- bool: `true` if the vectors are equal, `false` otherwise.
func (*Vec2) Length ¶
Length returns the length of the vector. If the receiver is `nil`, 0.0 is returned.
Returns:
- float64: The length of the vector.
func (*Vec2) Max ¶
Max returns the maximum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- Vec2: The maximum vector.
func (*Vec2) Min ¶
Min returns the minimum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- Vec2: The minimum vector.
func (*Vec2) MulScalar ¶
MulScalar returns the product of the vector and the scalar. If the receiver is `nil`, the zero vector is returned.
Parameters:
- s: The scalar to perform the multiplication with.
Returns:
- Vec2: The product of the vector and the scalar.
func (*Vec2) Multiply ¶
Multiply returns the product of the two vectors. If either one of them is `nil`, the zero vector is returned.
Parameters:
- v2: The other vector to perform the multiplication with.
Returns:
- Vec2: The product of the two vectors.
func (*Vec2) Sub ¶
Sub returns the difference of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to perform the subtraction with.
Returns:
- Vec2: The difference of the two vectors.
type Vec3 ¶
type Vec3 struct {
// X is the x component of the vector.
X float64
// Y is the y component of the vector.
Y float64
// Z is the z component of the vector.
Z float64
}
Vec3 represents a vector in 3D space.
It uses the RSG cordinate system.
var ( // CanonicalRight is the right canonical vector in 3D space (i.e. the // positive X axis). CanonicalRight Vec3 = NewVec3(1.0, 0.0, 0.0) // CanonicalLeft is the left canonical vector in 3D space (i.e. the // negative X axis). CanonicalLeft Vec3 = NewVec3(-1.0, 0.0, 0.0) // CanonicalDown is the down canonical vector in 3D space (i.e. the // positive Y axis). CanonicalDown Vec3 = NewVec3(0.0, 1.0, 0.0) // CanonicalUp is the up canonical vector in 3D space (i.e. the // negative Y axis). CanonicalUp Vec3 = NewVec3(0.0, -1.0, 0.0) // CanonicalToward is the toward canonical vector in 3D space (i.e. // the positive Z axis). CanonicalToward Vec3 = NewVec3(0.0, 0.0, 1.0) // CanonicalAway is the away canonical vector in 3D space (i.e. the // negative Z axis). CanonicalAway Vec3 = NewVec3(0.0, 0.0, -1.0) )
func DirectionFromAngles ¶
DirectionFromAngles returns the derection vector corresponding to the provided yaw and pitch angles, in radians.
Parameters:
- yaw: The yaw angle, in radians.
- pitch: The pitch angle, in radians.
Returns:
- Vec3: The direction vector corresponding to the provided angles.
func LineIntersection3D ¶
LineIntersection3D returns the intersection point of two lines in 3D.
If any of the points is `nil`, it is treated as the zero vector.
Parameters:
- a: The first point of the first line.
- b: The second point of the first line.
- c: The first point of the second line.
- d: The second point of the second line.
Returns:
- Vec3: The intersection point. It is never `nil`.
- bool: `true` if the lines intersect, `false` otherwise.
func NewVec3 ¶
NewVec3 creates a new vector with the given components.
Parameters:
- x: The x component of the vector.
- y: The y component of the vector.
- z: The z component of the vector.
Returns:
- Vec3: The newly created vector.
func OffsetPolygon ¶
Returns outward offset polygon. distance > 0 expands distance < 0 contracts
func PointTowards ¶
PointTowards returns a vector that is `distance` units towards the other vector.
If either vector is `nil`, it is treated as the zero vector.
Parameters:
- v1: The first vector.
- v2: The second vector.
- distance: The distance to move the vector.
Returns:
- Vec3: The new vector.
func PolygonNormal ¶
Estimate polygon plane normal from vertices.
func RotateVec3 ¶
func RotateVec3(q *Quaternion, vec *Vec3) Vec3
RotateVec3 returns the vector rotated by the quaternion.
If the vector is `nil`, it is treated as the zero vector. If the quaternion is `nil`, no rotation is performed.
Parameters:
- q: The quaternion to rotate.
- vec: The vector to rotate.
Returns:
- Vec3: The rotated vector.
func (*Vec3) Add ¶
Add returns the sum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to perform the addition with.
Returns:
- Vec3: The sum of the two vectors.
func (*Vec3) Copy ¶
Copy returns a copy of the vector. If the receiver is `nil`, the zero vector is returned.
Returns:
- Vec3: The copy of the vector.
func (*Vec3) Cross ¶
Cross performs the left-handed cross product between the two vectors. If either one of them is `nil`, the zero vector is returned.
Parameters:
- v2: The other vector to perform the cross product with.
Returns:
- Vec3: The cross product of the two vectors.
func (*Vec3) Distance ¶
Distance returns the distance between the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- float64: The distance between the two vectors.
func (*Vec3) Dot ¶
Dot returns the dot product between the two vectors. If either one of them is `nil`, the dot product is 0.0.
Parameters:
- v2: The other vector to perform the dot product with.
Returns:
- float64: The dot product of the two vectors.
func (*Vec3) Equals ¶
Equals reports whether the given vector is equal to the receiver. If either one of them is `nil`, the two vectors are not equal.
Parameters:
- v2: The other vector to compare with.
Returns:
- bool: `true` if the vectors are equal, `false` otherwise.
func (*Vec3) Length ¶
Length returns the length of the vector. If the receiver is `nil`, 0.0 is returned.
Returns:
- float64: The length of the vector.
func (*Vec3) Max ¶
Max returns the maximum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- Vec3: The maximum vector.
func (*Vec3) Min ¶
Min returns the minimum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- Vec3: The minimum vector.
func (*Vec3) MulScalar ¶
MulScalar returns the product of the vector and the scalar. If the receiver is `nil`, the zero vector is returned.
Parameters:
- s: The scalar to perform the multiplication with.
Returns:
- Vec3: The product of the vector and the scalar.
func (*Vec3) Multiply ¶
Multiply returns the product of the two vectors. If either one of them is `nil`, the zero vector is returned.
Parameters:
- v2: The other vector to perform the multiplication with.
Returns:
- Vec3: The product of the two vectors.
func (*Vec3) Sub ¶
Sub returns the difference of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to perform the subtraction with.
Returns:
- Vec3: The difference of the two vectors.
func (*Vec3) Unit ¶
Unit returns the unit vector of the vector. If the receiver is `nil`, the zero vector is returned.
Returns:
- Vec3: The unit vector of the vector.
func (*Vec3) ZDiff ¶
ZDiff returns the difference between the Z components of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- float64: The difference between the Z components of the two vectors.
type Vec4 ¶
type Vec4 struct {
// X is the x component of the vector.
X float64
// Y is the y component of the vector.
Y float64
// Z is the z component of the vector.
Z float64
// W is the w component of the vector.
W float64
}
Vec4 represents a vector in 4D space.
It uses the RSG cordinate system.
func NewVec4 ¶
NewVec4 creates a new vector with the given components.
Parameters:
- x: The x component of the vector.
- y: The y component of the vector.
- z: The z component of the vector.
- w: The w component of the vector.
Returns:
- Vec4: The newly created vector.
func (*Vec4) Add ¶
Add returns the sum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to perform the addition with.
Returns:
- Vec4: The sum of the two vectors.
func (*Vec4) Copy ¶
Copy returns a copy of the vector. If the receiver is `nil`, the zero vector is returned.
Returns:
- Vec4: The copy of the vector.
func (*Vec4) Distance ¶
Distance returns the distance between the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- float64: The distance between the two vectors.
func (*Vec4) Dot ¶
Dot returns the dot product between the two vectors. If either one of them is `nil`, the dot product is 0.0.
Parameters:
- v2: The other vector to perform the dot product with.
Returns:
- float64: The dot product of the two vectors.
func (*Vec4) Equals ¶
Equals reports whether the given vector is equal to the receiver. If either one of them is `nil`, the two vectors are not equal.
Parameters:
- v2: The other vector to compare with.
Returns:
- bool: `true` if the vectors are equal, `false` otherwise.
func (*Vec4) Length ¶
Length returns the length of the vector. If the receiver is `nil`, 0.0 is returned.
Returns:
- float64: The length of the vector.
func (*Vec4) Max ¶
Max returns the maximum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- Vec4: The maximum vector.
func (*Vec4) Min ¶
Min returns the minimum of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- Vec4: The minimum vector.
func (*Vec4) MulScalar ¶
MulScalar returns the product of the vector and the scalar. If the receiver is `nil`, the zero vector is returned.
Parameters:
- s: The scalar to perform the multiplication with.
Returns:
- Vec4: The product of the vector and the scalar.
func (*Vec4) Multiply ¶
Multiply returns the product of the two vectors. If either one of them is `nil`, the zero vector is returned.
Parameters:
- v2: The other vector to perform the multiplication with.
Returns:
- Vec4: The product of the two vectors.
func (*Vec4) Sub ¶
Sub returns the difference of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to perform the subtraction with.
Returns:
- Vec4: The difference of the two vectors.
func (*Vec4) Unit ¶
Unit returns the unit vector of the vector. If the receiver is `nil`, the zero vector is returned.
Returns:
- Vec4: The unit vector of the vector.
func (*Vec4) ZDiff ¶
ZDiff returns the difference between the Z components of the two vectors. If the receiver is `nil`, it is treated as the zero vector.
If the other vector is `nil`, it is treated as the zero vector.
Parameters:
- v2: The other vector to compare with.
Returns:
- float64: The difference between the Z components of the two vectors.