#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GEOMETRY_LINES_CURVE1_H #define NUCLEX_GEOMETRY_LINES_CURVE1_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Math.h" namespace Nuclex { namespace Geometry { namespace Lines { // ------------------------------------------------------------------------------------------- // /// Cubic bezier curve on one axis template struct Curve1 { /// Initializes the cubic bezier curve using the specified coordinates /// Point at which the cubic bezier curve begins /// Point giving direction and magnitude at the curve start /// Point giving direction and magnitude at the curve end /// Point at which the cubic bezier curve ends public: Curve1(TScalar p0, TScalar p1, TScalar p2, TScalar p3) : P0(p0), P1(p1), P2(p2), P3(p3) {} /// Offsets the entire curve by the specified amount /// Amount the curve will be offset public: void ShiftBy(TScalar offset) { this.P0 += offset; this.P1 += offset; this.P2 += offset; this.P3 += offset; } /// Interpolates a point along the bezier curve /// Time (0.0 .. 1.0) at which the point will be interpolated /// The point at the specified time public: TScalar Interpolate(TScalar t) const { return Math::Power(1 - t, 3) * this->P0 + 3 * Math::Power(1 - t, 2) * t * this->P1 + 3 * (1 - t) * Math::Power(t, 2) * this->P2 + Math::Power(t, 3) * this->P3; } /// Position of the curve's starting point public: TScalar P0; /// Position towards which the curve's starting point extends public: TScalar P1; /// Position from which the curve enters its ending point public: TScalar P2; /// Position at which the curve ends public: TScalar P3; /* /// The polyline's vertices public: std::vector< Point2 > Vertices; */ }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Lines #endif // NUCLEX_GEOMETRY_LINES_CURVE1_H