summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6b88a31)
raw | patch | inline | side by side (parent: 6b88a31)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Wed, 18 Jun 2008 23:31:50 +0000 (23:31 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Wed, 18 Jun 2008 23:31:50 +0000 (23:31 +0000) |
src/2geom/curve.h | patch | blob | history | |
src/2geom/transforms.cpp | patch | blob | history | |
src/2geom/transforms.h | patch | blob | history |
diff --git a/src/2geom/curve.h b/src/2geom/curve.h
index 7f138dabf92653c5f6a838435ad69f8ecd8d4b44..22d2ec55609cc4194b8374a1b0b10388419a4ba2 100644 (file)
--- a/src/2geom/curve.h
+++ b/src/2geom/curve.h
* [ point at t, 1st derivative at t, 2nd derivative at t, ... , n'th derivative at t] */
virtual std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const = 0;
+ /* unitTangentAt returns the unit vector tangent to the curve at position t
+ * (in the direction of increasing t). The method uses l'Hopital's rule when the derivative
+ * is (0,0), parameter n determines the maximum nr of iterations (for when higher derivatives are also (0,0) ).
+ * Point(0,0) is returned if no non-zero derivative could be found. */
+ virtual Point unitTangentAt(Coord t, unsigned n = 3) const
+ {
+ for (unsigned deriv_n = 1; deriv_n <= n; deriv_n++) {
+ Point deriv = pointAndDerivatives(t, deriv_n)[deriv_n];
+ Coord length = deriv.length();
+ if ( ! are_near(length, 0) ) {
+ // length of derivative is non-zero, so return unit vector
+ return deriv / length;
+ }
+ }
+ return Point (0,0);
+ };
+
virtual D2<SBasis> toSBasis() const = 0;
};
index b2f305d1856f7c07961bdc725e88158852cfee85..62b340221f5072f37f012448e411f9662128b416 100644 (file)
--- a/src/2geom/transforms.cpp
+++ b/src/2geom/transforms.cpp
}
Matrix operator*(Matrix const &m, Rotate const &r) {
+ // TODO: we just convert the Rotate to a matrix and use the existing operator*(); is there a better way?
Matrix ret(m);
ret *= (Matrix) r;
return ret;
diff --git a/src/2geom/transforms.h b/src/2geom/transforms.h
index 0e276bfc2aa21479f6226f045dee264461c6e16e..fb077a910316256d2313e337185ca070ba1782a7 100644 (file)
--- a/src/2geom/transforms.h
+++ b/src/2geom/transforms.h
explicit Rotate(Coord theta) : vec(std::cos(theta), std::sin(theta)) {}
Rotate(Point const &p) {Point v = p; v.normalize(); vec = v;} //TODO: UGLY!
explicit Rotate(Coord x, Coord y) { Rotate(Point(x, y)); }
- inline operator Matrix() const { return Matrix(vec[X], -vec[Y], vec[Y], vec[X], 0, 0); }
+ inline operator Matrix() const { return Matrix(vec[X], vec[Y], -vec[Y], vec[X], 0, 0); }
inline Coord operator[](Dim2 const dim) const { return vec[dim]; }
inline Coord operator[](unsigned const dim) const { return vec[dim]; }