{"id":22859,"date":"2021-09-29T20:14:18","date_gmt":"2021-09-29T14:44:18","guid":{"rendered":"https:\/\/python-programs.com\/?p=22859"},"modified":"2021-11-22T18:35:35","modified_gmt":"2021-11-22T13:05:35","slug":"python-program-to-find-area-of-a-circular-segment","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-area-of-a-circular-segment\/","title":{"rendered":"Python Program to Find Area of a Circular Segment"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find the Center of the Circle using Endpoints of Diameter<\/a> Given the radius of the circle and the angle that forms a minor segment, the task is to find the areas of both major and minor segments of a circle.<\/p>\n Formula:<\/strong><\/p>\n pi * r2 * (angle\/360) – 1\/2 * r2 * Sin(angle)<\/p><\/blockquote>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to find the areas of both major and minor segments of a circle in Python:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n If you wanna write simple python programs as a part of your coding practice refer to numerous Simple Python Program Examples<\/a> existing and learn the approach used.<\/p>\n In the previous article, we have discussed Python Program to Find the Center of the Circle using Endpoints of Diameter When a chord is drawn in a circle, it divides the circle into two parts. These two parts of the circle are known as circle segments. The smaller area is referred to as the Minor …<\/p>\n
\nWhen a chord is drawn in a circle, it divides the circle into two parts. These two parts of the circle are known as circle segments. The smaller area is referred to as the Minor segment, while the larger area is referred to as the Major segment.<\/p>\nGiven radius = 20\r\nGiven angle = 60 (degrees)<\/pre>\n
The minor segment area = 36.23434102950645\r\nThe major segment area = 1220.402189686826<\/pre>\n
Given radius = 10.5\r\nGiven angle = 45<\/pre>\n
The minor segment area = 4.315801733342639\r\nThe major segment area = 342.0447026361856<\/pre>\n
Program to Find Area of a Circular Segment in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n\r\n# Create a function to say BothSegments_area() which takes the given radius and angle\r\n# as the arguments, and returns the major and minor segments area.\r\n\r\n\r\ndef BothSegments_area(gven_radius, gven_angl):\r\n # Inside the function, calculate the value area of the sector using the above\r\n # given mathematical formula and store it in a variable.\r\n rsltareaof_sectr = pi * (gven_radius * gven_radius) * (gven_angl \/ 360)\r\n\r\n # Calculate the\u00a0area of the triangle using the above given mathematical formula and\r\n # math.sin() function.\r\n # store it in another variable.\r\n rsltareaof_triangl = 1 \/ 2 * \\\r\n (gven_radius * gven_radius) * math.sin((gven_angl * pi) \/ 180)\r\n\r\n # Subtract the area of a triangle from the area of a sector and return it.\r\n return rsltareaof_sectr - rsltareaof_triangl\r\n\r\n\r\n# Give the radius as static input and store it in a variable.\r\ngven_radius = 20\r\n# Give the angle as static input and store it in another variable.\r\ngven_angl = 60\r\n# Take a variable and initialize the pi value as 3.14159.\r\npi = 3.14159\r\n# Pass the given radius and angle as the arguments to the BothSegments_area()\r\n# function and print the area of the minor segment.\r\nprint(\"The minor segment area =\",\r\n BothSegments_area(gven_radius, gven_angl))\r\n# Pass the given radius and 360-angle as the arguments to the BothSegments_area()\r\n# function and print the area of the major segment.\r\nprint(\"The major segment area =\",\r\n BothSegments_area(gven_radius, (360 - gven_angl)))\r\n<\/pre>\n
The minor segment area = 36.23434102950645\r\nThe major segment area = 1220.402189686826<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n\r\n# Create a function to say BothSegments_area() which takes the given radius and angle\r\n# as the arguments, and returns the major and minor segments area.\r\n\r\n\r\ndef BothSegments_area(gven_radius, gven_angl):\r\n # Inside the function, calculate the value area of the sector using the above\r\n # given mathematical formula and store it in a variable.\r\n rsltareaof_sectr = pi * (gven_radius * gven_radius) * (gven_angl \/ 360)\r\n\r\n # Calculate the\u00a0area of the triangle using the above given mathematical formula and\r\n # math.sin() function.\r\n # store it in another variable.\r\n rsltareaof_triangl = 1 \/ 2 * \\\r\n (gven_radius * gven_radius) * math.sin((gven_angl * pi) \/ 180)\r\n\r\n # Subtract the area of a triangle from the area of a sector and return it.\r\n return rsltareaof_sectr - rsltareaof_triangl\r\n\r\n\r\n# Give the radius as user input using the float(input()) function and store it in a variable.\r\ngven_radius = float(input(\"Enter some random number = \"))\r\n# Give the angle as as user input using the float(input()) function and\r\n# store it in another variable.\r\ngven_angl = float(input(\"Enter some random number = \"))\r\n# Take a variable and initialize the pi value as 3.14159.\r\npi = 3.14159\r\n# Pass the given radius and angle as the arguments to the BothSegments_area()\r\n# function and print the area of the minor segment.\r\nprint(\"The minor segment area =\",\r\n BothSegments_area(gven_radius, gven_angl))\r\n# Pass the given radius and 360-angle as the arguments to the BothSegments_area()\r\n# function and print the area of the major segment.\r\nprint(\"The major segment area =\",\r\n BothSegments_area(gven_radius, (360 - gven_angl)))\r\n<\/pre>\n
Enter some random number = 10.5\r\nEnter some random number = 45\r\nThe minor segment area = 4.315801733342639\r\nThe major segment area = 342.0447026361856<\/pre>\n
\n