Finger.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace bbiwarg
  8. {
  9. class Finger
  10. {
  11. private List<Point> fingerPoints;
  12. public Finger(Point fingerPoint) {
  13. fingerPoints = new List<Point>();
  14. fingerPoints.Add(fingerPoint);
  15. }
  16. public float getMinDistance(Point fingerPoint) {
  17. float minDinstance = float.MaxValue;
  18. foreach(Point fp in fingerPoints) {
  19. int xDiff = fp.X-fingerPoint.X;
  20. int yDiff = fp.Y-fingerPoint.Y;
  21. float distance = (float)Math.Sqrt(xDiff*xDiff + yDiff*yDiff);
  22. if(distance < minDinstance) {
  23. minDinstance = distance;
  24. }
  25. }
  26. return minDinstance;
  27. }
  28. public void add(Point fingerPoint) {
  29. fingerPoints.Add(fingerPoint);
  30. }
  31. public float getLength() {
  32. int minX = int.MaxValue;
  33. int maxX = int.MinValue;
  34. int minY = int.MaxValue;
  35. int maxY = int.MinValue;
  36. foreach (Point fingerPoint in fingerPoints) {
  37. if (fingerPoint.X < minX) minX = fingerPoint.X;
  38. if (fingerPoint.X > maxX) maxX = fingerPoint.X;
  39. if (fingerPoint.Y < minY) minY = fingerPoint.Y;
  40. if (fingerPoint.Y > maxY) maxY = fingerPoint.Y;
  41. }
  42. int xDiff = maxX-minX;
  43. int yDiff = maxY-minY;
  44. return (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
  45. }
  46. public int getNumPoints()
  47. {
  48. return fingerPoints.Count;
  49. }
  50. public Point getNearest(DepthImage image)
  51. {
  52. Point nearest = new Point(0, 0);
  53. Int16 minDepth = Int16.MaxValue;
  54. foreach (Point p in fingerPoints)
  55. {
  56. Int16 d = image.getDepthAt(p.X, p.Y);
  57. if (d < minDepth) {
  58. minDepth = d;
  59. nearest = p;
  60. }
  61. }
  62. return nearest;
  63. }
  64. public Point getFarthest(DepthImage image)
  65. {
  66. Point farthest = new Point(0, 0);
  67. Int16 maxDepth = 0;
  68. foreach (Point p in fingerPoints)
  69. {
  70. Int16 d = image.getDepthAt(p.X, p.Y);
  71. if (d > maxDepth)
  72. {
  73. maxDepth = d;
  74. farthest = p;
  75. }
  76. }
  77. return farthest;
  78. }
  79. public List<Point> getFingerPoints() {
  80. return fingerPoints;
  81. }
  82. }
  83. }