ELASTICPATHING/SOURCECODE/UbiComp2014/Elastic_Pathing_Code/path_decisions.rb
def turnRadius(start_lanes, end_lanes, way_changes, turn_angle, step_dist, prev_step_dist)
  #Turn in the same road. Use the step distance to calculate the turn radius
  #Also use this kind of turn for any kind of *_link or motorway_junction
  #because these are high-speed ramps that curve rather than making hard turns
  #The map data doesn't seem to have labelled a lot of the ramps
  #leading onto major roads (eg. route 1) so also check the angle here and
  #if the angle is less than 30 assume that this is a ramp.
  if (turn_angle < 30)
    way_changes = false
  end
  if (step_dist == 0.0 or prev_step_dist == 0.0)
    return 0.0;
  end
  if (not way_changes)
    #Convert from miles to feet for the turn radius
    step_dist = milesToFeet(step_dist)
    prev_step_dist = milesToFeet(prev_step_dist)

    #The road is curved, not a hard turn, so see how many steps fit into
    #360 degrees, treat the distance as a circle's curcumference
    #and calculate the radius
    steps = 360.0 / turn_angle.abs
    radius = steps*step_dist / (2.0*Math::PI)

  else
    #In this case the step distance is not the turning distance because the
    #road is making a single, sharp turn rather than a gradual curve
    #Assume that a driver always makes a smooth curve (as in along the
    #circumference of a circle) so we can just find the distance moved
    #by considering this path as a triangle inscribed in a circle.
    #Flipping the triangle over the x-axis creates a circular segment.
    #The equation for a radius of a circle given a circule segment is
    #r = h/2 + c**2 / 8h
    #where h is the heigh of the segment (from the chord to the circle's edge)
    #and c is the length of the chord forming the base of the segment.
    #h is the horizontal number of lanes crossed, and c is twice the
    #number of vertical lanes crossed
    #Use the number of lanes crossed to determine the turn radius
    #First case: right turn
    if (0 < turn_angle)
      #Turn over the starting lane to at most the number of lanes in the second road
      actual_distance = LANE_WIDTH*(1 + end_lanes)
      h = LANE_WIDTH
      c = 2 * end_lanes * LANE_WIDTH
    else
      #Left turns cover the lanes on the far side of the starting road, the
      #initial lane, and the lanes in the new way
      actual_distance = LANE_WIDTH*(1 + start_lanes + 2*end_lanes)
      h = (1+start_lanes)*LANE_WIDTH
      c = 2 * 2 * end_lanes * LANE_WIDTH
    end
    #Again, the equation for a radius of a circle given a circule segment is
    #r = h/2 + c**2 / 8h
    radius = h / 2.0 + c**2 / (8*h)
  end
  return radius
end
#Use the number of lanes crossed and the turn angle to determine a turn radius
#Uses the same unit as the lane sizes, which is feet
Use the number of lanes crossed and the turn angle to determine a turn radius
Uses the same unit as the lane sizes, which is feet
Use the number of lanes crossed and the turn angle to determine a turn radius Uses the same unit as the lane sizes which is feet
def turnRadius(start_lanes, end_lanes, way_changes, turn_angle, step_dist, prev_step_dist)
  if (turn_angle < 30)
    way_changes = false
  end
  if (step_dist == 0.0 or prev_step_dist == 0.0)
    return 0.0;
  end
  if (not way_changes)
    step_dist = milesToFeet(step_dist)
    prev_step_dist = milesToFeet(prev_step_dist)
    steps = 360.0 / turn_angle.abs
    radius = steps*step_dist / (2.0*Math::PI)
  else
    if (0 < turn_angle)
      actual_distance = LANE_WIDTH*(1 + end_lanes)
      h = LANE_WIDTH
      c = 2 * end_lanes * LANE_WIDTH
    else
      actual_distance = LANE_WIDTH*(1 + start_lanes + 2*end_lanes)
      h = (1+start_lanes)*LANE_WIDTH
      c = 2 * 2 * end_lanes * LANE_WIDTH
    end
    radius = h / 2.0 + c**2 / (8*h)
  end
  return radius
end
def turnRadius ( start_lanes , end_lanes , way_changes , turn_angle , step_dist , prev_step_dist ) if ( turn_angle < 30 ) way_changes = false end if ( step_dist == 0.0 or prev_step_dist == 0.0 ) return 0.0 ; end if ( not way_changes ) step_dist = milesToFeet ( step_dist ) prev_step_dist = milesToFeet ( prev_step_dist ) steps = 360.0 / turn_angle . abs radius = steps * step_dist / ( 2.0 * Math :: PI ) else if ( 0 < turn_angle ) actual_distance = LANE_WIDTH * ( 1 + end_lanes ) h = LANE_WIDTH c = 2 * end_lanes * LANE_WIDTH else actual_distance = LANE_WIDTH * ( 1 + start_lanes + 2 * end_lanes ) h = ( 1 + start_lanes ) * LANE_WIDTH c = 2 * 2 * end_lanes * LANE_WIDTH end radius = h / 2.0 + c ** 2 / ( 8 * h ) end return radius end
Use the number of lanes crossed and the turn angle to determine a turn radius
Uses the same unit as the lane sizes, which is feet
Use the number of lanes crossed and the turn angle to determine a turn radius Uses the same unit as the lane sizes which is feet
#Turn in the same road. Use the step distance to calculate the turn radius #Also use this kind of turn for any kind of *_link or motorway_junction #because these are high-speed ramps that curve rather than making hard turns #The map data doesn't seem to have labelled a lot of the ramps #leading onto major roads (eg. route 1) so also check the angle here and #if the angle is less than 30 assume that this is a ramp. #Convert from miles to feet for the turn radius #The road is curved, not a hard turn, so see how many steps fit into #360 degrees, treat the distance as a circle's curcumference #and calculate the radius #In this case the step distance is not the turning distance because the #road is making a single, sharp turn rather than a gradual curve #Assume that a driver always makes a smooth curve (as in along the #circumference of a circle) so we can just find the distance moved #by considering this path as a triangle inscribed in a circle. #Flipping the triangle over the x-axis creates a circular segment. #The equation for a radius of a circle given a circule segment is #r = h/2 + c**2 / 8h #where h is the heigh of the segment (from the chord to the circle's edge) #and c is the length of the chord forming the base of the segment. #h is the horizontal number of lanes crossed, and c is twice the #number of vertical lanes crossed #Use the number of lanes crossed to determine the turn radius #First case: right turn #Turn over the starting lane to at most the number of lanes in the second road #Left turns cover the lanes on the far side of the starting road, the #initial lane, and the lanes in the new way #Again, the equation for a radius of a circle given a circule segment is #r = h/2 + c**2 / 8h
start_lanes
end_lanes
way_changes
turn_angle
step_dist
prev_step_dist