import math


def from_gps_to_xyz(latitude: float, longitude: float, altitude: float):
    """Get carla location x y z coordinates from GPS (latitude, longitude, altitude)."""

    # Equatorial mean radius of Earth in meters
    # https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
    earth_radius = 6378137.0

    # Hardcoded can only work for town 01 to 07
    lat_ref = 0.0
    lon_ref = 0.0

    scale = math.cos(lat_ref * math.pi / 180.0)
    base_x = scale * lon_ref * math.pi * earth_radius / 180.0
    base_y = scale * earth_radius * math.log(math.tan((90.0 + lat_ref) * math.pi / 360.0))

    x = scale * (longitude - base_x) * math.pi * earth_radius / 180.0
    y = (scale * earth_radius * math.log(math.tan((90.0 + latitude) * math.pi / 360.0)) - base_y) * -1
    z = altitude

    # Like carla.Location
    carla_location = (x, y, z)

    return carla_location