]> Shamusworld >> Repos - architektonas/blob - src/vector.h
Further progress on Polylines: Polylines can be selected and moved.
[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, 2018 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 typedef Vector Point;
18
19 class Vector
20 {
21         public:
22                 Vector(double xx = 0, double yy = 0, double zz = 0);
23                 Vector(Vector tail, Vector head);       // Create vector from two points
24                 Vector(const Vector &v);
25                 void SetAngleAndLength(double angle, double length);
26                 Vector operator=(Vector const v);
27                 Vector operator+(Vector const v);
28                 Vector operator-(Vector const v);
29                 Vector operator-(void);                         // Unary negation
30                 Vector operator*(double const v);       // Vector times constant (double)
31                 Vector operator*(float const v);        // Vector times constant (float)
32                 Vector operator/(double const v);       // Vector divided by constant (double)
33                 Vector operator/(float const v);        // Vector divided by constant (float)
34                 Vector operator*(Vector const v);       // Vector product
35                 double Dot(Vector const v);                     // Dot product
36
37                 Vector& operator*=(double const v);     // Vector times constant self-assignment
38                 Vector& operator/=(double const v);     // Vector divided by constant self-assignment
39                 Vector& operator+=(Vector const v);     // Vector plus Vector self-assignment
40                 Vector& operator+=(double const v);     // Vector plus constant self-assignment
41                 Vector& operator-=(Vector const v);     // Vector minus Vector self-assignment
42                 Vector& operator-=(double const v);     // Vector minus constant self-assignment
43
44                 bool operator==(Vector const v);        // Check for equality
45                 bool operator!=(Vector const v);        // Check for inequality
46
47                 Vector Unit(void);
48                 double Magnitude(void);
49                 double Angle(void);
50                 bool isZero(double epsilon = 1e-6);
51
52                 // Class methods
53
54                 static double Dot(Vector v1, Vector v2);
55                 static double Magnitude(Vector v1, Vector v2);
56                 static Vector Unit(Point p1, Point p2);
57                 static double Angle(Point p1, Point p2);
58                 static double Parameter(Vector v1, Vector v2, Vector p);
59                 static Vector Normal(Vector v1, Vector v2);
60                 static double AngleBetween(Vector a1, Vector a2);
61                 static Point Midpoint(Point p1, Point p2);
62
63         public:
64                 double x, y, z, b; // "b" is an extra used mainly for arc bumps
65 };
66
67 #endif  // __VECTOR_H__