maths.area

Find the area of various geometric shapes Wikipedia reference: https://en.wikipedia.org/wiki/Area

Functions

area_circle(→ float)

Calculate the area of a circle.

area_ellipse(→ float)

Calculate the area of a ellipse.

area_parallelogram(→ float)

Calculate the area of a parallelogram.

area_rectangle(→ float)

Calculate the area of a rectangle.

area_reg_polygon(→ float)

Calculate the area of a regular polygon.

area_rhombus(→ float)

Calculate the area of a rhombus.

area_square(→ float)

Calculate the area of a square.

area_trapezium(→ float)

Calculate the area of a trapezium.

area_triangle(→ float)

Calculate the area of a triangle given the base and height.

area_triangle_three_sides(→ float)

Calculate area of triangle when the length of 3 sides are known.

surface_area_cone(→ float)

Calculate the Surface Area of a Cone.

surface_area_conical_frustum(→ float)

Calculate the Surface Area of a Conical Frustum.

surface_area_cube(→ float)

Calculate the Surface Area of a Cube.

surface_area_cuboid(→ float)

Calculate the Surface Area of a Cuboid.

surface_area_cylinder(→ float)

Calculate the Surface Area of a Cylinder.

surface_area_hemisphere(→ float)

Calculate the Surface Area of a Hemisphere.

surface_area_sphere(→ float)

Calculate the Surface Area of a Sphere.

surface_area_torus(→ float)

Calculate the Area of a Torus.

Module Contents

maths.area.area_circle(radius: float) float

Calculate the area of a circle.

>>> area_circle(20)
1256.6370614359173
>>> area_circle(1.6)
8.042477193189871
>>> area_circle(0)
0.0
>>> area_circle(-1)
Traceback (most recent call last):
    ...
ValueError: area_circle() only accepts non-negative values
maths.area.area_ellipse(radius_x: float, radius_y: float) float

Calculate the area of a ellipse.

>>> area_ellipse(10, 10)
314.1592653589793
>>> area_ellipse(10, 20)
628.3185307179587
>>> area_ellipse(0, 0)
0.0
>>> area_ellipse(1.6, 2.6)
13.06902543893354
>>> area_ellipse(-10, 20)
Traceback (most recent call last):
    ...
ValueError: area_ellipse() only accepts non-negative values
>>> area_ellipse(10, -20)
Traceback (most recent call last):
    ...
ValueError: area_ellipse() only accepts non-negative values
>>> area_ellipse(-10, -20)
Traceback (most recent call last):
    ...
ValueError: area_ellipse() only accepts non-negative values
maths.area.area_parallelogram(base: float, height: float) float

Calculate the area of a parallelogram.

>>> area_parallelogram(10, 20)
200
>>> area_parallelogram(1.6, 2.6)
4.16
>>> area_parallelogram(0, 0)
0
>>> area_parallelogram(-1, -2)
Traceback (most recent call last):
    ...
ValueError: area_parallelogram() only accepts non-negative values
>>> area_parallelogram(1, -2)
Traceback (most recent call last):
    ...
ValueError: area_parallelogram() only accepts non-negative values
>>> area_parallelogram(-1, 2)
Traceback (most recent call last):
    ...
ValueError: area_parallelogram() only accepts non-negative values
maths.area.area_rectangle(length: float, width: float) float

Calculate the area of a rectangle.

>>> area_rectangle(10, 20)
200
>>> area_rectangle(1.6, 2.6)
4.16
>>> area_rectangle(0, 0)
0
>>> area_rectangle(-1, -2)
Traceback (most recent call last):
    ...
ValueError: area_rectangle() only accepts non-negative values
>>> area_rectangle(1, -2)
Traceback (most recent call last):
    ...
ValueError: area_rectangle() only accepts non-negative values
>>> area_rectangle(-1, 2)
Traceback (most recent call last):
    ...
ValueError: area_rectangle() only accepts non-negative values
maths.area.area_reg_polygon(sides: int, length: float) float

Calculate the area of a regular polygon. Wikipedia reference: https://en.wikipedia.org/wiki/Polygon#Regular_polygons Formula: (n*s^2*cot(pi/n))/4

>>> area_reg_polygon(3, 10)
43.301270189221945
>>> area_reg_polygon(4, 10)
100.00000000000001
>>> area_reg_polygon(0, 0)
Traceback (most recent call last):
    ...
ValueError: area_reg_polygon() only accepts integers greater than or equal to three as number of sides
>>> area_reg_polygon(-1, -2)
Traceback (most recent call last):
    ...
ValueError: area_reg_polygon() only accepts integers greater than or equal to three as number of sides
>>> area_reg_polygon(5, -2)
Traceback (most recent call last):
    ...
ValueError: area_reg_polygon() only accepts non-negative values as length of a side
>>> area_reg_polygon(-1, 2)
Traceback (most recent call last):
    ...
ValueError: area_reg_polygon() only accepts integers greater than or equal to three as number of sides
maths.area.area_rhombus(diagonal_1: float, diagonal_2: float) float

Calculate the area of a rhombus.

>>> area_rhombus(10, 20)
100.0
>>> area_rhombus(1.6, 2.6)
2.08
>>> area_rhombus(0, 0)
0.0
>>> area_rhombus(-1, -2)
Traceback (most recent call last):
    ...
ValueError: area_rhombus() only accepts non-negative values
>>> area_rhombus(1, -2)
Traceback (most recent call last):
    ...
ValueError: area_rhombus() only accepts non-negative values
>>> area_rhombus(-1, 2)
Traceback (most recent call last):
    ...
ValueError: area_rhombus() only accepts non-negative values
maths.area.area_square(side_length: float) float

Calculate the area of a square.

>>> area_square(10)
100
>>> area_square(0)
0
>>> area_square(1.6)
2.5600000000000005
>>> area_square(-1)
Traceback (most recent call last):
    ...
ValueError: area_square() only accepts non-negative values
maths.area.area_trapezium(base1: float, base2: float, height: float) float

Calculate the area of a trapezium.

>>> area_trapezium(10, 20, 30)
450.0
>>> area_trapezium(1.6, 2.6, 3.6)
7.5600000000000005
>>> area_trapezium(0, 0, 0)
0.0
>>> area_trapezium(-1, -2, -3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
>>> area_trapezium(-1, 2, 3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
>>> area_trapezium(1, -2, 3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
>>> area_trapezium(1, 2, -3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
>>> area_trapezium(-1, -2, 3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
>>> area_trapezium(1, -2, -3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
>>> area_trapezium(-1, 2, -3)
Traceback (most recent call last):
    ...
ValueError: area_trapezium() only accepts non-negative values
maths.area.area_triangle(base: float, height: float) float

Calculate the area of a triangle given the base and height.

>>> area_triangle(10, 10)
50.0
>>> area_triangle(1.6, 2.6)
2.08
>>> area_triangle(0, 0)
0.0
>>> area_triangle(-1, -2)
Traceback (most recent call last):
    ...
ValueError: area_triangle() only accepts non-negative values
>>> area_triangle(1, -2)
Traceback (most recent call last):
    ...
ValueError: area_triangle() only accepts non-negative values
>>> area_triangle(-1, 2)
Traceback (most recent call last):
    ...
ValueError: area_triangle() only accepts non-negative values
maths.area.area_triangle_three_sides(side1: float, side2: float, side3: float) float

Calculate area of triangle when the length of 3 sides are known. This function uses Heron’s formula: https://en.wikipedia.org/wiki/Heron%27s_formula

>>> area_triangle_three_sides(5, 12, 13)
30.0
>>> area_triangle_three_sides(10, 11, 12)
51.521233486786784
>>> area_triangle_three_sides(0, 0, 0)
0.0
>>> area_triangle_three_sides(1.6, 2.6, 3.6)
1.8703742940919619
>>> area_triangle_three_sides(-1, -2, -1)
Traceback (most recent call last):
    ...
ValueError: area_triangle_three_sides() only accepts non-negative values
>>> area_triangle_three_sides(1, -2, 1)
Traceback (most recent call last):
    ...
ValueError: area_triangle_three_sides() only accepts non-negative values
>>> area_triangle_three_sides(2, 4, 7)
Traceback (most recent call last):
    ...
ValueError: Given three sides do not form a triangle
>>> area_triangle_three_sides(2, 7, 4)
Traceback (most recent call last):
    ...
ValueError: Given three sides do not form a triangle
>>> area_triangle_three_sides(7, 2, 4)
Traceback (most recent call last):
    ...
ValueError: Given three sides do not form a triangle
maths.area.surface_area_cone(radius: float, height: float) float

Calculate the Surface Area of a Cone. Wikipedia reference: https://en.wikipedia.org/wiki/Cone Formula: pi * r * (r + (h ** 2 + r ** 2) ** 0.5)

>>> surface_area_cone(10, 24)
1130.9733552923256
>>> surface_area_cone(6, 8)
301.59289474462014
>>> surface_area_cone(1.6, 2.6)
23.387862992395807
>>> surface_area_cone(0, 0)
0.0
>>> surface_area_cone(-1, -2)
Traceback (most recent call last):
    ...
ValueError: surface_area_cone() only accepts non-negative values
>>> surface_area_cone(1, -2)
Traceback (most recent call last):
    ...
ValueError: surface_area_cone() only accepts non-negative values
>>> surface_area_cone(-1, 2)
Traceback (most recent call last):
    ...
ValueError: surface_area_cone() only accepts non-negative values
maths.area.surface_area_conical_frustum(radius_1: float, radius_2: float, height: float) float

Calculate the Surface Area of a Conical Frustum.

>>> surface_area_conical_frustum(1, 2, 3)
45.511728065337266
>>> surface_area_conical_frustum(4, 5, 6)
300.7913575056268
>>> surface_area_conical_frustum(0, 0, 0)
0.0
>>> surface_area_conical_frustum(1.6, 2.6, 3.6)
78.57907060751548
>>> surface_area_conical_frustum(-1, 2, 3)
Traceback (most recent call last):
    ...
ValueError: surface_area_conical_frustum() only accepts non-negative values
>>> surface_area_conical_frustum(1, -2, 3)
Traceback (most recent call last):
    ...
ValueError: surface_area_conical_frustum() only accepts non-negative values
>>> surface_area_conical_frustum(1, 2, -3)
Traceback (most recent call last):
    ...
ValueError: surface_area_conical_frustum() only accepts non-negative values
maths.area.surface_area_cube(side_length: float) float

Calculate the Surface Area of a Cube.

>>> surface_area_cube(1)
6
>>> surface_area_cube(1.6)
15.360000000000003
>>> surface_area_cube(0)
0
>>> surface_area_cube(3)
54
>>> surface_area_cube(-1)
Traceback (most recent call last):
    ...
ValueError: surface_area_cube() only accepts non-negative values
maths.area.surface_area_cuboid(length: float, breadth: float, height: float) float

Calculate the Surface Area of a Cuboid.

>>> surface_area_cuboid(1, 2, 3)
22
>>> surface_area_cuboid(0, 0, 0)
0
>>> surface_area_cuboid(1.6, 2.6, 3.6)
38.56
>>> surface_area_cuboid(-1, 2, 3)
Traceback (most recent call last):
    ...
ValueError: surface_area_cuboid() only accepts non-negative values
>>> surface_area_cuboid(1, -2, 3)
Traceback (most recent call last):
    ...
ValueError: surface_area_cuboid() only accepts non-negative values
>>> surface_area_cuboid(1, 2, -3)
Traceback (most recent call last):
    ...
ValueError: surface_area_cuboid() only accepts non-negative values
maths.area.surface_area_cylinder(radius: float, height: float) float

Calculate the Surface Area of a Cylinder. Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder Formula: 2 * pi * r * (h + r)

>>> surface_area_cylinder(7, 10)
747.6990515543707
>>> surface_area_cylinder(1.6, 2.6)
42.22300526424682
>>> surface_area_cylinder(0, 0)
0.0
>>> surface_area_cylinder(6, 8)
527.7875658030853
>>> surface_area_cylinder(-1, -2)
Traceback (most recent call last):
    ...
ValueError: surface_area_cylinder() only accepts non-negative values
>>> surface_area_cylinder(1, -2)
Traceback (most recent call last):
    ...
ValueError: surface_area_cylinder() only accepts non-negative values
>>> surface_area_cylinder(-1, 2)
Traceback (most recent call last):
    ...
ValueError: surface_area_cylinder() only accepts non-negative values
maths.area.surface_area_hemisphere(radius: float) float

Calculate the Surface Area of a Hemisphere. Formula: 3 * pi * r^2

>>> surface_area_hemisphere(5)
235.61944901923448
>>> surface_area_hemisphere(1)
9.42477796076938
>>> surface_area_hemisphere(0)
0.0
>>> surface_area_hemisphere(1.1)
11.40398133253095
>>> surface_area_hemisphere(-1)
Traceback (most recent call last):
    ...
ValueError: surface_area_hemisphere() only accepts non-negative values
maths.area.surface_area_sphere(radius: float) float

Calculate the Surface Area of a Sphere. Wikipedia reference: https://en.wikipedia.org/wiki/Sphere Formula: 4 * pi * r^2

>>> surface_area_sphere(5)
314.1592653589793
>>> surface_area_sphere(1)
12.566370614359172
>>> surface_area_sphere(1.6)
32.169908772759484
>>> surface_area_sphere(0)
0.0
>>> surface_area_sphere(-1)
Traceback (most recent call last):
    ...
ValueError: surface_area_sphere() only accepts non-negative values
maths.area.surface_area_torus(torus_radius: float, tube_radius: float) float

Calculate the Area of a Torus. Wikipedia reference: https://en.wikipedia.org/wiki/Torus :return 4pi^2 * torus_radius * tube_radius >>> surface_area_torus(1, 1) 39.47841760435743 >>> surface_area_torus(4, 3) 473.7410112522892 >>> surface_area_torus(3, 4) Traceback (most recent call last):

ValueError: surface_area_torus() does not support spindle or self intersecting tori >>> surface_area_torus(1.6, 1.6) 101.06474906715503 >>> surface_area_torus(0, 0) 0.0 >>> surface_area_torus(-1, 1) Traceback (most recent call last):

ValueError: surface_area_torus() only accepts non-negative values >>> surface_area_torus(1, -1) Traceback (most recent call last):

ValueError: surface_area_torus() only accepts non-negative values