The angle between two straight lines

C ++ write a program, an angle calculation four points constituting two straight
setprecision (n) Description: stream may control the output display the number of floating-point numbers. C ++ default value of the output stream is 6 significant bits.
Given the coordinates of four points ABCD, represent straight lines AB and CD on the plane. Integer coordinates are the absolute value of not more than 100. The two straight lines is calculated as the number of degrees is an acute angle. (Two decimal places)
Note: When two straight lines parallel or coincident, the answer is 0.
Test Example:
Test Input: 00100001
Expected Output: 90.00
Test Input: 163,421,879,823,129
expected output: 75.36

#include<iostream>
#include<cmath>
#include<iomanip>
#define pi 3.1415926;
using namespace std;
int main()
{    
    double x1,y1,x2,y2,x3,y3,x4,y4;
    long double x,y;
    cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    x=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    y=(x3-x4)*(x3-x4)+(y3-y4)*(y3-y4);
    long double s1,s2;
    s1=sqrt(x);
    s2=sqrt(y);
    long double s3;
    s3=(x2-x1)*(x4-x3)+(y2-y1)*(y4-y3);
    long double s4;
    s4=abs(s3);
    long double ans,ans2;
    ans2=s4/(s1*s2);
    ans=acos(ans2);
    long  double ans3;
    ans3=(180*ans)/pi;
    cout<<fixed<<setprecision(2)<<(long double)ans3;
    return 0;
}
Published 102 original articles · won praise 93 · views 4983

Guess you like

Origin blog.csdn.net/huangziguang/article/details/104574951