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
|
//==================================================================
// Copyright 2002, softSurfer (www.softsurfer.com)
// This code may be freely used and modified for any purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from it's use.
// Users of this code must verify correctness for their application.
//==================================================================
// Heavily modified by Randal A. Koene, 20050111
#ifndef SS_Vector3D_H
#include <cmath>
#include "Point3D.hh"
#define SS_Vector3D_H
class Vector3D : public Point3D {
public:
Vector3D(): Point3D() {};
Vector3D(double X, double Y, double Z) : Point3D(X,Y,Z) {};
//Vector3D(Vector3D & v): Point3D(v.x,v.y,v.z) {};
//*** Using implicit copy constructor
~Vector3D() {};
Vector3D operator-(); // unary minus
Vector3D operator~(); // unary 2D perp operator
// Scalar Multiplication
friend Vector3D operator*( int, Vector3D);
friend Vector3D operator*( double, Vector3D);
friend Vector3D operator*( Vector3D, int);
friend Vector3D operator*( Vector3D, double);
// Scalar Division
friend Vector3D operator/( Vector3D, int);
friend Vector3D operator/( Vector3D, double);
// Vector3D Arithmetic Operations
Vector3D operator+( Vector3D); // vector add
Vector3D operator-( Vector3D); // vector subtract
double operator*( Vector3D w) { return (x * w.x + y * w.y + z * w.z); } // inner dot product
double operator|( Vector3D w) { return (x * w.y - y * w.x); } // 2D exterior perp product
Vector3D operator^( Vector3D); // 3D exterior cross product
Vector3D& operator*=(double c) { // vector scalar mult
x *= c;
y *= c;
z *= c;
return *this;
}
Vector3D& operator/=(double c) { // vector scalar div
x /= c;
y /= c;
z /= c;
return *this;
}
Vector3D& operator+=( Vector3D w) { // vector increment
x += w.x;
y += w.y;
z += w.z;
return *this;
}
Vector3D& operator-=( Vector3D w) { // vector decrement
x -= w.x;
y -= w.y;
z -= w.z;
return *this;
}
Vector3D& operator^=( Vector3D); // 3D exterior cross product
// operator== inherited from Point
double len() { return sqrt(x*x + y*y + z*z); } // vector length
double len2() { return (x*x + y*y + z*z); } // vector length squared (faster)
// Special Operations
double normalize(); // convert vector to unit length
friend Vector3D sum( int, int[], Vector3D[]); // vector sum
friend Vector3D sum( int, double[], Vector3D[]); // vector sum
};
#endif
|