0% found this document useful (0 votes)
14 views15 pages

Mathematical Library Methods

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

Mathematical Library Methods

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Mathematical library

methods
Angle conversions
• Two basic units of measuring angles: Degree and radians
• Angle conversion in Java refers to converting an angle from one unit
to another, typically between degrees and radians. These two units
are commonly used in trigonometric and mathematical calculations.
• In trigonometrical calculations we need to convert angles from degree
to radian and vice versa
• Java provides methods in the Math class for these conversions:
• 1. Degrees to Radians
• To convert degrees to radians, use the formula:

Or
radian= Math.PI/180*degree

• Or you can convert using mathematical function


Math.toRadians(double degrees)

Where Math.toRadians() is a built in mathematical


function in java
It accepts the double argument and will return the
value also in double data type.
Or
degree= (radian*180)/Math.PI;

Or
By using mathematical function
Math.toDegrees(double radians)
Input
Enter angle in degrees: 90
Enter angle in radians: 1.5708

output
Angle in radians: 1.5707963267948966
Angle in degrees: 89.99984796050427
Trigonometrical functions
• Java provides a rich set of trigonometric functions in the Math
class to perform various calculations.
• These methods operate on angles measured in radians (not
degrees).
• You can use the Math.toRadians() and Math.toDegrees() methods
to convert between radians and degrees as needed.
Angles in trigonometric functions are in radians, not
degrees.

Use Math.toRadians(degrees) to convert degrees to


radians.
The trigonometrical functions are
used for the following purposes
• To find the trigonometrical ratio, if angle is known
• To find an angle, if the trigonometrical ration is known

• The library functions for those purpose are:


i) Math.sin()
ii) Math.cos()
iii) Math.tan()
To find the trigonometrical ratio if
the angle is known
• <return data type><variable>=<function name(angle in radian)>

Eg::

double val=Math.sin(angle);
To find an angle if trigonometrical
ratio is known
• The returned angle will be in radian you need to convert it into degree

• Some of the trigonometrical functions are ::


i) Math.asin()
ii) Math.acos()
iii) Math.atan()
• <return data type><variable>=<function name(value in radian)>

• Eg:: double m=Math.asin(radian);


Program to display the value of cosine for the given angle a where a=60
degree.
//program to display value
public class cos
{
public static void main()
{
int a =60;
double radian=(22.0/(7.0*180))*a;
double d=Math.cos(radian);
System.out.println(“value of cos 60 degree is “+d);
}
}
public class CosineExample
{
public static void main()
{
double a = 60;
double radians = Math.toRadians(a);
double cosValue = Math.cos(radians);
System.out.println("The cosine of " + a + " degrees is: " + cosValue);
}
}
Common Trigonometric Functions in Java
1. Sine (sin)
Method: Math.sin(double angleInRadians)
Returns the sine of the given angle in radians.
2. Cosine (cos)
Method: Math.cos(double angleInRadians)
Returns the cosine of the given angle in radians.
3. Tangent (tan)
Method: Math.tan(double angleInRadians)
Returns the tangent of the given angle in radians.
4. Inverse Sine (asin)
Method: Math.asin(double value)
Returns the angle in radians whose sine is the given value. The result is in the range [-π/2, π/2].
5. Inverse Cosine (acos)
Method: Math.acos(double value)
Returns the angle in radians whose cosine is the given value. The result is in the range [0, π].
6. Inverse Tangent (atan)
Method: Math.atan(double value)
Returns the angle in radians whose tangent is the given value. The result is in the range [-π/2, π/2].

You might also like