1 /*
2 * @(#)$Id: F1.java 689 2009-07-22 00:10:27Z bsigner $
3 *
4 * Author : Ueli Kurmann, igesture@uelikurmann.ch
5 *
6 * Purpose : Rubine feature F1. Cosine of the initial angle of the
7 * gesture.
8 *
9 * -----------------------------------------------------------------------
10 *
11 * Revision Information:
12 *
13 * Date Who Reason
14 *
15 * Dec 26, 2006 ukurmann Initial Release
16 * Mar 15, 2007 bsigner Cleanup
17 *
18 * -----------------------------------------------------------------------
19 *
20 * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21 *
22 * This software is the proprietary information of ETH Zurich.
23 * Use is subject to license terms.
24 *
25 */
26
27
28 package org.ximtec.igesture.algorithm.feature;
29
30 import org.sigtec.ink.Note;
31 import org.sigtec.ink.Point;
32 import org.sigtec.ink.Trace;
33
34
35 /**
36 * Rubine feature F1. Cosine of the initial angle of the gesture.
37 *
38 * @version 1.0 Dec 2006
39 * @author Ueli Kurmann, igesture@uelikurmann.ch
40 * @author Beat Signer, signer@inf.ethz.ch
41 */
42 public class F1 implements Feature {
43
44 private static final int MINIMAL_NUMBER_OF_POINTS = 5;
45
46
47 /* (non-Javadoc)
48 * @see org.ximtec.igesture.algorithm.feature.Feature#compute(org.sigtec.ink.Note)
49 */
50 public double compute(Note note) throws FeatureException {
51 if (note.getPoints().size() < MINIMAL_NUMBER_OF_POINTS) {
52 throw new FeatureException(FeatureException.NOT_ENOUGH_POINTS);
53 }
54
55 final Trace trace = FeatureTool.createTrace(note);
56 final Point p0 = trace.get(0);
57 Point p2 = trace.get(2);
58
59 if (p0.getX() == p2.getX() && p0.getY() == p2.getY()) {
60 p2 = trace.get(4);
61 }
62
63 return (p2.getX() - p0.getX())
64 / (Math.sqrt(Math.pow(p2.getX() - p0.getX(), 2)
65 + Math.pow(p2.getY() - p0.getY(), 2)));
66 } // compute
67
68
69 public int getMinimalNumberOfPoints() {
70 return MINIMAL_NUMBER_OF_POINTS;
71 } // getMinimalNumberOfPoints
72
73 }