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 829421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:52:50+00:00 2026-05-15T03:52:50+00:00

I have two lines: Line1 and Line2. Each line is defined by two points

  • 0

I have two lines: Line1 and Line2. Each line is defined by two points (P1L1(x1, y1), P2L1(x2, y2) and P1L1(x1, y1), P2L3(x2, y3)). I want to know the inner angle defined by these two lines.

For do it I calculate the angle of each line with the abscissa:

double theta1 = atan(m1) * (180.0 / PI);
double theta2 = atan(m2) * (180.0 / PI);

After to know the angle I calculate the following:

double angle = abs(theta2 - theta1);

The problem or doubt that I have is: sometimes I get the correct angle but sometimes I get the complementary angle (for me outer). How can I know when subtract 180º to know the inner angle? There is any algorithm better to do that? Because I tried some methods: dot product,
following formula:

result = (m1 - m2) / (1.0 + (m1 * m2));

But always I have the same problem; I never known when I have the outer angle or the inner angle!

  • 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-05-15T03:52:51+00:00Added an answer on May 15, 2026 at 3:52 am

    I think what you’re looking for is the inner product (you may also want to look over the dot product entry) of the two angles. In your case, that’s given by:

    float dx21 = x2-x1;
    float dx31 = x3-x1;
    float dy21 = y2-y1;
    float dy31 = y3-y1;
    float m12 = sqrt( dx21*dx21 + dy21*dy21 );
    float m13 = sqrt( dx31*dx31 + dy31*dy31 );
    float theta = acos( (dx21*dx31 + dy21*dy31) / (m12 * m13) );

    Answer is in radians.

    EDIT: Here’s a complete implementation. Substitute the problematic values in p1, p2, and p3 and let me know what you get. The point p1 is the vertex where the two lines intersect, in accordance with your definition of the two lines.

    #include <math.h>
    #include <iostream>
    
    template <typename T> class Vector2D
    {
    private:
        T x;
        T y;
    
    public:
        explicit Vector2D(const T& x=0, const T& y=0) : x(x), y(y) {}
        Vector2D(const Vector2D&ltT>& src) : x(src.x), y(src.y) {}
        virtual ~Vector2D() {}
    
        // Accessors
        inline T X() const { return x; }
        inline T Y() const { return y; }
        inline T X(const T& x) { this->x = x; }
        inline T Y(const T& y) { this->y = y; }
    
        // Vector arithmetic
        inline Vector2D<T> operator-() const
            { return Vector2D<T>(-x, -y); }
    
        inline Vector2D<T> operator+() const
            { return Vector2D<T>(+x, +y); }
    
        inline Vector2D<T> operator+(const Vector2D<T>& v) const
            { return Vector2D<T>(x+v.x, y+v.y); }
    
        inline Vector2D<T> operator-(const Vector2D<T>& v) const
            { return Vector2D<T>(x-v.x, y-v.y); }
    
        inline Vector2D<T> operator*(const T& s) const
            { return Vector2D<T>(x*s, y*s); }
    
        // Dot product
        inline T operator*(const Vector2D<T>& v) const
            { return x*v.x + y*v.y; }
    
        // l-2 norm
        inline T norm() const { return sqrt(x*x + y*y); }
    
        // inner angle (radians)
        static T angle(const Vector2D<T>& v1, const Vector2D<T>& v2)
        {
            return acos( (v1 * v2) / (v1.norm() * v2.norm()) );
        }
    };
    
    int main()
    {
        Vector2D<double> p1(215, 294);
        Vector2D<double> p2(174, 228);
        Vector2D<double> p3(303, 294);
    
        double rad = Vector2D<double>::angle(p2-p1, p3-p1);
        double deg = rad * 180.0 / M_PI;
    
        std::cout << "rad = " << rad << "\tdeg = " << deg << std::endl;
    
        p1 = Vector2D<double>(153, 457);
        p2 = Vector2D<double>(19, 457);
        p3 = Vector2D<double>(15, 470);
    
        rad = Vector2D<double>::angle(p2-p1, p3-p1);
        deg = rad * 180.0 / M_PI;
    
        std::cout << "rad = " << rad << "\tdeg = " << deg << std::endl;
    
        return 0;
    }

    The code above yields:

    rad = 2.12667   deg = 121.849
    rad = 0.0939257 deg = 5.38155

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

Sidebar

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.