Skip to content

Math & MathF: Conversion constants between degrees and radians #38566

@Ramobo

Description

@Ramobo

Background and Motivation

My use-case is working with quaternions, since the inputs for Quaternion.CreateFromYawPitchRoll(...) are in radians.

Proposed API

namespace System
{
    public static class Math
    {
+        public const double RadiansToDegrees = 57.295779513;
+        public const double DegreesToRadians = 0.0174532925;
    }

    public static class MathF
    {
+        public const double RadiansToDegrees = 57.295779513f;
+        public const double DegreesToRadians = 0.0174532925f;
    }
}

Don't quote me on the values, and add more precision to the double variant. float should have 9 decimal places, and double should have 29.

Usage Examples

Vector3 input = new Vector3(10f, 20f, 30f) * MathF.DegreesToRadians;

Quaternion quaternion = Quaternion.CreateFromYawPitchRoll(input.Y, input.X, input.Z);

Alternative Designs

  • Use methods instead. Not ideal, since then you need more code to convert types with multiple numerical components:
    • Constant: vector * MathF.DegreesToRadians;
    • Method: public Vector3 DegreesToRadians(this Vector3 vector) => new Vector2(MathF.DegreesToRadians(vector.X), MathF.DegreesToRadians(vector.Y));

Risks

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions