-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector2d.h
27 lines (25 loc) · 949 Bytes
/
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
#pragma once
#ifndef VECTOR2D_H
#define VECTOR2D_H
class Vector2d
{
double x, y;
public:
Vector2d();
Vector2d(double x, double y);
Vector2d(const Vector2d& v);
double norm();
void normalize();
double sqrNorm();
double dot(Vector2d op);
double getX() { return x; }
double getY() { return y; }
Vector2d getUnitVector() { return *this / norm(); }
friend Vector2d operator + (const Vector2d& v1, const Vector2d& v2) { return Vector2d(v1.x + v2.x, v1.y + v2.y); }
friend Vector2d operator - (const Vector2d& v1, const Vector2d& v2) { return Vector2d(v1.x - v2.x, v1.y - v2.y); }
friend Vector2d operator * (const Vector2d& v1, const double& d) { return Vector2d(v1.x * d, v1.y * d); }
friend Vector2d operator / (const Vector2d& v1, const double& d) { return Vector2d(v1.x / d, v1.y / d); }
friend Vector2d operator * (const double& d, const Vector2d& v1) { return Vector2d(v1.x * d, v1.y * d); }
~Vector2d();
};
#endif // !VECTOR2D_H