Skip to content

Commit

Permalink
Added Vector3 FromAngleDegrees
Browse files Browse the repository at this point in the history
Added documentation
  • Loading branch information
vchelaru committed Dec 1, 2023
1 parent 4620608 commit 9f92efd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,29 @@ public static Vector2 RotatedBy(this Vector2 vector2, float radiansToRotateBy)
}
}

/// <summary>
/// Returns a unit vector pointing in the direction specified by the radians argument.
/// </summary>
/// <param name="angleRadians">The direction in radians, where 0 is to the right, and values
/// increase counterclockwise.</param>
/// <returns></returns>
public static Vector2 FromAngle(float angleRadians)
{
return new Vector2((float)Math.Cos(angleRadians),
(float)Math.Sin(angleRadians));
}

/// <summary>
/// Returns a unit vector pointing in the direction specified by the degrees argument.
/// </summary>
/// <param name="angleDegrees">The direction in degrees, where 0 is to the right, and values
/// increasing counterclockwise.</param>
/// <returns></returns>
public static Vector2 FromAngleDegrees(float angleDegrees)
{
var angleRadians = MathHelper.ToRadians(angleDegrees);
return new Vector2((float)Math.Cos(angleRadians),
return new Vector2(
(float)Math.Cos(angleRadians),
(float)Math.Sin(angleRadians));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static Vector3 RotatedBy(this Vector3 vector3, float radiansToRotateBy)

/// <summary>
/// Returns a unit vector with a Z value of 0 pointing in the direction
/// specified by the radians value.
/// specified by the radians argument.
/// </summary>
/// <param name="radians">The direction in radians, where 0 is to the right, and
/// values increase counterclockwise.</param>
Expand All @@ -174,6 +174,23 @@ public static Vector3 FromAngle(float radians)
);
}

/// <summary>
/// Returns a unit vector with a Z value of 0 pointing in the direction
/// specified by the degrees argument.
/// </summary>
/// <param name="angleDegrees">The direction in angles, where 0 is to the right, and
/// values increase counterclockwise.</param>
/// <returns>A new Vector3 pointing in the desired direction.</returns>
public static Vector3 FromAngleDegrees(float angleDegrees)
{
var radians = MathHelper.ToRadians(angleDegrees);
return new Vector3(
(float)Math.Cos(radians),
(float)Math.Sin(radians),
0
);
}

/// <summary>
/// Returns a vector in the same direction as the argument vector, but of the length specified by the length argument.
/// This can safely be called on vectors with length 0, as the right direction will be used.
Expand Down

0 comments on commit 9f92efd

Please sign in to comment.