home *** CD-ROM | disk | FTP | other *** search
- #include <fstream.h>
- #include <math.h>
- #include "vect.h"
-
- char Vector::delim = ' ';
-
- ostream& operator<< (ostream &f, const Vector &v)
- {
- f.setf(ios::showpoint | ios::fixed);
- f.width(8);
- f.precision(4);
-
- f << v.x << v.delim << v.y << v.delim << v.z;
-
- return f;
- }
-
-
- Vector min (const Vector &v1, const Vector &v2)
- {
- Vector v;
-
- v.x = (v1.x < v2.x) ? v1.x : v2.x;
- v.y = (v1.y < v2.y) ? v1.y : v2.y;
- v.z = (v1.z < v2.z) ? v1.z : v2.z;
-
- return v;
- }
-
- Vector max (const Vector &v1, const Vector &v2)
- {
- Vector v;
-
- v.x = (v1.x > v2.x) ? v1.x : v2.x;
- v.y = (v1.y > v2.y) ? v1.y : v2.y;
- v.z = (v1.z > v2.z) ? v1.z : v2.z;
-
- return v;
- }
-
-
- float angle (const Vector &v1, const Vector &v2)
- {
- float angle;
-
- float mag1 = mag(v1);
- float mag2 = mag(v2);
-
- if (mag1 * mag2 == 0.0)
- angle = 0.0;
- else {
- float cos_theta = (v1 DOT v2) / (mag1 * mag2);
-
- if (cos_theta <= -1.0)
- angle = M_PI;
- else if (cos_theta >= +1.0)
- angle = 0.0;
- else
- angle = acos(cos_theta);
- }
-
- return angle;
- }
-