Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:12:16+00:00 2026-06-10T06:12:16+00:00

I want to do a angle class to be initialized in radians or degrees

  • 0

I want to do a angle class to be initialized in radians or degrees but i don’t know if it is a good idea. I’m thinking about something like this:

Class Diagram

class Radian;
class Degree;

/**
  * My angle class.
  **/
class Angle
{
    private:
        float m_radian;

    public:
        explicit Angle(const Radian& rad);

        explicit Angle(const Degree& deg);

        float GetRadian(void) const
        {
            return this->m_radian;
        }

        float GetDegree(void) const
        {
            return ToDegree(this->m_radian);
        }

        bool IsEqual(const Angle& angle, float epsilon = 0.001f) const
        {
            return Abs<float>(this->m_radian - angle.m_radian) < epsilon;
        }

        void Set(const Angle& ang);

    protected:
        Angle(void) : m_radian(0.0f)
        {}

        Angle(float rad) : m_radian(rad)
        {}
};

class Radian : public Angle
{
    public:
        Radian(void)
        {}

        Radian(float r) : Angle(r)
        {}
};

class Degree : public Angle
{
    public:
        Degree(void)
        {}

        Degree(float d) : Angle(ToRadian(d))
        {}
};

/// Trigonometric functions.
float Sin(const Angle& angle);
...

This way i won’t confuse radian and degrees in my code. But, is this a good idea or i should use other design?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:12:17+00:00Added an answer on June 10, 2026 at 6:12 am

    I don’t see the need for inheritance here. As far as using your class is concerned, all that matters is that you get an angle – whether it was in degrees or radians to start with is irrelevant.

    Disclaimer: I’ve done this before. Exactly the same use case. My solution was to make the constructor take two arguments: a number and a unit enum. I’d use my class like so:

    Angle a(1.2345, Angle::Radians);
    std::cout << a.radians() << a.degrees() << sin(a);
    

    If you want convenience methods to create angles from common units, they could be just that: helper methods. No need for separate classes.

    Angle r = Radians(2.3);
    Angle d = Degrees(180);
    

    Anyway – just what I’ve been happy using in the past. Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Angle class that I want initialized to a random value. The Angle
I have an Angle class that I want to behave like a float, with
My question is about angle functions in programming languge Java. if i want to
want to know why String behaves like value type while using ==. String s1
here's a very simple js but i don't know where to begin. in a
I want to calculate the angle between two vectors a and b. Lets assume
I want to put a title field in a bibtex citation that includes angle
Want the function to sort the table by HP but if duplicate HPs then
NOTE: This question is written in a C# like pseudo code, but I am
The idea of local variables is a little hard to understand when I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.