Vector
by
Joe Strout
This is a very simple-but-handy implementation of a three-dimensional
real-valued vector. (You can use it as a 2D vector, too; the third (Z)
dimension defaults to zero.) No source code (.cxx) file is needed; it's an
entirely inline class, which means that code using it will be very zippy
(no true function calls).
Grab the header file here.
Vector supports all the arithmatic operators you would
expect: addition and subtraction (+,-), multiplication by a scalar (*),
and cross product (*). Other functions are:
- Vector::Dot(const Vector): dot product with another
vector (returns a scalar)
- Dot(const Vector, const Vector): another form of the
same
- Vector::Cross(const Vector): cross product with
another vector (returns a vector)
- Cross(const Vector, const Vector): another form;
equivalent to Vector * Vector
- Vector::Length(): vector magnitude
- Vector::LenSqr(): vector magnitude, squared
- Vector::Proj(const Vector): projection of *this onto
another vector (i.e., component of this vector which is parallel to that)
- Vector::CosAng(const Vector): cosine of the angle
between this vector and another
- ostream << Vector: stream output, in the form (a,b,c)
- istream >> Vector: stream input, in the form a b c
Note: if you need the component of a vector A which is
perpendicular to another vector B, it's just A - A.Proj(B)
http://www-ncmir.ucsd.edu/~jstrout/classlib/String.html
Last Updated:
1/30/96
Joe Strout (
joe@strout.net )