-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectTools.cpp
46 lines (37 loc) · 1.12 KB
/
VectTools.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "VectTools.h"
float VectTools::dot(const sf::Vector2f& l, const sf::Vector2f& r)
{
return l.x * r.x + l.y * r.y;
}
float VectTools::sqrMagnitude(const sf::Vector2f& vect)
{
return vect.x * vect.x + vect.y * vect.y;
}
float VectTools::magnitude(const sf::Vector2f& vect)
{
return std::sqrt(VectTools::sqrMagnitude(vect));
}
sf::Vector2f VectTools::leftNormal(const sf::Vector2f& vect)
{
return sf::Vector2f(-vect.y,vect.x);
}
sf::Vector2f VectTools::rightNormal(const sf::Vector2f& vect)
{
return sf::Vector2f(vect.y,-vect.x);
}
sf::Vector2f VectTools::normalize(const sf::Vector2f& vect)
{
return vect / VectTools::magnitude(vect);
}
float VectTools::cosAngle(const sf::Vector2f& first, const sf::Vector2f& second)
{
return VectTools::dot(first,second)/std::sqrt(VectTools::sqrMagnitude(first)*VectTools::sqrMagnitude(second));
}
float VectTools::angleDeg(const sf::Vector2f& first, const sf::Vector2f& second)
{
return VectTools::angleRad(first, second) * 180.f / VectTools::PI;
}
float VectTools::angleRad(const sf::Vector2f& first, const sf::Vector2f& second)
{
return std::acos(VectTools::cosAngle(first, second));
}