How To Get the Arc Length from Given Angle in Java?


Arc length refers to the length between two points along the arc (two points along a section of a circle or curve). Simply it is a part of the circumference of the circle.

When two lines intersect each other, the common meeting point is called a vertex and the geometrical figure between the two arms/lines is called an angle.

As per the problem statement, there is a circle and you have the angle from which you need to find out arc length.

Formula to find the arc length by using diameter −

Arc Length = (Θ / 360) * (d * π)

Where, ‘d’ refers to the diameter of the circle and Θ refers to the degree measure of arc.

Formula to find the arc length by using radius −

Arc Length = (Θ / 360) * (2 * π * r)

Where, ‘r’ refers to the radius of the circle and Θ refers to the degree measure of arc.

In this article we will see how we can find the arc length from a given angle by using Java programming language.

To show you some instances

Instance-1

Suppose diameter(d) of the circle is 8 and given angle is 60 degrees

Then by using the arc length formula. We have

Arc Length = 4.18

Instance-2

Suppose diameter(d) of the circle is 7 and given angle is 50 degrees

Then by using the arc length formula. We have

Arc Length = 3.05

Instance-3

Suppose diameter(d) of the circle is 6.5 and given angle is 45 degrees

Then by using the arc length formula. We have

Arc Length = 2.55

Syntax

In Java we have a predefined constant in Math class of java.lang package i.e. Math.PI which gives us the pie value which is approximately equal to 3.14159265359. Following is the syntax for that

Math.PI

Algorithm

Step-1 − Get the radius or diameter of the hemisphere either by initialization or by user input.

Step-2 − Find the arc length by using the formula.

Step-3 − Print the result.

Multiple Approaches

We have provided the solution in different approaches.

  • When radius and angle is given

  • When diameter and angle is given

Let’s see the program along with its output one by one.

Approach-1: When Radius and Angle is Given

In this approach, the radius value of the circle and the arc angle will be initialized in the program. Then by using the algorithm, find the arc length.

Example

import java.io.*; public class Main { public static void main(String args[]) { //initialized the radius value double r = 4; System.out.println("Given radius of circle: "+r); //initialized the angle value double angle = 40; System.out.println("Given angle : "+angle); double arcLength; //if angle is more than 360 then it is Invalid //As no angle is possible with that if (angle > 360) { System.out.println("Invalid angle"); } //else find the arc length else { arcLength = (angle / 360) * (2 * Math.PI * r); //print result System.out.println("Arc length : "+arcLength); } } }

Output

Given radius of circle: 4.0
Given angle : 40.0
Arc length : 2.792526803190927

Approach-2: When Diameter and Angle is Given

In this approach, the radius value of the circle and the arc angle will be initialized in the program. Then by using the algorithm, find the arc length.

Example

import java.io.*; public class Main { public static void main(String args[]) { //initialized the radius value double d = 6; System.out.println("Given diameter of circle: "+d); //initialized the angle value double angle = 40; System.out.println("Given angle : "+angle); double arcLength; //if angle is more than 360 then it is Invalid //As no angle is possible with that if (angle > 360) { System.out.println("Invalid angle"); } //else find the arc length else { arcLength = (angle / 360) * (d * Math.PI); //print result System.out.println("Arc length : "+arcLength); } } }

Output

Given diameter of circle: 6.0
Given angle : 40.0
Arc length : 2.0943951023931953

In this article, we explored how to find the arc length from a given angle in Java by using different approaches.

Updated on: 17-Nov-2022

280 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements