-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_basics.h
100 lines (88 loc) · 2.63 KB
/
vector_basics.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef VECTOR_BASICS
#define VECTOR_BASICS
#include <math.h>
#include <stdio.h>
#include <iostream>
#define PI 3.14159265358979
class Point;
class Vector;
class LineSeg;
class Point{
public:
union{ // make it so we can access the data as array or xyz
struct{
double x,y,z;
};
double data[3];
};
Point();
Point(double x, double y, double z);
//==============================================================================
// OPERATOR OVERLOADS
//==============================================================================
Point& operator+=(const Vector& other);
Point& operator+=(const Point& other);
Point operator+(const Vector& other);
Point operator+(const Point& other);
Point& operator*=(const double scale);
Point operator*(const double scale);
Point& operator/=(const double scale);
Point operator/(const double scale);
Point translatePoint(double x, double y, double z);
Point scalePoint(double scaleX, double scaleY, double scaleZ);
Point rotatePoint(double theta, bool x, bool y, bool z);
bool operator==(const Point& other);
bool operator!=(const Point& other);
double& operator[](const int index);
};
class Vector{
public:
union{ // make it so we can access the data as array or xyz
struct{
double x,y,z;
};
double data[3];
};
Vector();
Vector(double x, double y, double z);
Vector(Point& p1, Point& p2);
//==============================================================================
// BASIC VECTOR OPERATIONS
//==============================================================================
double magnitude();
double length();
double dot(Vector& other);
double dotProduct(Vector& other);
Vector cross(const Vector& other);
Vector crossProduct(Vector& other);
//==============================================================================
// OPERATOR OVERLOADS
//==============================================================================
Vector& operator+=(const Vector& other);
Vector operator+(const Vector& other);
Vector& operator-=(const Vector& other);
Vector operator-(const Vector& other);
Vector& operator*=(const double scale);
Vector operator*(const double scale);
Vector& operator/=(const double scale);
Vector operator/(const double scale);
bool operator==(const Vector& other);
bool operator!=(const Vector& other);
double& operator[](const int index);
};
class LineSeg{
public:
Point p1;
Point p2;
LineSeg();
LineSeg(const Point& p1, const Point& p2);
LineSeg(Point p1, const Vector& v);
bool intersect(LineSeg& other);
Point intersection(LineSeg& other);
Point& operator[](const int& index);
Vector direction();
};
struct Triangle{
Point p1,p2,p3;
};
#endif