Classes | Typedefs | Functions
Vectors

A lot of operations based on sf::Vector2 and sf::Vector3. For specific overview, see VectorAlgebra2D.hpp and VectorAlgebra3D.hpp. More...

Classes

struct  thor::PolarVector2< T >
 Vector in polar coordinate system. More...
 

Typedefs

typedef PolarVector2< float > thor::PolarVector2f
 Type definition for float polar vectors.
 

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...
 
template<typename T >
thor::length (const sf::Vector3< T > &vector)
 Returns the length of the 3D vector.
 
template<typename T >
thor::squaredLength (const sf::Vector3< T > &vector)
 Returns the square of vector's length. More...
 
template<typename T >
sf::Vector3< T > thor::unitVector (const sf::Vector3< T > &vector)
 Returns a vector with same direction as the argument, but with length 1. More...
 
template<typename T >
thor::polarAngle (const sf::Vector3< T > &vector)
 Returns the angle between the projection of vector onto the XY-plane and the X-axis. More...
 
template<typename T >
thor::elevationAngle (const sf::Vector3< T > &vector)
 Returns the elevation angle of vector. More...
 
template<typename T >
thor::dotProduct (const sf::Vector3< T > &lhs, const sf::Vector3< T > &rhs)
 Computes the dot product of two 3D vectors.
 
template<typename T >
sf::Vector3< T > thor::crossProduct (const sf::Vector3< T > &lhs, const sf::Vector3< T > &rhs)
 Computes the cross product of two 3D vectors.
 
template<typename T >
sf::Vector3< T > thor::cwiseProduct (const sf::Vector3< T > &lhs, const sf::Vector3< T > &rhs)
 Returns the component-wise product of lhs and rhs. More...
 
template<typename T >
sf::Vector3< T > thor::cwiseQuotient (const sf::Vector3< T > &lhs, const sf::Vector3< T > &rhs)
 Returns the component-wise quotient of lhs and rhs. More...
 
template<typename T >
sf::Vector3< T > thor::toVector3 (const sf::Vector2< T > &vector2)
 Constructs a 3D vector from a 2D vector by setting the Z component to zero.
 
template<typename T >
length (const PolarVector2< T > &vector)
 Returns the length of a polar vector. More...
 
template<typename T >
polarAngle (const PolarVector2< T > &vector)
 Returns the angle of a polar vector in degrees. More...
 

Detailed Description

A lot of operations based on sf::Vector2 and sf::Vector3. For specific overview, see VectorAlgebra2D.hpp and VectorAlgebra3D.hpp.

Function Documentation

template<typename T >
T thor::crossProduct ( const sf::Vector2< T > &  lhs,
const sf::Vector2< T > &  rhs 
)

Computes the cross product of two 2D vectors (Z component only).

Treats the operands as 3D vectors, computes their cross product and returns the result's Z component (X and Y components are always zero).

template<typename T >
sf::Vector3<T> thor::cwiseProduct ( const sf::Vector3< T > &  lhs,
const sf::Vector3< T > &  rhs 
)

Returns the component-wise product of lhs and rhs.

Computes (lhs.x*rhs.x, lhs.y*rhs.y, lhs.z*rhs.z). Component-wise multiplications are mainly used for scales.

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.

Computes (lhs.x*rhs.x, lhs.y*rhs.y). Component-wise multiplications are mainly used for scales.

template<typename T >
sf::Vector3<T> thor::cwiseQuotient ( const sf::Vector3< T > &  lhs,
const sf::Vector3< T > &  rhs 
)

Returns the component-wise quotient of lhs and rhs.

Computes (lhs.x/rhs.x, lhs.y/rhs.y, lhs.z/rhs.z). Component-wise divisions are mainly used for scales.

Precondition
Neither component of rhs is zero.
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.

Computes (lhs.x/rhs.x, lhs.y/rhs.y). Component-wise divisions are mainly used for scales.

Precondition
Neither component of rhs is zero.
template<typename T >
T thor::elevationAngle ( const sf::Vector3< T > &  vector)

Returns the elevation angle of vector.

The elevation angle is the angle between the vector and the XY-plane. It has the same sign as vector.z.

Returns
Elevation angle in degrees in the interval [-90,90].
Precondition
vector is no zero vector.
template<typename T >
T length ( const PolarVector2< T > &  vector)
related

Returns the length of a polar vector.

The returned value is vector.r.

template<typename T >
sf::Vector2<T> thor::perpendicularVector ( const sf::Vector2< T > &  vector)

Returns a perpendicular vector.

Returns vector turned by 90 degrees counter clockwise; (x,y) becomes (-y,x). For example, the vector (1,0) is transformed to (0,1).

template<typename T >
T thor::polarAngle ( const sf::Vector3< T > &  vector)

Returns the angle between the projection of vector onto the XY-plane and the X-axis.

Example: The vector (1,0,z) corresponds 0 degrees, (0,1,z) corresponds 90 degrees, where z is arbitrary.

Returns
Angle in degrees in the interval [-180,180].
Precondition
vector is no zero vector.
template<typename T >
T polarAngle ( const PolarVector2< T > &  vector)
related

Returns the angle of a polar vector in degrees.

The returned value is vector.phi.

template<typename T >
T thor::polarAngle ( const sf::Vector2< T > &  vector)

Returns the polar angle.

The vector (1,0) corresponds 0 degrees, (0,1) corresponds 90 degrees.

Returns
Angle in degrees in the interval [-180,180].
Precondition
vector is no zero vector.
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.

Parameters
vectorVector to project onto another.
axisVector being projected onto. Need not be a unit vector, but may not have length zero.
template<typename T >
void thor::rotate ( sf::Vector2< T > &  vector,
angle 
)

Rotates the vector by the given angle (in degrees).

The vector (1,0) corresponds 0 degrees, (0,1) corresponds 90 degrees.

template<typename T >
sf::Vector2<T> thor::rotatedVector ( const sf::Vector2< T > &  vector,
angle 
)

Returns a copy of the vector, rotated by angle degrees.

The vector (1,0) corresponds 0 degrees, (0,1) corresponds 90 degrees.

template<typename T >
void thor::setLength ( sf::Vector2< T > &  vector,
newLength 
)

Adapts vector so that its length is |newLength| after this operation.

If newLength is less than zero, the vector's direction changes.

Precondition
vector is no zero vector.
template<typename T >
void thor::setPolarAngle ( sf::Vector2< T > &  vector,
newAngle 
)

Sets the polar angle of the specified vector.

The vector (1,0) corresponds 0 degrees, (0,1) corresponds 90 degrees.

template<typename T >
T thor::signedAngle ( const sf::Vector2< T > &  lhs,
const sf::Vector2< T > &  rhs 
)

Computes the signed angle from lhs to rhs.

Returns
Angle in degrees in the interval [-180,180]. The angle determines how much you have to turn lhs until it points to the same direction as rhs.
Precondition
Neither lhs nor rhs is a zero vector.
template<typename T >
T thor::squaredLength ( const sf::Vector3< T > &  vector)

Returns the square of vector's length.

Suitable for comparisons, more efficient than length().

template<typename T >
T thor::squaredLength ( const sf::Vector2< T > &  vector)

Returns the square of vector's length.

Suitable for comparisons, more efficient than length().

template<typename T >
sf::Vector3<T> thor::unitVector ( const sf::Vector3< T > &  vector)

Returns a vector with same direction as the argument, but with length 1.

Precondition
vector is no zero vector.
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.

Precondition
vector is no zero vector.