/* public Point GetPalm(List<Point> hull) { int countX = 0; int countY = 0; int countZ = 0; foreach (Point point in hull) { countX += point.x; countY += point.y; countZ += point.z; } return new Point(countX/hull.Count,countY/hull.Count,countZ/hull.Count); } public List<Point> getFingers(List<Point> hull, Point hand, Point palm, Point elbow) { //remove other points int cY = hand.y - elbow.y; int cX = hand.x - elbow.x; float grad = 1/(float) (cY)/(float) (cX); Point other = new Point(palm.x+100, (int)(palm.y+(100*grad)),palm.z); for(int i=0;i<hull.Count;i++) { if (PointComparator.isLeftExcl(palm, other, hull[i])) hull.RemoveAt(i--); } for (int i = 0; i < hull.Count;i++) { Point current = hull[i]; for(int j=i+1;j<hull.Count;j++) { Point compare = hull[j]; if (current.x - compare.x < 5 && current.x - compare.x > 5) { if (current.y - compare.y < 5 && current.y - compare.y > 5) { hull.RemoveAt(j--); } } } } return hull; } public List<List<Point>> GetHands(List<List<Point>> points, Point rightHand, Point leftHand) { List<List<Point>> hands = new List<List<Point>>(); foreach (List<Point> lPoints in points) { if(ContainsPoint(lPoints,rightHand) || ContainsPoint(lPoints,leftHand)) { hands.Add(lPoints); } } return hands; } */ public bool ContainsPoint(List<Point> points, Point point) { foreach (Point p in points) { if (p.x==point.x && p.y==point.y) return true; } return false; }
public static List<Point> RemovePoint(List<Point> _points, Point p) { List<Point> points = new List<Point>(); for (int i = 0; i < _points.Count(); i++) { if (!_points[i].Equals(p)) points.Add(_points[i]); //point is not the one we what to remove, so add it to the new list } return points; }
public void comparatorTest() { List<Point> points = new List<Point>(); Point start = new Point(1,1,1); points.Add(new Point(-1, 3, 1)); points.Add(new Point(3,3,1)); points.Add(new Point(2,2,1)); points.Add(new Point(2,4,1)); PointComparator pc = new PointComparator(start); points.Sort(pc.Compare); Assert.AreEqual(new Point(2, 2, 1), points[0]); Assert.AreEqual(new Point(3, 3, 1), points[1]); Assert.AreEqual(new Point(2, 4, 1), points[2]); Assert.AreEqual(new Point(-1,3,1), points[3]); }
public void HullSquareAdvanTest() { List<Point> points = new List<Point>(); Point start = new Point(1, 1, 1); points.Add(start); points.Add(new Point(20, 1, 1)); points.Add(new Point(1, 20, 1)); points.Add(new Point(20, 20, 1)); points.Add(new Point(10, 15, 1)); //not on hull points.Add(new Point(15, 10, 1)); //not on hull Assert.AreEqual(4, GrahamScan.Scan(points).Count); }