amosproj / amos2021ws01-geo-data-search

Natural language and buzzword search on routing and places
MIT License
3 stars 1 forks source link

Research and draft for curve algorithm with polyline #212

Closed oliviadargel closed 2 years ago

oliviadargel commented 2 years ago

Note: Old ticket #179 was about coordinates, this one is about polylines

User story

  1. As a user
  2. I want to search for routes with a specific number of turns/length of turns
  3. So that I can plan test drives

Acceptance criteria

Definition of done

NumanFidan commented 2 years ago

Okey here is the Pseudo Code:

calculating the radius of every point : // starting point for this approach : https://roadcurvature.com/how-it-works/

val coordinates //list of coordinates
val radiuses //list of radious
for (i in 0 until coordiantes.size){
    val firstC = coordinates[i]
    val secC   = coordinates[i+1]
    val thirdC = coordinates[i+2]

    val a = distance(firstC, secC)
    val b = distance(secC,thirdC)
    val c = distance(firstC, thirdC)

    // resource: https://www.mathopenref.com/trianglecircumcircle.html
    val radius = (a*b*c)/(sqrt((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c)))
    radiuses.add(radius)
}

We now have a radius for every 3 nodes in the route. The problem is a curve is not have to only contain 3 nodes. Let's say if a curve has 9 nodes and if we filter them only by radius, our result will be like, "there are 9 curves here" but normally all of these nodes are in the same curve. OSM has segments attributes for it, it might be useful to calculate but here API doesn't have these attributes. Need to find a way to differentiate if a node group is just in an already determined curve or a new curve.