コード例 #1
0
        /// <span class="code-SummaryComment"><summary></span>
        /// The distance of a point from a line made from point1 and point2.
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name="pt1">The PT1.</param></span>
        /// <span class="code-SummaryComment"><param name="pt2">The PT2.</param></span>
        /// <span class="code-SummaryComment"><param name="p">The p.</param></span>
        /// <span class="code-SummaryComment"><returns></returns></span>
        public static Double PerpendicularDistance(
            PolygonPoint point1, PolygonPoint point2, PolygonPoint point)
        {
            double Point1X, Point1Y;

            point1.GetCoordinates(out Point1X, out Point1Y);
            double Point2X, Point2Y;

            point2.GetCoordinates(out Point2X, out Point2Y);
            double PointX, PointY;

            point.GetCoordinates(out PointX, out PointY);

            //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)|   *Area of triangle
            //Base = v((x1-x2)²+(x1-x2)²)                               *Base of Triangle*
            //Area = .5*Base*H                                          *Solve for height
            //Height = Area/.5/Base


            Double area = Math.Abs(.5 * (Point1X * Point2Y + Point2X *
                                         PointY + PointX * Point1Y - Point2X * Point1Y - PointX *
                                         Point2Y - Point1X * PointY));
            Double bottom = Math.Sqrt(Math.Pow(Point1X - Point2X, 2) +
                                      Math.Pow(Point1Y - Point2Y, 2));
            Double height = area / bottom * 2;

            return(height);
        }
コード例 #2
0
        private TubeVisual3D GetPathForMeanReadingLocation(double maxHeight)
        {
            int    totalDeltas = BooksReadProvider.BookLocationDeltas.Count;
            double increment   = maxHeight / (0.5 * (1 + totalDeltas));

            List <Point3D> averagePosition = new List <Point3D>();
            int            counter         = 0;

            foreach (BookLocationDelta delta in BooksReadProvider.BookLocationDeltas)
            {
                PolygonPoint latLong = new PolygonPoint {
                    Latitude = delta.AverageLatitude, Longitude = delta.AverageLongitude
                };
                double x, y;
                latLong.GetCoordinates(out x, out y);

                double height = maxHeight - (counter * increment);

                averagePosition.Add(new Point3D(x, y, height));
                counter++;
            }

            TubeVisual3D path = new TubeVisual3D
            {
                Path         = new Point3DCollection(averagePosition),
                Diameter     = 0.5,
                ThetaDiv     = 20,
                IsPathClosed = false,
                Fill         = Brushes.Green
            };

            return(path);
        }
コード例 #3
0
        private TextVisual3D GetCountryText(
            double latitude, double longitude, int booksCount, string label, double height)
        {
            PolygonPoint latLong = new PolygonPoint()
            {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);

            var labelPoint = new Point3D(x, y + 1, height + 1);

            TextVisual3D text3D = new TextVisual3D()
            {
                Foreground          = Brushes.Black,
                Background          = Brushes.LightYellow,
                BorderBrush         = Brushes.DarkBlue,
                Height              = 2,
                FontWeight          = System.Windows.FontWeights.Normal,
                IsDoubleSided       = true,
                Position            = labelPoint,
                UpDirection         = new Vector3D(0, 0.7, 1),
                TextDirection       = new Vector3D(1, 0, 0),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                VerticalAlignment   = System.Windows.VerticalAlignment.Bottom,
                Text = label
            };

            return(text3D);
        }
コード例 #4
0
        private GeometryModel3D GetCountryHelixArrowGeometry(
            double latitude, double longitude, double height, OxyColor color)
        {
            PolygonPoint latLong = new PolygonPoint()
            {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);

            GeometryModel3D countryGeometry = new GeometryModel3D();
            var             brush           = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));

            countryGeometry.Material = MaterialHelper.CreateMaterial(brush, ambient: 177);
            var meshBuilder = new MeshBuilder(false, false);

            var top          = new Point3D(x, y, height);
            var countryPoint = new Point3D(x, y, 0);

            meshBuilder.AddCone(top, countryPoint, 1.0, true, 16);

            var textStart = new Point3D(x, y + 1, height + 1);

            meshBuilder.AddArrow(textStart, top, 0.1);

            countryGeometry.Geometry = meshBuilder.ToMesh();
            return(countryGeometry);
        }
コード例 #5
0
        private static GeometryModel3D GetCountryEllipsoidArrowGeometry(
            double latitude,
            double longitude,
            int booksCount,
            Color color)
        {
            PolygonPoint latLong = new PolygonPoint {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);
            double height = 1 + Math.Log(booksCount);

            GeometryModel3D countryGeometry = new GeometryModel3D();
            SolidColorBrush brush           = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));

            countryGeometry.Material = MaterialHelper.CreateMaterial(brush, ambient: 177);
            MeshBuilder meshBuilder = new MeshBuilder(false, false);

            Point3D countryPoint = new Point3D(x, y, 0);

            meshBuilder.AddEllipsoid(countryPoint, 1.0, 1.0, height);

            Point3D top       = new Point3D(x, y, height);
            Point3D textStart = new Point3D(x, y + 1, height + 1);

            meshBuilder.AddArrow(textStart, top, 0.1);

            countryGeometry.Geometry = meshBuilder.ToMesh();
            return(countryGeometry);
        }
        private void AddBooksAndPagesScatterSeries(PlotModel newPlot)
        {
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries");

            foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries)
            {
                string       name    = authorCountry.Country;
                WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name);
                if (country != null)
                {
                    int pointSize = authorCountry.TotalBooksReadFromCountry;
                    if (pointSize < 5)
                    {
                        pointSize = 5;
                    }

                    PolygonPoint latLong = new PolygonPoint()
                    {
                        Latitude = country.Latitude, Longitude = country.Longitude
                    };
                    double x, y;
                    latLong.GetCoordinates(out x, out y);

                    ScatterPoint point =
                        new ScatterPoint(x, y, pointSize,
                                         authorCountry.TotalPagesReadFromCountry)
                    {
                        Tag = name
                    };
                    pointsSeries.Points.Add(point);
                }
            }
            pointsSeries.RenderInLegend      = false;
            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotalPages {6}";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (OxyColor color in OxyPalettes.Jet(200).Colors)
            {
                OxyColor faintColor = OxyColor.FromArgb(128, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Total Pages"
            });
        }
コード例 #7
0
        private TextVisual3D GetNationText(Nation country, int count, string label, double height)
        {
            double       latitude  = country.Latitude;
            double       longitude = country.Longitude;
            PolygonPoint latLong   = new PolygonPoint()
            {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);

            var labelPoint = new Point3D(x, y + 1, height + 1);

            Brush background = Brushes.LightYellow;

            if (country.ImageUri != null)
            {
                try
                {
                    System.Windows.Media.Imaging.BitmapImage im =
                        new System.Windows.Media.Imaging.BitmapImage(country.DisplayImage);

                    background         = new ImageBrush(im);
                    background.Opacity = 0.5;
                }
                catch (Exception e)
                {
                    _log.Debug(e);
                }
            }

            TextVisual3D text3D = new TextVisual3D()
            {
                Foreground          = Brushes.DarkBlue,
                Background          = background,
                BorderBrush         = Brushes.PapayaWhip,
                Height              = 2,
                FontWeight          = System.Windows.FontWeights.Bold,
                IsDoubleSided       = true,
                Position            = labelPoint,
                UpDirection         = new Vector3D(0, 0.7, 1),
                TextDirection       = new Vector3D(1, 0, 0),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                VerticalAlignment   = System.Windows.VerticalAlignment.Bottom,
                Text = label
            };

            return(text3D);
        }
コード例 #8
0
        private GeometryModel3D GetCountryOctahedronGeometry(
            double latitude, double longitude, double height, OxyColor color, int books, Uri image = null)
        {
            PolygonPoint latLong = new PolygonPoint()
            {
                Latitude = latitude, Longitude = longitude
            };
            double x, y;

            latLong.GetCoordinates(out x, out y);

            GeometryModel3D countryGeometry = new GeometryModel3D();
            var             brush           = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));

            countryGeometry.Material = MaterialHelper.CreateMaterial(brush, ambient: 177);

            var meshBuilder = new MeshBuilder(false, false);

            var top          = new Point3D(x, y, height);
            var countryPoint = new Point3D(x, y, 0);

            Vector3D normalVector = new Vector3D(1, 1, 0);
            Vector3D upVector     = new Vector3D(0, 0, 1);

            meshBuilder.AddCone(top, countryPoint, 1.0, true, 16);

            double side = (1 + Math.Log(books)) / Math.Log(3);

            meshBuilder.AddOctahedron(countryPoint, normalVector, upVector, side, height);

            var textStart = new Point3D(x, y + 1, height + 1);

            meshBuilder.AddArrow(textStart, top, 0.1);

            countryGeometry.Geometry = meshBuilder.ToMesh();
            return(countryGeometry);
        }
        private void AddLastTenLatLongWithTimeScatterSeries(PlotModel newPlot)
        {
            ScatterSeries pointsSeries;

            OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries,
                                                      ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Last Ten Books With Time");


            LineSeries overallSeries;

            OxyPlotUtilities.CreateLineSeries(out overallSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Overall", 0);
            var faintColorBlue = OxyColor.FromArgb(80, OxyColors.Blue.R, OxyColors.Blue.G, OxyColors.Blue.B);

            overallSeries.Color           = faintColorBlue;
            overallSeries.StrokeThickness = 2;

            LineSeries lastTenSeries;

            OxyPlotUtilities.CreateLineSeries(out lastTenSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Last 10", 0);
            var faintColorRed = OxyColor.FromArgb(80, OxyColors.Red.R, OxyColors.Red.G, OxyColors.Red.B);

            lastTenSeries.Color           = faintColorRed;
            lastTenSeries.StrokeThickness = 2;

            foreach (var delta in _mainModel.BookLocationDeltas)
            {
                var pointSize = 5;

                PolygonPoint latLong =
                    new PolygonPoint()
                {
                    Latitude = delta.AverageLatitudeLastTen, Longitude = delta.AverageLongitudeLastTen
                };
                double x, y;
                latLong.GetCoordinates(out x, out y);

                lastTenSeries.Points.Add(new DataPoint(x, y));

                ScatterPoint point =
                    new ScatterPoint(x, y, pointSize, delta.DaysSinceStart)
                {
                    Tag = delta.Date.ToString("ddd d MMM yyy")
                };
                pointsSeries.Points.Add(point);

                latLong =
                    new PolygonPoint()
                {
                    Latitude = delta.AverageLatitude, Longitude = delta.AverageLongitude
                };
                latLong.GetCoordinates(out x, out y);

                overallSeries.Points.Add(new DataPoint(x, y));
            }

            // don't draw these as renders the pic unusable
            //newPlot.Series.Add(lastTenSeries);
            //newPlot.Series.Add(overallSeries);

            pointsSeries.RenderInLegend      = false;
            pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} )";
            newPlot.Series.Add(pointsSeries);

            List <OxyColor> colors = new List <OxyColor>();

            foreach (var color in OxyPalettes.Jet(200).Colors)
            {
                var faintColor = OxyColor.FromArgb(80, color.R, color.G, color.B);
                colors.Add(faintColor);
            }

            OxyPalette faintPalette = new OxyPalette(colors);

            newPlot.Axes.Add(new LinearColorAxis {
                Position = AxisPosition.Right, Palette = faintPalette, Title = "Days Since Start"
            });
        }
コード例 #10
0
        /// <summary>
        /// Sets up the plot model to be displayed.
        /// </summary>
        /// <returns>The plot model.</returns>
        protected override PlotModel SetupPlot()
        {
            // Create the plot model
            PlotModel newPlot = new PlotModel {
                Title = "Countries of the World"
            };

            SetupLatitudeAndLongitudeAxes(newPlot);

            int flagCount = 0;

            foreach (Nation nation in GeographyProvider.Nations)
            {
                CountryGeography country = nation.Geography;
                if (country != null)
                {
                    OxyColor colour        = OxyColors.LightGreen;
                    string   title         = country.Name;
                    string   tag           = "";
                    string   trackerFormat = "{0}";
                    OxyPlotUtilities.AddCountryGeographyAreaSeriesToPlot(newPlot, country, colour, title, tag, trackerFormat);
                }

                if (!string.IsNullOrEmpty(nation.ImageUri) && flagCount < 100)
                {
                    PolygonPoint capitalCity =
                        new PolygonPoint(nation.Longitude, nation.Latitude);
                    double x, y;
                    capitalCity.GetCoordinates(out x, out y);

                    WebRequest req    = WebRequest.Create(nation.ImageUri);
                    Stream     stream = req.GetResponse().GetResponseStream();

                    if (stream == null)
                    {
                        continue;
                    }

                    Bitmap bitmap = new Bitmap(stream);

                    MemoryStream memoryStream = new MemoryStream();
                    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
                    byte[] asBytes = memoryStream.ToArray();

                    ImageFormat typeOfImage = GetImageFormat(asBytes);

                    if (typeOfImage == ImageFormat.Unknown)
                    {
                        continue;
                    }

                    OxyImage image = new OxyImage(asBytes);
                    newPlot.Annotations.Add(
                        new ImageAnnotation
                    {
                        ImageSource         = image,
                        Opacity             = 0.5,
                        X                   = new PlotLength(x, PlotLengthUnit.Data),
                        Y                   = new PlotLength(y, PlotLengthUnit.Data),
                        Width               = new PlotLength(30, PlotLengthUnit.ScreenUnits),
                        Height              = new PlotLength(20, PlotLengthUnit.ScreenUnits),
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Middle
                    });

                    flagCount++;
                }
            }

            // finally update the model with the new plot
            return(newPlot);
        }