VectorAlgebra2D.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
42 
43 #ifndef THOR_VECTORALGEBRA2D_HPP
44 #define THOR_VECTORALGEBRA2D_HPP
45 
47 
48 #include <SFML/System/Vector2.hpp>
49 
50 #include <cassert>
51 
52 
53 namespace thor
54 {
55 
58 
61 template <typename T>
62 T length(const sf::Vector2<T>& vector);
63 
66 template <typename T>
67 T squaredLength(const sf::Vector2<T>& vector);
68 
72 template <typename T>
73 void setLength(sf::Vector2<T>& vector, T newLength);
74 
77 template <typename T>
78 sf::Vector2<T> unitVector(const sf::Vector2<T>& vector);
79 
84 template <typename T>
85 T polarAngle(const sf::Vector2<T>& vector);
86 
89 template <typename T>
90 void setPolarAngle(sf::Vector2<T>& vector, T newAngle);
91 
94 template <typename T>
95 void rotate(sf::Vector2<T>& vector, T angle);
96 
99 template <typename T>
100 sf::Vector2<T> rotatedVector(const sf::Vector2<T>& vector, T angle);
101 
105 template <typename T>
106 sf::Vector2<T> perpendicularVector(const sf::Vector2<T>& vector);
107 
108 // ---------------------------------------------------------------------------------------------------------------------------
109 
110 
115 template <typename T>
116 T signedAngle(const sf::Vector2<T>& lhs, const sf::Vector2<T>& rhs);
117 
120 template <typename T>
121 T dotProduct(const sf::Vector2<T>& lhs, const sf::Vector2<T>& rhs);
122 
126 template <typename T>
127 T crossProduct(const sf::Vector2<T>& lhs, const sf::Vector2<T>& rhs);
128 
131 template <typename T>
132 sf::Vector2<T> cwiseProduct(const sf::Vector2<T>& lhs, const sf::Vector2<T>& rhs);
133 
137 template <typename T>
138 sf::Vector2<T> cwiseQuotient(const sf::Vector2<T>& lhs, const sf::Vector2<T>& rhs);
139 
143 template <typename T>
144 sf::Vector2<T> projectedVector(const sf::Vector2<T>& vector, const sf::Vector2<T>& axis);
145 
147 
148 } // namespace thor
149 
150 #include <Thor/Vectors/Detail/VectorAlgebra2D.inl>
151 #endif // THOR_VECTORALGEBRA2D_HPP
T polarAngle(const sf::Vector2< T > &vector)
Returns the polar angle.
T dotProduct(const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
Computes the dot product of two 2D vectors.
void setLength(sf::Vector2< T > &vector, T newLength)
Adapts vector so that its length is |newLength| after this operation.
sf::Vector2< T > rotatedVector(const sf::Vector2< T > &vector, T angle)
Returns a copy of the vector, rotated by angle degrees.
void rotate(sf::Vector2< T > &vector, T angle)
Rotates the vector by the given angle (in degrees).
Definition: AnimationMap.hpp:42
void setPolarAngle(sf::Vector2< T > &vector, T newAngle)
Sets the polar angle of the specified vector.
Class template thor::TrigonometricTraits and some trigonometry-related functions and constants...
T squaredLength(const sf::Vector2< T > &vector)
Returns the square of vector's length.
sf::Vector2< T > perpendicularVector(const sf::Vector2< T > &vector)
Returns a perpendicular vector.
T signedAngle(const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
Computes the signed angle from lhs to rhs.
sf::Vector2< T > cwiseProduct(const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
Returns the component-wise product of lhs and rhs.
sf::Vector2< T > cwiseQuotient(const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
Returns the component-wise quotient of lhs and rhs.
T length(const sf::Vector2< T > &vector)
Returns the length of the 2D vector.
sf::Vector2< T > projectedVector(const sf::Vector2< T > &vector, const sf::Vector2< T > &axis)
Returns the projection of vector onto axis.
sf::Vector2< T > unitVector(const sf::Vector2< T > &vector)
Returns a vector with same direction as the argument, but with length 1.
T crossProduct(const sf::Vector2< T > &lhs, const sf::Vector2< T > &rhs)
Computes the cross product of two 2D vectors (Z component only).