# Calculating semi-major and semi-minor axis length of an ellipse in QGIS

I have a layer that contains ellipse-shaped geometries. The layer has projected CRS and there are also rotated ellipses in the layer. I couldn't find a tool or plugin related to semi-major and semi-minor of an ellipse.

Is there a way to calculate semi-major and semi-minor axis length? I have added the blue points and green lines just for representation.

• Are their nodes arranged in a way that they would touch those lines exactly? Then you could (ab)use distances to the centroid I guess. Otherwise I'd try oriented rectangles and use the lengths of the sides. Apr 23, 2021 at 20:38
• If the vertices are in a projected spatial reference, then once you have the center, semi-major and semi-minor are min and max distance to vertices, and orientation is the angle to the semi-major vertex. If it's a geographic SR, you can still calculate, but you need to work through forward and inverse geodesic functions. Apr 23, 2021 at 20:42
• @bugmenot123 Some lines (maybe many of them) don't touch any vertices. I mean many touches directly a boundary segment. Apr 23, 2021 at 20:59

`Processing Toolbox -> Vector geometry -> Oriented minimum bounding box` tool may be another solution. This tool already generates the width and height of the bounding boxes.  Half of both will give you the semi-minor/major lengths with a negligible error. Then use Field Calculator to calculate them using `"width"/2` and `"height"/2`.

`Use Menu Processing / Toolbox / Minimum bounding geometry / Minimum Oriented Rectangle`. Than the values you look for correspond to half of the sited of the rectangle.

Edit: as described in @Kübras solution, the `Minimum Oriented Rectangle` already contains an attribute for width and height - thus the following step, desribed in the original answer, is not necessary.

To calculate the sites, convert the polygon to lines and explode the lines - this last tool will automatically create an attribute for width and height.

Screenshot: I created the ellipse with this expression: ` make_ellipse( make_point (0,0), 22, 55, 72)` - thus 22 and 55 for semi-minor/semi-major axis, 72 for azimuth. This corresponds almost to half of the values for the width/height attributes - the ellipse is not really round an contains just the default number of 36 segments, hence the rounding error: Calculate your ellipse center point if you do not already know it. create a Euclidean distance raster from that point. Then, use zonal statistics to get the minimum and maximum values using the ellipse and the Zonal Statistics tool.

• Isn't there a way to do it without messing with Raster? Apr 23, 2021 at 20:30