Пример #1
0
Vec2D Vec2D::projection(Vec2D const& other) const
{
  Vec2D direction = other.unit();
  return direction.scalei(dot(direction));
}
Пример #2
0
// n.projection(m) = m, m.reverseProjection(n.unit()) = n
Vec2D Vec2D::reverseProjection(const Vec2D &other) const
{
  Vec2D nu = other.unit();
  float l = length();
  return nu.scalei(l / nu.dot(scale(1.0f/l)));
}