how 2 find the angle in the c++ coad?

hi, i want 2 calculate the angle pettween 3 potential sides by this formula


fabs( (slope2-slope1)/(1 + slope11*slope2)) ;

so , what i want is the angle .that's why i must use the tan inverse
i found in my book that tan inverse is written as (tanh(x)
but the answer would'nt show what to do .

do u need my program?.
her is my program the question ask to read 3 points from a file

and then determain wither these 3 points form atringle if yes calculat the area and the primeter :



# include <iostream>
# include <fstream>
# include <cmath>
# include <iomanip>
# include <string>
using namespace std;
int main()
{
// decalaring the variables that we will read from file
float X1,X2,X3;
float Y1,Y2,Y3;
string fileName;
fstream inData; //decalaring apointer

// prompt the user to enter file name wich contain the apropreuat format
cout << "please enter the name of the file cotaning the 3 coordinates\n the file should have the following format :(X1,Y1);(X2,Y2);(X3,Y3):";
cin >> fileName;

//opining the file
inData.open(fileName.c_str());
// shecking if the file existes
if (! inData) {
cout << "Error:cannot open file " << fileName << endl;
}


//rading from file the cordinates
inData.ignore(200,'(') >> X1;
inData.ignore(200,',') >> Y1; //reding point1
inData.ignore(200,')');
inData.ignore(200,';');
inData.ignore(200,'(') >> X2;
inData.ignore(200,',') >> Y2; //reading point2
inData.ignore(200,')');
inData.ignore(200,';');
inData.ignore(200,'(') >> X3;
inData.ignore(200,',') >> Y3; //reding point3
inData.ignore(200,')');


double distance1,distance2,distance3; //declaring the distance variable

distance1 = sqrt(pow((X2-X1),2) + pow((Y2-Y1),2));
distance2 = sqrt(pow((X3-X1),2) + pow((Y3-Y1),2)); // calculating the distance between every 2 points
distance3 = sqrt(pow((X3-X2),2) + pow((Y3-Y2),2));

// declaring the slope variables
double slope1,slope2,slope3;

//declaring the the angle between the sides and tangential of the angle
double tanOfAngle1,tanOfAngle2,tanOfAngle3;
double angle1,angle2,angle3;

cout << "p1=(x1,y1)= " << " " << "( " << int(X1) << "," << int(Y1) << ")" << endl;

cout << "p2=(x2,y2)= " << " " << "( " << int(X2) << "," << int(Y2) << ")" << endl;

cout << "p1=(x3,y3)= " << " " << "( " << int(X3) << "," << int(Y3) << ")" << endl;


// showing the distance for each side
cout << "side1 = p1_p2 = " << fixed << showpoint << setprecision(2) << distance1 << endl;
cout << "side2 = p1_p3 = " << fixed << showpoint << setprecision(2) << distance2 << endl;
cout << "side3 = p2_p3 = " << fixed << showpoint << setprecision(2) << distance3 << endl;

if (X1 == X2)
slope1 = 1E37;
else
{
slope1 = (Y2-Y1)/(X2-X1);
}
if (X3==X1)
slope2 = 1E37;
else
{ // calculating the slope 4 each side
slope2 = (Y3-Y1)/(X3-X1);
}
if (X3 == X2)
slope3 = 1E37;
else
{
slope3 = (Y3-Y2)/(X3-X2);
}
cout << "slope are" << slope1 << endl;
cout << "slope 2 :" << slope2 << endl;
cout << "slope3 :" << slope3 << endl;

// calculating the angle between every 2 sides

if ((1 + slope2 * slope1)== 0)
{
angle1 = 90;
}
else
{
tanOfAngle1 = fabs((slope2-slope1)/(1 + int(slope2) * int(slope1)));
angle1 = tanh(tanOfAngle1);

}
if ((1 + slope3 * slope1) == 0)
{
angle2 = 90;
}
else
{
tanOfAngle2 = ((slope3-slope1)/(1 + int(slope3) * int(slope1)));

angle2= tanh(tanOfAngle2);
}
if ((1 + slope3 * slope2) == 0)
{
angle3 = 90;
}
else
{
tanOfAngle3 = ((slope3-slope2)/(1 + int(slope3) * int(slope2)));
angle3 = tanh(tanOfAngle3);

}
// formating the out put

cout << "Absolute value of the angle between side1 and side2 is: " << setprecision(2) << angle1 << endl;
cout << "Absolute value of the angle between side3 and side1 is: " << setprecision(2) << angle2 << endl;
cout << "Absolute value of the angle between side3 and side2 is: " << setprecision(2) << angle3 << endl;

// if all the information shows atringle then we will calculate the the area and the primeter
// if not we will disblay a masseag tell that the following points dose not represent a tringle
double sum_angle ;
sum_angle = angle1 + angle2 + angle3;

if (( sum_angle == 180) && ( (slope1 != slope2) && (slope2 != slope3) && (slope1 != slope3)))
{
cout << "The three points form a triangle that has" << endl;
double A,P; // declaring the area AND the perimeter

A = fabs((X1 * Y1) + (Y1 * X3) - (Y3 * X2) - (Y2 * X3)- (Y1 * X2) - (X1 * Y3));
P = distance1 + distance2 + distance3;


// showing the area and the perimeter in the out put
cout << "an area of : " << A << endl;
cout << "and a perimeter of : " << P << endl;
}
else
{
cout << "The three points do not form a triangle!!" << endl;
}
inData.close();

return 0;
}
Topic archived. No new replies allowed.