]> Shamusworld >> Repos - architektonas/blob - src/vector.h
62438986ef653bd0462d9e600e307105ce592ba3
[architektonas] / src / vector.h
1 //
2 // vector.h (Last modified: 6/28/2001)
3 //
4 // Various structures used for 3 dimensional imaging
5 //
6 // by James Hammons
7 // (C) 2001, 2014 Underground Software
8 //
9
10 #ifndef __VECTOR_H__
11 #define __VECTOR_H__
12
13 // What we'll do here is create the vector type and use typedef to alias Point
14 // to it. Yeah, that's it.
15
16 class Vector
17 {
18         public:
19                 Vector(double xx = 0, double yy = 0, double zz = 0);
20                 Vector(Vector tail, Vector head);               // Create vector from two points
21                 void SetAngleAndLength(double angle, double length);
22                 Vector operator=(Vector const v);
23                 Vector operator+(Vector const v);
24                 Vector operator-(Vector const v);
25                 Vector operator-(void);                                 // Unary negation
26                 Vector operator*(double const v);               // Vector times constant (double)
27                 Vector operator*(float const v);                // Vector times constant (float)
28                 Vector operator/(double const v);               // Vector divided by constant (double)
29                 Vector operator/(float const v);                // Vector divided by constant (float)
30                 Vector operator*(Vector const v);               // Vector product
31                 double Dot(Vector const v);                             // Dot product
32
33                 Vector& operator*=(double const v);             // Vector times constant self-assignment
34                 Vector& operator/=(double const v);             // Vector divided by constant self-assignment
35                 Vector& operator+=(Vector const v);             // Vector plus Vector self-assignment
36                 Vector& operator+=(double const v);             // Vector plus constant self-assignment
37                 Vector& operator-=(Vector const v);             // Vector minus Vector self-assignment
38                 Vector& operator-=(double const v);             // Vector minus constant self-assignment
39
40                 bool operator==(Vector const v);                // Check for equality
41                 bool operator!=(Vector const v);                // Check for inequality
42
43                 Vector Unit(void);
44                 double Magnitude(void);
45                 double Angle(void);
46                 bool isZero(double epsilon = 1e-6);
47
48                 // Class methods
49
50                 static double Dot(Vector v1, Vector v2);
51                 static double Magnitude(Vector v1, Vector v2);
52                 static double Parameter(Vector v1, Vector v2, Vector p);
53                 static Vector Normal(Vector v1, Vector v2);
54                 static double AngleBetween(Vector a, Vector b);
55
56         public:
57                 double x, y, z;
58 };
59
60 typedef Vector Point;
61
62 #endif  // __VECTOR_H__