Default

Calculate Third side of Triangle puzzle?

Calculate Third side of Triangle puzzle?

Given two sides with length 7 cm and 9 cm and angle between them is 25 degrees. Calculate the third side length of the triangle.

Solution:

Triangle with known sides a and b

Mathematical proof:

Based on the data given , you can calculate the height of the triangle as shown in the above figure.

\LARGE h = asin\Theta

 

b side can be split into acosθ and b- acosθ

\LARGE b = acos\Theta + (b - acos\Theta )

 

Applying law of right angled triangle

\LARGE c^{2} = a^2sin^{2}\Theta + (b-acos\Theta )^2

 

 

Expanding the terms we get:

\LARGE c^{2} = a^2sin^{2}\Theta + b^2 + a^2cos^2\Theta - 2abcos\Theta

 

\LARGE a^{2} = a^2sin^{2}\Theta + a^2cos^2\Theta

 

Replace the terms, we get:

\LARGE c^{2} = a^2 + b^2 -2abcos\Theta

 

Java Program

package com.testingdocs.examples;

public class TriangleThirdSide {
 double a;
 double b;
 double angle;

public TriangleThirdSide(double a, double b, double angle) {
 this.a=a;
 this.b=b;
 this.angle=angle * Math.PI /180;
 }

public double findC() {
 return Math.sqrt( a*a + b*b - (2*a*b* Math.cos(angle)));

}

public static void main(String[] args) {
 TriangleThirdSide triangle= new TriangleThirdSide(7.0,9.0,25.0);
 double c = triangle.findC();
 System.out.println("Third side of the Triangle = "+ String.format( "%.2f", c ) + " cm");
 }

}

 

Answer:

Third side of the Triangle = 3.98 cm

 

public TriangleThirdSide(double a, double b, double angle) {
 this.a=a;
 this.b=b;
 this.angle=angle * Math.PI /180; 
}

 

The class constructor takes the values of known sides a , b and the angle between the sides i.e θ . We can create a new Triangle using the new operator as shown below:

Example : new TriangleThirdSide(7.0,9.0,25.0);

Method findC() calculates the third side using the mathematical proof and the formula shown above.