Largest Square that can be inscribed within a hexagon Last Updated : 07 Aug, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a regular hexagonof side length a, the task is to find the area of the largest square that can be inscribed within it.Examples: Input: a = 6 Output: 57.8817Input: a = 8 Output: 102.901 Approach: The square we will derive will have the same centre and axes of the hexagon. This is because the square will become smaller if we will rotate it. The sides of the hexagonal are equal i.e. a = b + c. Now, let d be the length of the side of the inscribed square, Then the top side of the square, d = 2 * c * sin(60). And, the left side of the square, d = a + 2 * b * sin(30). Substituting for c, d = 2 * (a - b) * sin(60). Now taking d and re-arranging, we get, b / a = (2 * sin(60) - 1) / (2 * (sin(30) + sin(60))) So, b / a = 2 - ?3 Now, substituting the relation of b and a in the left hand side equation of square, we get, d / a = 3 - ?3 i.e. d / a = 1.268 Therefore, d = 1.268 * a Below is the implementation of the above approach: C++ // C++ program to find the area of the largest square // that can be inscribed within the hexagon #include <bits/stdc++.h> using namespace std; // Function to find the area // of the square float squareArea(float a) { // Side cannot be negative if (a < 0) return -1; // Area of the square float area = pow(1.268, 2) * pow(a, 2); return area; } // Driver code int main() { float a = 6; cout << squareArea(a) << endl; return 0; } Java // Java program to find the area of the largest square // that can be inscribed within the hexagon class Solution { // Function to find the area // of the square static float squareArea(float a) { // Side cannot be negative if (a < 0) return -1; // Area of the square float area = (float)(Math.pow(1.268, 2) * Math.pow(a, 2)); return area; } // Driver code public static void main(String args[]) { float a = 6; System.out.println(squareArea(a)); } } // This code is contributed by Arnab Kundu Python3 # Python program to find the area of the largest square # that can be inscribed within the hexagon # Function to find the area # of the square def squareArea(a): # Side cannot be negative if (a < 0): return -1; # Area of the square area = (1.268 ** 2) * (a ** 2); return area; # Driver code a = 6; print(squareArea(a)); # This code contributed by PrinciRaj1992 C# // C# program to find the area of the largest square // that can be inscribed within the hexagon using System; class Solution { // Function to find the area // of the square static float squareArea(float a) { // Side cannot be negative if (a < 0) return -1; // Area of the square float area = (float)(Math.Pow(1.268, 2) * Math.Pow(a, 2)); return area; } // Driver code public static void Main() { float a = 6; Console.WriteLine(squareArea(a)); } } // This code is contributed by anuj_67.. PHP <?php // PHP program to find the area of the largest square // that can be inscribed within the hexagon // Function to find the area // of the square function squareArea($a) { // Side cannot be negative if ($a < 0) return -1; // Area of the square $area = pow(1.268, 2) * pow($a, 2); return $area; } // Driver code $a = 6; echo squareArea($a), "\n"; // This code is contributed by Tushil ?> JavaScript <script> // javascript program to find the area of the largest square // that can be inscribed within the hexagon // Function to find the area // of the square function squareArea(a) { // Side cannot be negative if (a < 0) return -1; // Area of the square var area = (Math.pow(1.268, 2) * Math.pow(a, 2)); return area; } // Driver code var a = 6; document.write(squareArea(a).toFixed(5)); // This code is contributed by Princi Singh </script> Output: 57.8817 Time Complexity: O(1) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Largest trapezoid that can be inscribed in a semicircle I IshwarGupta Follow Improve Article Tags : Mathematical Geometric DSA Practice Tags : GeometricMathematical Similar Reads Largest triangle that can be inscribed in a semicircle Given a semicircle with radius r, we have to find the largest triangle that can be inscribed in the semicircle, with base lying on the diameter.Examples: Input: r = 5 Output: 25 Input: r = 8 Output: 64 Approach: From the figure, we can clearly understand the biggest triangle that can be inscribed in 3 min read Largest cube that can be inscribed within a right circular cone Given a right circular cone of radius r and perpendicular height h. We have to find the side length of the biggest cube that can be inscribed within it.Examples: Input : h = 5, r = 6 Output : 3.14613 Input : h = 8, r = 12 Output : 5.43698 Approach: Let, side of the cube = a.From the diagram, we can 4 min read Largest square that can be inscribed in a semicircle Given a semicircle with radius r, we have to find the largest square that can be inscribed in the semicircle, with base lying on the diameter. Examples: Input: r = 5 Output: 20 Input: r = 8 Output: 51.2 Approach: Let r be the radius of the semicircle & a be the side length of the square. From th 4 min read Largest trapezoid that can be inscribed in a semicircle Given a semicircle of radius r, the task is to find the largest trapezoid that can be inscribed in the semicircle, with base lying on the diameter.Examples: Input: r = 5 Output: 32.476 Input: r = 8 Output: 83.1384 Approach: Let r be the radius of the semicircle, x be the lower edge of the trapezoid, 4 min read Area of the Largest Triangle inscribed in a Hexagon Given here is a regular hexagon, of side length a, the task is to find the area of the biggest triangle that can be inscribed within it.Examples: Input: a = 6 Output: area = 46.7654 Input: a = 8 Output: area = 83.1384 Approach: It is very clear that the biggest triangle that can be inscribed within 3 min read Largest triangle that can be inscribed in an ellipse Given an ellipse, with major axis length 2a & 2b, the task is to find the area of the largest triangle that can be inscribed in it.Examples: Input: a = 4, b = 2 Output: 10.3923 Input: a = 5, b = 3 Output: 10.8253 Approach: So we know the ellipse is just the scaled shadow of a circle.Let's find t 4 min read Like