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

Function convert_to_2d

graphics/vector3_for_2d_rendering.py:13–35  ·  view source on GitHub ↗

Converts 3d point to a 2d drawable point >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) (7.6923076923076925, 15.384615384615385) >>> convert_to_2d(1, 2, 3, 10, 10) (7.6923076923076925, 15.384615384615385) >>> convert_to_2d("1", 2, 3, 10, 10) # '1' is str Traceback (mos

(
    x: float, y: float, z: float, scale: float, distance: float
)

Source from the content-addressed store, hash-verified

11
12
13def convert_to_2d(
14 x: float, y: float, z: float, scale: float, distance: float
15) -> tuple[float, float]:
16 """
17 Converts 3d point to a 2d drawable point
18
19 >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0)
20 (7.6923076923076925, 15.384615384615385)
21
22 >>> convert_to_2d(1, 2, 3, 10, 10)
23 (7.6923076923076925, 15.384615384615385)
24
25 >>> convert_to_2d("1", 2, 3, 10, 10) # '1' is str
26 Traceback (most recent call last):
27 ...
28 TypeError: Input values must either be float or int: ['1', 2, 3, 10, 10]
29 """
30 if not all(isinstance(val, (float, int)) for val in locals().values()):
31 msg = f"Input values must either be float or int: {list(locals().values())}"
32 raise TypeError(msg)
33 projected_x = ((x * distance) / (z + distance)) * scale
34 projected_y = ((y * distance) / (z + distance)) * scale
35 return projected_x, projected_y
36
37
38def rotate(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected