Home > Java > javaTutorial > body text

How to get arc length based on given angle in Java?

WBOY
Release: 2023-09-01 16:29:06
forward
1372 people have browsed it

How to get arc length based on given angle in Java?

Arc length refers to the length between two points along an arc (two points along a segment of a circle or curve). Simply put, it is a portion of the circumference of a circle.

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

According to the problem statement, there is a circle, and there is an angle from which you need to find the arc length.

The formula for finding arc length using diameter -

Arc Length = (Θ / 360) * (d * π)
Copy after login

Among them, "d" refers to the diameter of the circle, and θ refers to the degree of the arc.

The formula for finding arc length using radius -

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

Among them, "r" refers to the radius of the circle, and θ refers to the degree of the arc.

In this article, we will learn how to find the arc length of a given angle using Java programming language.

Show you some examples

Example 1

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

Then use the arc length formula. We have

Arc Length = 4.18
Copy after login

Example 2

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

Then use the arc length formula. We have

Arc Length = 3.05
Copy after login

Example 3

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

Then use the arc length formula. We have

Arc Length = 2.55
Copy after login

grammar

In Java, we have a predefined constant in the Math class of the java.lang package, namely Math.PI, which gives us a pie chart value that is approximately equal to 3.14159265359. The following is its syntax

Math.PI
Copy after login

algorithm

Step-1 - Get the radius or diameter of the hemisphere through initialization or user input.

Step-2 - Calculate arc length using formula.

Step 3 - Print the results.

Multiple methods

We provide solutions in different ways.

  • When the radius and angle are given

  • When the diameter and angle are given

Let’s look at the program and its output one by one.

Method 1: When the radius and angle are given

In this method, the radius value and arc angle of the circle will be initialized in the program. Then use an algorithm to 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);
      }
   }
}
Copy after login

Output

Given radius of circle: 4.0
Given angle : 40.0
Arc length : 2.792526803190927
Copy after login

Method 2: When diameter and angle are given

In this method, the radius value and arc angle of the circle will be initialized in the program. Then use an algorithm to 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);
      }
   }
}
Copy after login

Output

Given diameter of circle: 6.0
Given angle : 40.0
Arc length : 2.0943951023931953
Copy after login

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

The above is the detailed content of How to get arc length based on given angle in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!