1 # SPDX-FileCopyrightText: 2014-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 from math
import sin
, cos
, atan
, atanh
, radians
, tan
, sinh
, asin
, cosh
, degrees
7 # see conversion formulas at
8 # http://en.wikipedia.org/wiki/Transverse_Mercator_projection
9 # http://mathworld.wolfram.com/MercatorProjection.html
12 class TransverseMercator
:
15 def __init__(self
, lat
=0, lon
=0):
16 self
.lat
= lat
# in degrees
17 self
.lon
= lon
# in degrees
18 self
.lat_rad
= radians(self
.lat
)
19 self
.lon_rad
= radians(self
.lon
)
21 def fromGeographic(self
, lat
, lon
):
22 lat_rad
= radians(lat
)
23 lon_rad
= radians(lon
)
24 B
= cos(lat_rad
) * sin(lon_rad
- self
.lon_rad
)
25 x
= self
.radius
* atanh(B
)
26 y
= self
.radius
* (atan(tan(lat_rad
) / cos(lon_rad
- self
.lon_rad
)) - self
.lat_rad
)
29 def toGeographic(self
, x
, y
):
33 lon
= atan(sinh(x
) / cos(D
))
34 lat
= asin(sin(D
) / cosh(x
))
36 lon
= self
.lon
+ degrees(lon
)