-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector2d.h
68 lines (52 loc) · 2 KB
/
Vector2d.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include <cfloat>
#include <climits>
#include <cmath>
/*The Vector2d class is an object consisting of simply an x and
y value. Certain operators are overloaded to make it easier
for vector math to be performed.*/
class Vector2d {
public:
/*The x and y values are public to give easier access for
outside funtions. Accessors and mutators are not really
necessary*/
float x;
float y;
//Constructor assigns the inputs to x and y.
Vector2d();
Vector2d(float, float);
/*The following operators simply return Vector2ds that
have operations performed on the relative (x, y) values*/
Vector2d operator+(const Vector2d&) const;
Vector2d operator-(const Vector2d&) const;
Vector2d operator*(const Vector2d&) const;
Vector2d operator/(const Vector2d&) const;
//Check if the Vectors have the same values.
bool operator==(const Vector2d&) const;
/*Check which Vectors are closer or further from the
origin.*/
bool operator>(const Vector2d&) const;
bool operator<(const Vector2d&) const;
bool operator>=(const Vector2d&) const;
bool operator<=(const Vector2d&) const;
//Negate both the x and y values.
Vector2d operator-() const;
//Apply scalar operations.
Vector2d operator*(const float&) const;
Vector2d operator/(const float&) const;
//Product functions
static float DotProduct(const Vector2d&, const Vector2d&);
static float CrossProduct(const Vector2d&, const Vector2d&);
//Returns the length of the vector from the origin.
static float Magnitude(const Vector2d&);
//Returns the angle of direction of the vector.
float direction();
//Return the unit vector of the input.
static Vector2d Normal(const Vector2d&);
//Return a vector perpendicular to the left.
static Vector2d Perpendicular(const Vector2d&);
//Return true if two line segments intersect.
static bool Intersect(const Vector2d&, const Vector2d&, const Vector2d&, const Vector2d&);
//Return the point where two lines intersect.
static Vector2d GetIntersect(const Vector2d&, const Vector2d&, const Vector2d&, const Vector2d&);
};