diff options
author | Peter Wu <lekensteyn@gmail.com> | 2014-01-17 15:36:28 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2014-01-17 15:36:28 +0100 |
commit | 499778373f172dad7b2d0a3eabf335283ae1e274 (patch) | |
tree | 0f84bdf3e6a4698a114ff71e0ca3db9f17c93c41 | |
parent | fd58d9209acbd32489608151924edc32d9dd8697 (diff) | |
download | 2iv60-robots-499778373f172dad7b2d0a3eabf335283ae1e274.tar.gz |
Fix broken tangent calculation of ellipse
-rw-r--r-- | src/RaceTrack.java | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/src/RaceTrack.java b/src/RaceTrack.java index 5c5b842..81fdc99 100644 --- a/src/RaceTrack.java +++ b/src/RaceTrack.java @@ -181,25 +181,11 @@ class RaceTrack extends BetterBase { return getCubicBezierTng(u, selectedControlPoints, bezier_start_i); } - /* - * 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), + // tangent is derivative of ellipse: + // d / dt (A cos(t)) / (B sin(t)) = (-A sin(t)) / (B cos(t)) + return new Vector(-ELLIPSE_A * sin(2 * PI * t), + ELLIPSE_B * cos(2 * PI * t), 0).normalized(); } |