/* takes recent n points, * proceeds to get approximated coordinate where the finger was heading to.*/ private PointCollection approximater() { // Find objects near these estimated points. IHTMLDocument2 webdoc = (IHTMLDocument2)webBrowser1.Document; double run = 0.0; double prev_x = 0.0; double avg_x = 0.0; double rise = 0.0; double prev_y = 0.0; double avg_y = 0.0; PointCollection recent_points = new PointCollection(); Console.WriteLine("Gather recent points"); // add the points into pointcollection foreach (Point p in coord_pack_Q.ToList()) { recent_points.AddPoint(p); } Point centroid1 = new Point(0.0, 0.0); Point centroid2 = new Point(0.0, 0.0); if (coord_pack_Q.Count > 40) { Console.WriteLine("Do Clustering"); // Get clusters. List<PointCollection> allclusters = Clustering.doClustering(recent_points, 2); centroid1 = allclusters[0].Centroid; centroid2 = allclusters[1].Centroid; get_around(webdoc, (int)centroid1.X, (int)centroid1.Y); Console.WriteLine("get around centroid1 at:" + centroid1.X.ToString() + "," + centroid1.Y.ToString()); get_around(webdoc, (int)centroid2.X, (int)centroid2.Y); Console.WriteLine("get around centroid2 at:" + centroid2.X.ToString() + "," + centroid2.Y.ToString()); } //Console.WriteLine("find linear estimation"); // Find average growth rate from list. // This is for linear movement. /* foreach (Point cord in coord_pack_Q.ToList()) { run = cord.X - prev_x; prev_x = cord.X; avg_x = (avg_x + run); rise = cord.Y - prev_y; prev_y = cord.Y; avg_y = (avg_y + rise); } avg_x = avg_x / coord_pack_Q.Count(); avg_y = avg_y / coord_pack_Q.Count(); Point estimate = new Point(avg_x, avg_y); get_around(webdoc, (int)(estimate.X), (int)(estimate.Y)); Console.WriteLine("get around linear estimation point at:" + estimate.X.ToString() + "," + estimate.Y.ToString()); */ PointCollection near_points = new PointCollection(); //near_points.AddPoint(estimate); near_points.AddPoint(centroid1); near_points.AddPoint(centroid2); return near_points; }