How to Calculate the Central Angle of a Sector in JavaScript

09/30/2021

Contents

In this article, you will learn how to calculate the central angle of a sector in JavaScript.

Calculating the central angle of a sector in JavaScript

The central angle of a sector is the angle that subtends the sector at the center of the circle. In JavaScript, we can use the following formula to calculate the central angle of a sector:

Central Angle (in degrees) = (Arc Length / (2 * π * r)) * 360

where Arc Length is the length of the arc of the sector, r is the radius of the circle, and π is the mathematical constant pi, which is approximately equal to 3.14159.

Examples

Calculating the central angle of a sector with an arc length of 5 units and a radius of 5 units

const arcLength = 5; // in units
const radius = 5; // in units
const centralAngle = (arcLength / (2 * Math.PI * radius)) * 360;
console.log(centralAngle); // 28.64788975654116

In this example, the arc length is 5 units, the radius is 5 units, and the output is the central angle of the sector, which is approximately 28.648 degrees.

Calculating the central angle of a sector with an arc length of 7 units and a radius of 3.5 units

const arcLength = 7; // in units
const radius = 3.5; // in units
const centralAngle = (arcLength / (2 * Math.PI * radius)) * 360;
console.log(centralAngle); // 114.59155902616465

In this example, the arc length is 7 units, the radius is 3.5 units, and the output is the central angle of the sector, which is approximately 114.592 degrees.

Calculating the central angle of a semicircle with a radius of 10 units

const arcLength = Math.PI * 10; // in units (since it's a semicircle)
const radius = 10; // in units
const centralAngle = (arcLength / (2 * Math.PI * radius)) * 360;
console.log(centralAngle); // 180

In this example, the arc length is π * 10 units (since it’s a semicircle), the radius is 10 units, and the output is the central angle of the semicircle, which is 180 degrees.

Note: If you have the area of the sector and you want to calculate the central angle, you can use the formula:

Central Angle (in degrees) = (Area / π * r^2) * 360