Functions
VectorAlgebra2D.hpp File Reference

Algebraic operations on two-dimensional vectors (dot product, vector length and angles, ...) More...

Go to the source code of this file.

Functions

template<typename T >
thor::length (const sf::Vector2< T > &vector)
 Returns the length of the 2D vector.
 
template<typename T >
thor::squaredLength (const sf::Vector2< T > &vector)
 Returns the square of vector's length. More...
 
template<typename T >
void thor::setLength (sf::Vector2< T > &vector, T newLength)
 Adapts vector so that its length is |newLength| after this operation. More...
 
template<typename T >
sf::Vector2< T > thor::unitVector (const sf::Vector2< T > &vector)
 Returns a vector with same direction as the argument, but with length 1. More...
 
template<typename T >
thor::polarAngle (const sf::Vector2< T > &vector)
 Returns the polar angle. More...
 
template<typename T >
void thor::setPolarAngle (sf::Vector2< T > &vector, T newAngle)
 Sets the polar angle of the specified vector. More...
 
template<typename T >
void thor::rotate (sf::Vector2< T > &vector, T angle)
 Rotates the vector by the given angle (in degrees). More...
 
template<typename T >
sf::Vector2< T > thor::rotatedVector (const sf::Vector2< T > &vector, T angle)
 Returns a copy of the vector, rotated by angle degrees. More...
 
template<typename T >
sf::Vector2< T > thor::perpendicularVector (const sf::Vector2< T > &vector)
 Returns a perpendicular vector. More...
 
template<typename T >
thor::signedAngle (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Computes the signed angle from lhs to rhs. More...
 
template<typename T >
thor::dotProduct (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Computes the dot product of two 2D vectors.
 
template<typename T >
thor::crossProduct (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Computes the cross product of two 2D vectors (Z component only). More...
 
template<typename T >
sf::Vector2< T > thor::cwiseProduct (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Returns the component-wise product of lhs and rhs. More...
 
template<typename T >
sf::Vector2< T > thor::cwiseQuotient (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Returns the component-wise quotient of lhs and rhs. More...
 
template<typename T >
sf::Vector2< T > thor::projectedVector (const sf::Vector2< T > &vector, const sf::Vector2< T > &axis)
 Returns the projection of vector onto axis. More...
 

Detailed Description

Algebraic operations on two-dimensional vectors (dot product, vector length and angles, ...)

Here is an overview over the functionality:

Operation Translation Scale Rotation
Get v length(v) polarAngle(v)
Set, absolute v = w setLength(v,l) setPolarAngle(v,a)
Set, relative v += w v *= l rotate(v,a)
Copy, relative v + w v * l rotatedVector(v,a)

Other functions:

dotProduct(v,w) unitVector(v) squaredLength(v)
crossProduct(v,w) perpendicularVector(v) signedAngle(v,w)
cwiseProduct(v,w) cwiseQuotient(v,w) projectedVector(v,w)