1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace bbiwarg
- {
- class Finger
- {
- private List<Point> fingerPoints;
- public Finger(Point fingerPoint) {
- fingerPoints = new List<Point>();
- fingerPoints.Add(fingerPoint);
- }
- public float getMinDistance(Point fingerPoint) {
- float minDinstance = float.MaxValue;
- foreach(Point fp in fingerPoints) {
- int xDiff = fp.X-fingerPoint.X;
- int yDiff = fp.Y-fingerPoint.Y;
- float distance = (float)Math.Sqrt(xDiff*xDiff + yDiff*yDiff);
- if(distance < minDinstance) {
- minDinstance = distance;
- }
- }
- return minDinstance;
- }
- public void add(Point fingerPoint) {
- fingerPoints.Add(fingerPoint);
- }
- public float getLength() {
- int minX = int.MaxValue;
- int maxX = int.MinValue;
- int minY = int.MaxValue;
- int maxY = int.MinValue;
- foreach (Point fingerPoint in fingerPoints) {
- if (fingerPoint.X < minX) minX = fingerPoint.X;
- if (fingerPoint.X > maxX) maxX = fingerPoint.X;
- if (fingerPoint.Y < minY) minY = fingerPoint.Y;
- if (fingerPoint.Y > maxY) maxY = fingerPoint.Y;
- }
- int xDiff = maxX-minX;
- int yDiff = maxY-minY;
- return (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
- }
- public int getNumPoints()
- {
- return fingerPoints.Count;
- }
- public Point getNearest(DepthImage image)
- {
- Point nearest = new Point(0, 0);
- Int16 minDepth = Int16.MaxValue;
- foreach (Point p in fingerPoints)
- {
- Int16 d = image.getDepthAt(p.X, p.Y);
- if (d < minDepth) {
- minDepth = d;
- nearest = p;
- }
- }
- return nearest;
- }
- public Point getFarthest(DepthImage image)
- {
- Point farthest = new Point(0, 0);
- Int16 maxDepth = 0;
- foreach (Point p in fingerPoints)
- {
- Int16 d = image.getDepthAt(p.X, p.Y);
- if (d > maxDepth)
- {
- maxDepth = d;
- farthest = p;
- }
- }
- return farthest;
- }
- public List<Point> getFingerPoints() {
- return fingerPoints;
- }
- }
- }
|