# 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 the scaling factor.

x^2/a^2 + y^2/b^2 = 1is an ellipse. Rewrite this as:

(y*(a/b))^2+x^2 = a^2

This is just a vertically scaled down circle of radius **a** (think light falls from the top at an angle), and the vertical factor is **a/b**. The biggest triangle in the ellipse is then a scaled up version of the biggest triangle in the circle. Using a little geometry and taking symmetry into account, we can understand that the biggest such triangle is the equilateral one. It’s sides will be **√3a** and the area will be **(3√3)a^2/4**

Translating this to ellipse terms – we scale the horizontal dimension up by a factor **a/b**, and the area of the biggest triangle in the ellipse is,

A = (3√3)a^2/4b

Below is the implementation of above approach:

## C++

`// C++ Program to find the biggest triangle ` `// which can be inscribed within the ellipse ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the area ` `// of the triangle ` `float` `trianglearea(` `float` `a, ` `float` `b) ` `{ ` ` ` ` ` `// a and b cannot be negative ` ` ` `if` `(a < 0 || b < 0) ` ` ` `return` `-1; ` ` ` ` ` `// area of the triangle ` ` ` `float` `area = (3 * ` `sqrt` `(3) * ` `pow` `(a, 2)) / (4 * b); ` ` ` ` ` `return` `area; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `a = 4, b = 2; ` ` ` `cout << trianglearea(a, b) << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`//Java Program to find the biggest triangle ` `//which can be inscribed within the ellipse ` ` ` `public` `class` `GFG { ` ` ` ` ` `//Function to find the area ` ` ` `//of the triangle ` ` ` `static` `float` `trianglearea(` `float` `a, ` `float` `b) ` ` ` `{ ` ` ` ` ` `// a and b cannot be negative ` ` ` `if` `(a < ` `0` `|| b < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// area of the triangle ` ` ` `float` `area = (` `float` `)(` `3` `* Math.sqrt(` `3` `) * Math.pow(a, ` `2` `)) / (` `4` `* b); ` ` ` ` ` `return` `area; ` ` ` `} ` ` ` ` ` `//Driver code ` ` ` `public` `static` `void` `main(String[] args) { ` ` ` ` ` `float` `a = ` `4` `, b = ` `2` `; ` ` ` `System.out.println(trianglearea(a, b)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 Program to find the biggest triangle ` `# which can be inscribed within the ellipse ` ` ` `from` `math ` `import` `*` ` ` `# Function to find the area ` `# of the triangle ` `def` `trianglearea(a, b) : ` ` ` ` ` `# a and b cannot be negative ` ` ` `if` `a < ` `0` `or` `b < ` `0` `: ` ` ` `return` `-` `1` ` ` ` ` `# area of the triangle ` ` ` `area ` `=` `(` `3` `*` `sqrt(` `3` `) ` `*` `pow` `(a, ` `2` `)) ` `/` `(` `4` `*` `b) ` ` ` ` ` `return` `area ` ` ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `a, b ` `=` `4` `, ` `2` ` ` `print` `(` `round` `(trianglearea(a, b),` `4` `)) ` ` ` ` ` `# This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the biggest ` `// triangle which can be inscribed ` `// within the ellipse ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the area ` `// of the triangle ` `static` `float` `trianglearea(` `float` `a, ` `float` `b) ` `{ ` ` ` `// a and b cannot be negative ` `if` `(a < 0 || b < 0) ` ` ` `return` `-1; ` ` ` `// area of the triangle ` `float` `area = (` `float` `)(3 * Math.Sqrt(3) * ` ` ` `Math.Pow(a, 2)) / (4 * b); ` ` ` `return` `area; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `float` `a = 4, b = 2; ` ` ` `Console.WriteLine(trianglearea(a, b)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the biggest ` `// triangle which can be inscribed ` `// within the ellipse ` ` ` `// Function to find the area ` `// of the triangle ` `function` `trianglearea(` `$a` `, ` `$b` `) ` `{ ` ` ` ` ` `// a and b cannot be negative ` ` ` `if` `(` `$a` `< 0 || ` `$b` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// area of the triangle ` ` ` `$area` `= (3 * sqrt(3) * ` ` ` `pow(` `$a` `, 2)) / (4 * ` `$b` `); ` ` ` ` ` `return` `$area` `; ` `} ` ` ` `// Driver code ` `$a` `= 4; ` `$b` `= 2; ` `echo` `trianglearea(` `$a` `, ` `$b` `); ` ` ` `// This code is contributed ` `// by Shivi_Aggarwal ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

10.3923

## Recommended Posts:

- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Area of the Largest square that can be inscribed in an ellipse
- Area of Largest rectangle that can be inscribed in an Ellipse
- Find the area of largest circle inscribed in ellipse
- Largest triangle that can be inscribed in a semicircle
- Largest hexagon that can be inscribed within an equilateral triangle
- Area of largest triangle that can be inscribed within a rectangle
- Area of the Largest Triangle inscribed in a Hexagon
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.