MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / get_mid

Function get_mid

fractals/sierpinski_triangle.py:30–45  ·  view source on GitHub ↗

Find the midpoint of two points >>> get_mid((0, 0), (2, 2)) (1.0, 1.0) >>> get_mid((-3, -3), (3, 3)) (0.0, 0.0) >>> get_mid((1, 0), (3, 2)) (2.0, 1.0) >>> get_mid((0, 0), (1, 1)) (0.5, 0.5) >>> get_mid((0, 0), (0, 0)) (0.0, 0.0)

(p1: tuple[float, float], p2: tuple[float, float])

Source from the content-addressed store, hash-verified

28
29
30def get_mid(p1: tuple[float, float], p2: tuple[float, float]) -> tuple[float, float]:
31 """
32 Find the midpoint of two points
33
34 >>> get_mid((0, 0), (2, 2))
35 (1.0, 1.0)
36 >>> get_mid((-3, -3), (3, 3))
37 (0.0, 0.0)
38 >>> get_mid((1, 0), (3, 2))
39 (2.0, 1.0)
40 >>> get_mid((0, 0), (1, 1))
41 (0.5, 0.5)
42 >>> get_mid((0, 0), (0, 0))
43 (0.0, 0.0)
44 """
45 return (p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2
46
47
48def triangle(

Callers 1

triangleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected