Exemplo n.º 1
0
def detect2DCollision(lineSegment, polygon):
    #(lineSegment:LineSegment) (polygon:Polygon) =
    #    // Check characteristics of the shapes
    #   assertGreaterEqualTo "sides" (float polygon.Length) "3 sides" 3.0
    # http://stackoverflow.com/questions/12222700/determine-if-line-segment-is-inside-polygon
    # first, sort a polygon. Here, polygons are assumed to be sorted already

    #  // Gather the sides for the polygon
    polygonSides = []
    for i in range(len(polygon)):
        if i == len(polygon) - 1:
            endPoint = polygon[0]
        else:
            endPoint = polygon[i + 1]
        polygonSides.append(Spatial.LineSegment(polygon[i], endPoint))

    axes = polygonSides
    axes.append(lineSegment)
    axes = [
        Spatial.toUnitVector(
            Spatial.toNormalVector(
                Spatial.calculateLocationDifference(v.Location1, v.Location2)))
        for v in axes
    ]

    #    // Check for separation between objects
    separationExists = False
    for axis in axes:
        polyProj = projectPolygonOntoAxis(polygon, axis)
        lineSegmentProj = projectSegmentOntoAxis(lineSegment, axis)
        #// Do gaps exist between max/min intervals?
        if polyProj.Min > lineSegmentProj.Max or lineSegmentProj.Min > polyProj.Max:
            separationExists = True
    return not separationExists
Exemplo n.º 2
0
def calculateMovement(coreFunctions, parameters, weather, state, instruction):
    # (coreFunctions:SimulationCoreFunctions)
    # (parameters:FlightParameters) 
    # (weather:WeatherState) (state:FlightState) (instruction:Instruction)
    time = parameters.ActualGateDepartureTime + state.TimeElapsed*1.0 # <Time/Hours>
    currentPosition = state.AircraftPosition
    altitude = Spatial.positionToAltitude(currentPosition)

    grossWeight = coreFunctions.WeightModel(parameters, state)
    (destination, instructedAirSpeed) = instruction

    currentLocation = Spatial.positionToLocation(currentPosition)
    destinationLocation = Spatial.positionToLocation(destination)
    destinationAltitude = coreFunctions.AltitudeLimiter(grossWeight,
            Spatial.positionToAltitude(destination))
    airSpeed = coreFunctions.AirSpeedLimiter(
        parameters.AircraftType.MaximumMachSpeed,
        grossWeight, altitude, instructedAirSpeed)
    deltaVector = Spatial.calculateLocationDifference(currentLocation, destinationLocation)
    distance = Spatial.calculateDistance1(currentLocation, destinationLocation)
    if distance <= 0.0 :
        zeroGroundSpeed = Spatial.Vector(0.0, 0.0)
        return (0.0, zeroGroundSpeed, 0.0, 0.0, 0.0, [])
    else:
        #windVector = getWindVelocity(weather, time, currentPosition)
        windVector = Weather.zeroWindVelocity
        groundSpeed = Movement.calculateGroundVelocity(airSpeed, 
                                                       Spatial.calculateRadians(deltaVector),
                                                       windVector)
        groundVector = Movement.rescale(deltaVector, groundSpeed)
        (cruiseBurn, verticalCruiseFuelDiff, verticalVelocity) =  \
        coreFunctions.FuelModel(FuelModel.flightFunctions, grossWeight, altitude, 
                                airSpeed,
                                FlightTypes.getVerticalState(altitude, destinationAltitude))
        return (cruiseBurn, groundVector, verticalCruiseFuelDiff, verticalVelocity, airSpeed, [])
Exemplo n.º 3
0
def calculateMovement(coreFunctions, parameters, weather, state, instruction):
    # (coreFunctions:SimulationCoreFunctions)
    # (parameters:FlightParameters)
    # (weather:WeatherState) (state:FlightState) (instruction:Instruction)
    time = parameters.ActualGateDepartureTime + state.TimeElapsed * 1.0  # <Time/Hours>
    currentPosition = state.AircraftPosition
    altitude = Spatial.positionToAltitude(currentPosition)

    grossWeight = coreFunctions.WeightModel(parameters, state)
    (destination, instructedAirSpeed) = instruction

    currentLocation = Spatial.positionToLocation(currentPosition)
    destinationLocation = Spatial.positionToLocation(destination)
    destinationAltitude = coreFunctions.AltitudeLimiter(
        grossWeight, Spatial.positionToAltitude(destination))
    airSpeed = coreFunctions.AirSpeedLimiter(
        parameters.AircraftType.MaximumMachSpeed, grossWeight, altitude,
        instructedAirSpeed)
    deltaVector = Spatial.calculateLocationDifference(currentLocation,
                                                      destinationLocation)
    distance = Spatial.calculateDistance1(currentLocation, destinationLocation)
    if distance <= 0.0:
        zeroGroundSpeed = Spatial.Vector(0.0, 0.0)
        return (0.0, zeroGroundSpeed, 0.0, 0.0, 0.0, [])
    else:
        #windVector = getWindVelocity(weather, time, currentPosition)
        windVector = Weather.zeroWindVelocity
        groundSpeed = Movement.calculateGroundVelocity(
            airSpeed, Spatial.calculateRadians(deltaVector), windVector)
        groundVector = Movement.rescale(deltaVector, groundSpeed)
        (cruiseBurn, verticalCruiseFuelDiff, verticalVelocity) =  \
        coreFunctions.FuelModel(FuelModel.flightFunctions, grossWeight, altitude,
                                airSpeed,
                                FlightTypes.getVerticalState(altitude, destinationAltitude))
        return (cruiseBurn, groundVector, verticalCruiseFuelDiff,
                verticalVelocity, airSpeed, [])