summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank v/d Haterd <f.h.a.v.d.haterd@student.tue.nl>2013-12-18 15:39:06 +0100
committerFrank v/d Haterd <f.h.a.v.d.haterd@student.tue.nl>2013-12-18 15:39:06 +0100
commit6a58fcca7e517714fd53543f194944d920867e2e (patch)
treed8150a4e7c60dc17fdd00c28222d9f86248e8a25
parente8ce8290c80aee69d38947b9074c75a814305f04 (diff)
download2iv60-robots-6a58fcca7e517714fd53543f194944d920867e2e.tar.gz
getTangent 2.1 finished
-rw-r--r--src/RaceTrack.java33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/RaceTrack.java b/src/RaceTrack.java
index 26119ab..c973fb5 100644
--- a/src/RaceTrack.java
+++ b/src/RaceTrack.java
@@ -6,6 +6,8 @@ import static java.lang.Math.*;
* Implementation of a race track that is made from Bezier segments.
*/
class RaceTrack {
+ protected static final int ellipse_a = 10;
+ protected static final int ellipse_b = 14;
/**
* Array with control points for the O-track.
@@ -32,6 +34,8 @@ class RaceTrack {
*/
public RaceTrack() {
// code goes here ...
+
+
}
/**
@@ -57,8 +61,8 @@ class RaceTrack {
* Returns the position of the curve at 0 <= {@code t} <= 1.
*/
public Vector getPoint(double t) {
- return new Vector(10 * cos(2 * PI * t),
- 14 * sin(2 * PI * t),
+ return new Vector(ellipse_a * cos(2 * PI * t),
+ ellipse_b * sin(2 * PI * t),
1);
}
@@ -66,9 +70,26 @@ class RaceTrack {
* Returns the tangent of the curve at 0 <= {@code t} <= 1.
*/
public Vector getTangent(double t) {
- // robot looks forward
- return new Vector(0,
- 1,
- 1);
+ /*
+ * Given a vector (-Y/B^2, X/A^2, 0) where X and Y are the coordinates
+ * of the point p on the ellipse. A is the HALFWIDTH of the ellipse and
+ * B is the HALFHEIGHT of the ellipse.
+ *
+ * Vector (X/A^2, Y/B^2, 0) is the normal vector through point p
+ * and the center of the ellipse. Because the X and Y coordinates
+ * are divided by the width and height of the ellipse, everything is
+ * "normalized" to a circle. Hence a line through the origin and a point
+ * p describes a normal vector for a point p on the ellipse.
+ *
+ * Since the dot product of the latter vector and the first (tangent)
+ * vector results in zero, we can say the normal vector is perpendicular
+ * to the tangent vector. And because of that, the first vector
+ * describes the tangent vector of point p.
+ */
+ Vector p = getPoint(t);
+
+ return new Vector(-p.y()/(ellipse_a * ellipse_a),
+ p.x()/(ellipse_b * ellipse_b),
+ 0).normalized();
}
}