Show / Hide Table of Contents

Class MathUtilities

Contains some utility functions related to math

Inheritance
object
MathUtilities
Namespace: WeaverCore.Utilities
Assembly: WeaverCore.dll
Syntax
public static class MathUtilities

Methods

| Edit this page View Source

AngleIsWithinRange(float, Vector2)

Checks if an angle is within a certain range

Declaration
public static bool AngleIsWithinRange(float angleDegrees, Vector2 range)
Parameters
Type Name Description
float angleDegrees

The angle in degrees

Vector2 range

The range the angle should be in

Returns
Type Description
bool

Returns true if the angle is within the range

| Edit this page View Source

CalculateMaximumOfCurve(float, float, float, float)

This function will calculate a velocity curve needed to get from startY to endY, and will return the time it takes to reach the peak of the curve and the peak height of the curve itself

Declaration
public static (float timeToPeak, float peakHeight) CalculateMaximumOfCurve(float startY, float endY, float time, float gravityScale = 1)
Parameters
Type Name Description
float startY

The starting height

float endY

The destination height

float time

The amount of time needed to get from startY to endY

float gravityScale

The gravity multiplier

Returns
Type Description
(float timeToPeak, float peakHeight)

the time it takes to reach the peak of the curve and the peak height of the curve itself

| Edit this page View Source

CalculateTimeToReachHeight(Vector2, Vector2, float, double)

Calculates the time needed to reach a certain height. Returns NaN if the height can never be reached

Declaration
public static float CalculateTimeToReachHeight(Vector2 start, Vector2 velocity, float targetHeight, double gravityScale = 1)
Parameters
Type Name Description
Vector2 start

The start position

Vector2 velocity

The starting velocity

float targetHeight

The target height to reach

double gravityScale

The gravity scale of the object

Returns
Type Description
float
| Edit this page View Source

CalculateVelocityToReachPoint(Vector2, Vector2, double, double)

Calculates the 2D velocity needed to reach the specified end point.

Declaration
public static Vector2 CalculateVelocityToReachPoint(Vector2 start, Vector2 end, double time, double gravityScale = 1)
Parameters
Type Name Description
Vector2 start

The starting position

Vector2 end

The end position

double time

The amount of time needed to get from the start to the end

double gravityScale

The gravity multiplier

Returns
Type Description
Vector2

Returns the 2D velocity needed to reach the specified end point.

| Edit this page View Source

CartesianToPolar(float, float)

Converts a set of cartesian coordinates to polar coordinates

Declaration
public static Vector2 CartesianToPolar(float x, float y)
Parameters
Type Name Description
float x

The x coordinates

float y

The y coordinates

Returns
Type Description
Vector2

Returns the polar coordinates (x is the angle in degrees, y is the magnitude)

| Edit this page View Source

CartesianToPolar(Vector2)

Converts a set of cartesian coordinates to polar coordinates

Declaration
public static Vector2 CartesianToPolar(Vector2 vector)
Parameters
Type Name Description
Vector2 vector

The x-y coordinates

Returns
Type Description
Vector2

Returns the polar coordinates (x is the angle in degrees, y is the magnitude)

| Edit this page View Source

ClampRotation(float)

Clamps an angle into the range -180 to 180

Declaration
public static float ClampRotation(float degrees)
Parameters
Type Name Description
float degrees

The angle to clamp

Returns
Type Description
float
| Edit this page View Source

PolarToCartesian(float, float)

Converts a set of polar coordinates to cartesian coordinates

Declaration
public static Vector2 PolarToCartesian(float angleDegrees, float magnitude)
Parameters
Type Name Description
float angleDegrees

The angle of the polar coordinate

float magnitude

The length of the polar coordinate

Returns
Type Description
Vector2

Returns the set of polar coordinates in cartesian coordinates

| Edit this page View Source

PolarToCartesian(Vector2)

Converts a set of polar coordinates to cartesian coordinates

Declaration
public static Vector2 PolarToCartesian(Vector2 angleAndMagnitude)
Parameters
Type Name Description
Vector2 angleAndMagnitude

The polar coordinates (x is the angle, y is the magnitude)

Returns
Type Description
Vector2

Returns the set of polar coordinates in cartesian coordinates

| Edit this page View Source

PredictPosition(Vector2, Vector2, float, float)

Declaration
public static Vector2 PredictPosition(Vector2 startPos, Vector2 velocity, float gravityScale, float time)
Parameters
Type Name Description
Vector2 startPos
Vector2 velocity
float gravityScale
float time
Returns
Type Description
Vector2
| Edit this page View Source

PredictPosition(Vector2, Vector2, Vector2, float)

Declaration
public static Vector2 PredictPosition(Vector2 startPos, Vector2 velocity, Vector2 acceleration, float time)
Parameters
Type Name Description
Vector2 startPos
Vector2 velocity
Vector2 acceleration
float time
Returns
Type Description
Vector2
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Generated by DocFX
☀
☾