Angle

package
v0.0.0-...-d966c78 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cos

func Cos(x Radians) Float.X

Cos returns the cosine of angle x in radians.

func Cosh

func Cosh[X Float.Any](x X) X

Cosh returns the hyperbolic cosine of x.

func Sin

func Sin(x Radians) Float.X

Sin returns the sine of angle x in radians.

func Sinh

func Sinh[X Float.Any](x X) X

Sinh returns the hyperbolic sine of x.

func Tan

func Tan(x Radians) Float.X

Tan returns the tangent of angle x in radians.

func Tanh

func Tanh(x Radians) Float.X

Tanh returns the hyperbolic tangent of x.

Types

type Degrees

type Degrees Float.X

func InDegrees

func InDegrees(rad Radians) Degrees

type Euler3D

type Euler3D = struct {
	X Radians
	Y Radians
	Z Radians
}

type Order

type Order int
const (
	OrderXYZ Order = 0
	OrderXZY Order = 1
	OrderYXZ Order = 2
	OrderYZX Order = 3
	OrderZXY Order = 4
	OrderZYX Order = 5
)

type Radians

type Radians Float.X
const Pi Radians = math.Pi
const Tau Radians = 2 * Pi

func Acos

func Acos[X Float.Any](x X) Radians

Acos returns the arc cosine of x in radians. Use to get the angle of cosine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent acos from returning NaN.

func Acosh

func Acosh[X Float.Any](x X) Radians

Acosh returns the hyperbolic arc cosine of x.

func Asin

func Asin[X Float.Any](x X) Radians

Asin returns the arc sine of x in radians. Use to get the angle of sine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent asin from returning NaN.

func Asinh

func Asinh[X Float.Any](x X) Radians

Asinh returns the hyperbolic arc sine of x.

func Atan

func Atan[X Float.Any](x X) Radians

Atan returns the arc tangent of x in radians. Use it to get the angle from an angle's tangent in trigonometry. The method cannot know in which quadrant the angle should fall. See atan2 if you have both y and x.

func Atan2

func Atan2[X Float.Any](y, x X) Radians

Atan2 returns the arc tangent of y/x in radians. Use to get the angle of tangent y/x. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.

Important note: The Y coordinate comes first, by convention.

func Atanh

func Atanh[X Float.Any](x X) Radians

Atanh returns the hyperbolic arc tangent of x.

func CubicInterpolate

func CubicInterpolate(from, to, pre, post, weight Radians) Radians

CubicInterpolateAngle cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also Lerp.

func CubicInterpolateAngleInTime

func CubicInterpolateAngleInTime(from, to, pre, post, weight, to_t, pre_t, post_t Radians) Radians

CubicInterpolateAngleInTime cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also Lerp.

It can perform smoother interpolation than CubicInterpolate by the time values.

func Difference

func Difference(from, to Radians) Radians

Difference returns the difference between the two angles, in the range of [-Pi, +Pi]. When from and to are opposite, returns -Pi if from is smaller than to, or Pi otherwise.

func InRadians

func InRadians(deg Degrees) Radians

func Lerp

func Lerp[X Float.Any](from, to Radians, weight X) Radians

Lerp linearly interpolates between two angles (in radians) by a weight value between 0.0 and 1.0. Similar to lerp, but interpolates correctly when the angles wrap around Tau. To perform eased interpolation with Lerp, combine it with [Float.Ease] or [Float.Smoothstep].

Note: This function lerps through the shortest path between from and to. However, when these two angles are approximately Pi + k * Tau apart for any integer k, it's not obvious which way they lerp due to floating-point precision errors. For example, Lerp(0, Pi, weight) lerps counter-clockwise, while Lerp(0, Pi + 5 * Tau, weight) lerps clockwise.

func RotateToward

func RotateToward[X Float.Any](from, to Radians, delta X) Radians

RotateToward rotates from toward to by the delta amount. Will not go past to.

Similar to move_toward, but interpolates correctly when the angles wrap around Tau.

If delta is negative, this function will rotate away from to, toward the opposite angle, and will not go past the opposite angle.

func (Radians) AsVector2

func (angle Radians) AsVector2() vector2

AsVector2 creates a unit Vector2 rotated to the given angle in radians. This is equivalent to doing:

Vector2.New(math.Cos(angle), math.Sin(angle))
Vector2.Rotated(Vector2.Right, angle).

Jump to

Keyboard shortcuts

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