Interpolate points on curve having start/end points coordinates and curvature values (Python)

62 views Asked by At

I want to interpolate points on a curve in Python having the coordinates of the start and end points, and their curvature values (curvature is 1/r , r being the radius of the circumference). The sign of the curvature value indicates if the curve is to the right or to the left. The distance of the curve is also known.

Example approach:

pointA = { 'coordinates' : (latitudeA, longitudeA), 'curvature': 0 } 
pointB = { 'coordinates' : (latitudeB, longitudeB), 'curvature': -30 }

curve_distance = 120 # in meters

step_size = 1 # interpolate points every step_size meters

# calculate interpolated points

If curvature value of both points is 0, it is a usual linear interpolation. I'm adding the code if someone is interested in how to calculate the GPS points.

def haversine_distance(lat1, lon1, lat2, lon2):
    # Convert latitude and longitude from degrees to radians
    lat1 = math.radians(lat1)
    lon1 = math.radians(lon1)
    lat2 = math.radians(lat2)
    lon2 = math.radians(lon2)

    # Radius of the Earth in kilometers
    earth_radius = 6371 

    # Haversine formula
    dlat = lat2 - lat1
    dlon = lon2 - lon1

    a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

    # Calculate the distance
    distance = earth_radius * c

    return distance * 1000 # return distance in meters

def linearInterpolation(a_gps, b_gps, step_size):

    latitudeA = a_gps[0]
    longitudeA = a_gps[1]
    latitudeB = b_gps[0]
    longitudeB = b_gps[1]

    distance = haversine_distance(latitudeA, longitudeA, latitudeB, longitudeB)

    if step_size >= distance:
        return None
    else:
        num_intervals = int(distance / step_size)

        # Generate points at specified intervals along the path
        intermediate_points = []
        intermediate_points.append((latitudeA, longitudeA)) # add start point to the returning vector
        for i in range(1, num_intervals + 1):
            fraction = i / (num_intervals + 1)
            intermediate_lat = latitudeA + fraction * (latitudeB - latitudeA)
            intermediate_lon = longitudeA + fraction * (longitudeB - longitudeA)

            intermediate_points.append((intermediate_lat, intermediate_lon)) # add interpolated point
        intermediate_points.append((latitudeB, longitudeB)) # add end point to the returning vector

        return intermediate_points

The issue I'm having is when I have different curvature values (I assume it is a clothoid case) and same curvature values (a circular case). I'm looking for a Python library/function that could help me with these two cases.

Thanks in advance

0

There are 0 answers