Esempio n. 1
0
        public static double GetPositiveWindWorkPercentage(GoogleMapsAPI googleMapsAPI, double forecastWindVectorDirection)
        {
            int positiveWorkLength = 0;
            int negativeWorkLength = 0;

            foreach (Step step in googleMapsAPI.GetSteps())
            {
                double windStepAngleDifference = TrigonometryUtility.GetDegreeBetweenVectors(googleMapsAPI.GetStepDirection(step), forecastWindVectorDirection);
                if (Math.Cos(TrigonometryUtility.ToRadians(windStepAngleDifference)) > 0)
                {
                    positiveWorkLength += step.distance;
                }
                else
                {
                    negativeWorkLength += step.distance;
                }
            }

            return((double)positiveWorkLength / (positiveWorkLength + negativeWorkLength));
        }
Esempio n. 2
0
        public static CommuteQuality GetCommuteQualityRating(string startAddress, string destinationAddress, DateTime forecastTime)
        {
            GoogleMapsAPI googleMapsAPI = new GoogleMapsAPI(startAddress, destinationAddress);

            if (googleMapsAPI.GetPathDistance() > 100000) // > 100 km
            {
                Console.WriteLine("Distance between addresses is too long. Results may be inaccurate.");
            }
            double pathDirection = googleMapsAPI.GetPathDirection();
            WindForecastInstance windForecastInstance = WindForecastAPI.GetWindForecast(googleMapsAPI.GetMedianLatitude(), googleMapsAPI.GetMedianLongitude(), forecastTime);

            // Wind direction is the direction wind comes from, therefore before doing vector calculations it needs to be rotated 180 degrees.
            double forecastWindVectorDirection = TrigonometryUtility.RotateAngle180(windForecastInstance.WindDirectionDegrees);

            double windAngleDifference = TrigonometryUtility.GetDegreeBetweenVectors(pathDirection, forecastWindVectorDirection);
            double windHelpMagnitude   = TrigonometryUtility.DotProductWithUnitVector(windForecastInstance.windStrengthMps, windAngleDifference);

            CommuteQuality commuteQuality = new CommuteQuality();

            commuteQuality.Rating = new CommuteRating(CalculateHelpIndex(windHelpMagnitude));
            commuteQuality.windPositiveWorkPercentage = GetPositiveWindWorkPercentage(googleMapsAPI, forecastWindVectorDirection);

            return(commuteQuality);
        }
Esempio n. 3
0
 public double GetStepDirection(Step step)
 {
     return(TrigonometryUtility.GetDegreeBearing(step.StartLocation.Latitude, step.StartLocation.Longitude, step.EndLocation.Latitude, step.EndLocation.Longitude));;
 }
Esempio n. 4
0
 public static double DotProductWithUnitVector(double magnitude, double vectorAngle)
 {
     return(magnitude * Math.Cos(TrigonometryUtility.ToRadians(vectorAngle)));
 }
Esempio n. 5
0
 public double GetPathDirection()
 {
     return(TrigonometryUtility.GetDegreeBearing(pathLeg.StartLocation.Latitude, pathLeg.StartLocation.Longitude, pathLeg.EndLocation.Latitude, pathLeg.EndLocation.Longitude));;
 }