Bromeon
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.
template<typename T >
void thor::SetLength (sf::Vector2< T > &vector, T newLength)
 Adapts vector so that its length is |newLength| after this operation.
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.
template<typename T >
thor::PolarAngle (const sf::Vector2< T > &vector)
 Returns the polar angle.
template<typename T >
void thor::SetPolarAngle (sf::Vector2< T > &vector, T newAngle)
 Sets the polar angle of the specified vector.
template<typename T >
void thor::Rotate (sf::Vector2< T > &vector, T angle)
 Rotates the vector by the given angle (in degrees).
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.
template<typename T >
sf::Vector2< T > thor::PerpendicularVector (const sf::Vector2< T > &vector)
 Returns a perpendicular vector.
template<typename T >
thor::Angle (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Computes the signed angle from lhs to rhs.
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 >
sf::Vector3< T > thor::CrossProduct (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Computes the cross product of two 2D vectors.
template<typename T >
sf::Vector2< T > thor::ComponentwiseProduct (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Returns the component-wise product of lhs and rhs.
template<typename T >
sf::Vector2< T > thor::ComponentwiseQuotient (const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
 Returns the component-wise quotient of lhs and rhs.
template<typename DestType , typename SourceType >
sf::Vector2< DestType > thor::ConvertVector (const sf::Vector2< SourceType > &vector)
 Converts vectors of different types.
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.
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.
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.
template<typename T >
thor::ElevationAngle (const sf::Vector3< T > &vector)
 Returns the elevation angle of vector.
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::ComponentwiseProduct (const sf::Vector3< T > &lhs, const sf::Vector3< T > &rhs)
 Returns the component-wise product of lhs and rhs.
template<typename T >
sf::Vector3< T > thor::ComponentwiseQuotient (const sf::Vector3< T > &lhs, const sf::Vector3< T > &rhs)
 Returns the component-wise quotient of lhs and rhs.
template<typename DestType , typename SourceType >
sf::Vector3< DestType > thor::ConvertVector (const sf::Vector3< SourceType > &vector)
 Converts vectors of different types.
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 >
thor::Length (const PolarVector2< T > &vector)
 Returns the length of a polar vector.
template<typename T >
thor::PolarAngle (const PolarVector2< T > &vector)
 Returns the angle of a polar vector in degrees.

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::Angle ( 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 >
sf::Vector3<T> thor::ComponentwiseProduct ( 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::ComponentwiseProduct ( 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::ComponentwiseQuotient ( 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::ComponentwiseQuotient ( 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 DestType , typename SourceType >
sf::Vector3<DestType> thor::ConvertVector ( const sf::Vector3< SourceType > &  vector)

Converts vectors of different types.

For a given vector, static_cast<DestType> is applied to every coordinate.

template<typename DestType , typename SourceType >
sf::Vector2<DestType> thor::ConvertVector ( const sf::Vector2< SourceType > &  vector)

Converts vectors of different types.

For a given vector, static_cast<DestType> is applied to every coordinate.

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

Computes the cross product of two 2D vectors.

The behavior is equivalent to the crossproduct of two 3D vectors with the Z component being zero. The result's X and Y components are always 0.

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 >
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::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.