Esempio n. 1
0
        public static float TotaleAfstand(List <Meting> route)
        {
            float res = 0;

            Meting vorige = null;

            foreach (Meting pt in route)
            {
                if (vorige != null)
                {
                    res += Meting.Afstand(pt, vorige);
                }
                vorige = pt;
            }

            return(res);
        }
Esempio n. 2
0
            protected override void OnDraw(Canvas canvas)
            {
                base.OnDraw(canvas);
                Paint verf = new Paint();

                if (running == true)
                {
                    verf.Color = Color.DarkRed;

                    //Midx en midy staan voor het midden van de kaart
                    midx = (centrum.X - 136000) * 0.4f;
                    midy = -(centrum.Y - 458000) * 0.4f;

                    //De kaart (geo) wordt getekend met behulp van de matrix
                    Matrix mat = new Matrix();
                    mat.PostTranslate(-midx, -midy);
                    mat.PostScale(Schaal, Schaal);
                    mat.PostTranslate(canvas.Width / 2, canvas.Height / 2);

                    canvas.DrawBitmap(geo, mat, verf);

                    //Teken de afgelegde route
                    foreach (Meting pt in route)
                    {
                        float bx = pt.punt.X - centrum.X;
                        float qx = bx * 0.4f;
                        float tx = qx * Schaal;
                        float a  = this.Width / 2 + tx;

                        float by = pt.punt.Y - centrum.Y;
                        float qy = by * 0.4f;
                        float ty = qy * Schaal;
                        float b  = this.Height / 2 + -ty;

                        canvas.DrawCircle(a, b, 10, verf);
                    }

                    //Centrum is het midden van de kaart en huidig is het huidige punt van de GPS
                    if (huidig != null)
                    {
                        float ax = huidig.X - centrum.X;
                        float px = ax * 0.4f;
                        float sx = px * Schaal;
                        float x  = this.Width / 2 + sx;

                        float ay = huidig.Y - centrum.Y;
                        float py = ay * 0.4f;
                        float sy = py * Schaal;
                        float y  = this.Height / 2 + -sy;

                        //Het pijltje dat aangeeft waar de user zich bevindt wordt getekend met behulp van de matrix
                        Matrix pmat = new Matrix();
                        pmat.PostTranslate(-arrow.Width / 2, -arrow.Height / 2);
                        pmat.PostRotate(this.Hoek);
                        pmat.PostTranslate(x, y);

                        canvas.DrawBitmap(arrow, pmat, null);
                    }
                }
                else
                {
                    Meting vorige = null;
                    max = 0;
                    min = 1000;
                    float snelheidafgelegd;
                    tijdsverschil = 0;
                    // float x = 50;

                    //vaste, constante delen van de grafiek
                    verf.Color    = Color.Black;
                    verf.TextSize = 30;
                    canvas.DrawRect(40, 0, 50, this.Height - 200, verf);
                    canvas.DrawRect(40, this.Height - 200, this.Width, this.Height - 190, verf);
                    canvas.DrawText("15", 5, 30, verf);
                    canvas.DrawText("0", 15, this.Height - 210, verf);


                    if (route != null && route.Count != 0)
                    {
                        //Startpunt en starttijd berekenen
                        Meting   startpunt = route[0];
                        DateTime starttijd = startpunt.dt;

                        //Eindpunt en eindtijd berekenen
                        Meting   eindpunt = route[route.Count - 1];
                        DateTime eindtijd = eindpunt.dt;

                        canvas.DrawText($"{starttijd}", 40, this.Height - 165, verf);
                        canvas.DrawText($"{eindtijd}", this.Width - 270, this.Height - 165, verf);


                        //Console.WriteLine(eindtijd);
                        //Console.WriteLine(starttijd);

                        //Het totale tijdsverschil
                        tijdsverschil = (float)(eindtijd - starttijd).TotalHours;
                        //Console.WriteLine(tijdsverschil.TotalSeconds);
                    }

                    //Teken de grafiek
                    float afgelegdeafstand = 0;
                    totaleafstand = Meting.TotaleAfstand(route);
                    float vorigex = 0;
                    float vorigey = 0;
                    float x       = 0;
                    float y       = 0;
                    //Gemiddelde snelheid berekenen en tekenen
                    verf.Color         = Color.Gray;
                    gemiddeldesnelheid = totaleafstand / tijdsverschil;
                    float yGS = (this.Height) - (gemiddeldesnelheid / 15 * (this.Height - 200) + 200);
                    canvas.DrawLine(40, yGS, this.Width, yGS, verf);
                    canvas.DrawText("Gem. snelheid", this.Width - 300, yGS + 35, verf);

                    foreach (Meting pt in route)
                    {
                        verf.Color = Color.DarkRed;


                        if (vorige != null)// er is een vorig punt
                        {
                            //snelheidafgelegd = 15;
                            snelheidafgelegd = Meting.Snelheid(pt, vorige);
                            //Console.WriteLine(snelheidafgelegd);

                            //snelheidafgelegd = 0;
                            afgelegdeafstand += Meting.Afstand(pt, vorige);

                            x = (afgelegdeafstand / totaleafstand) * (this.Width - 40) + 40; //totale afstand
                            y = (this.Height) - (snelheidafgelegd / 15 * (this.Height - 200) + 200);
                            float r = 10;

                            canvas.DrawCircle(x, y, r, verf);
                            if (vorigex != 0 && vorigey != 0)
                            {
                                canvas.DrawLine(vorigex, vorigey, x, y, verf);
                            }

                            //a += 30;

                            //Berekenen maximale snelheid
                            if (snelheidafgelegd > max)
                            {
                                max = snelheidafgelegd;
                            }

                            //Berekenen minimale snelheid
                            if (snelheidafgelegd < min)
                            {
                                min = snelheidafgelegd;
                            }

                            // canvas.DrawLine((((this.Width - x) / (float)tijdsduur.TotalSeconds) * (float)tijdpuntOud.TotalSeconds) + x, y - (y / 15) * snelheidOud, y - (y / 15) * snelheid, roze);
                            // canvas.DrawLine();
                        }
                        //Console.WriteLine(min);
                        vorige  = pt;
                        vorigex = x;
                        vorigey = y;
                        //Console.WriteLine(max);
                    }



                    //Informatie op het scherm zetten

                    //Laagste snelheid
                    canvas.DrawText($"De laagste snelheid was: {(int)min} km/u.", 30, this.Height - 80, verf);

                    //Hoogste snelheid
                    canvas.DrawText($"De hoogste snelheid was: {(int)max} km/u.", 30, this.Height - 10, verf);

                    //Gemiddelde snelheid
                    canvas.DrawText($"De gemiddelde snelheid was: {(int)gemiddeldesnelheid} km/u.", this.Width / 2, this.Height - 80, verf);

                    //Aantal calorieën verbrand
                    float kcal1 = 13 * 70; //Standaard aantal kcal en een gemiddeld gewicht genomen.
                    kcal2 = kcal1 * tijdsverschil;
                    canvas.DrawText($"Je hebt ongeveer {(int)kcal2} kcal verbrand.", this.Width / 2, this.Height - 10, verf);
                }
            }