cugl::Vector Class Reference

#include <cugl.h>

List of all members.

Public Member Functions

 Vector ()
 Vector (GLfloat x, GLfloat y, GLfloat z)
 Vector (GLfloat coordinates[])
 Vector (Point points[], int numPoints)
 Vector (Point &p, Point &q)
 Vector (const Quaternion &q)
Vector operator+= (const Vector &v)
Vector operator-= (const Vector &v)
Vector operator- () const
Vector operator *= (GLfloat scale)
Vector operator/ (GLfloat scale) const
Vector operator/= (GLfloat scale)
void normalize ()
Vector unit () const
GLfloat norm () const
GLfloat length () const
void translate () const
void drawNormal () const
void draw (const Point &p) const
GLfloat & operator[] (int i)
const GLfloat & operator[] (int i) const

Private Attributes

GLfloat x
GLfloat y
GLfloat z

Friends

class Point
class Matrix
class Quaternion
Vector cross (const Vector &u, const Vector &v)
Vector operator * (const Vector &u, const Vector &v)
GLfloat dot (const Vector &u, const Vector &v)
Vector operator * (const Vector &v, GLfloat s)
Vector operator * (GLfloat s, const Vector &v)
Vector operator+ (const Vector &u, const Vector &v)
Vector operator- (const Vector &u, const Vector &v)
Point operator+ (const Vector &v, const Point &p)
Point operator+ (const Point &p, const Vector &v)
bool operator== (const Vector &x, const Vector &y)
bool operator!= (const Vector &x, const Vector &y)
std::ostream & operator<< (std::ostream &os, Vector &v)


Detailed Description

An instance is a vector with 3 real components. A vector v is a 3-vector represented by three orthogonal components vx, vy, and vz. The norm of the vector v is vx*vx+vy*vy+vz*vz. The length of v is sqrt(norm(v)).

Definition at line 561 of file cugl.h.


Constructor & Destructor Documentation

cugl::Vector::Vector (  )  [inline]

Construct the zero vector: (0,0,0).

Definition at line 571 of file cugl.h.

Referenced by cugl::cross(), cugl::operator *(), cugl::operator+(), cugl::operator-(), and operator-().

cugl::Vector::Vector ( GLfloat  x,
GLfloat  y,
GLfloat  z 
) [inline]

Construct the vector (x,y,z).

Definition at line 578 of file cugl.h.

cugl::Vector::Vector ( GLfloat  coordinates[]  )  [inline]

Construct a vector from the array coordinates.

Precondition:
The array must have at least three components.

Definition at line 2552 of file cugl.h.

References x, y, and z.

cugl::Vector::Vector ( Point  points[],
int  numPoints 
)

Construct a vector normal to the polygon defined by the given points using Martin Newell's algorithm. The normal vector will be exact if the points lie in a plane, otherwise it will be a sort of average value. As with OpenGL, the vector will point in the direction from which the points are enumerated in a counter-clockwise direction.

Unlike other functions, this function does not use homogeneous coordinates. The points are assumed to have (x,y,z) coordinates; the w component is ignored.

Parameters:
points is an array of points.
numPoints is the number of points in the array.
Returns:
the vector normal to the plane defined by points.
Note:
The vector is not a unit vector because it will probably be averaged with other vectors.

cugl::Vector::Vector ( Point p,
Point q 
) [inline]

Construct a vector from two points. Vector(p, q) is equivalent to p - q.

Definition at line 2559 of file cugl.h.

References cugl::Point::w, cugl::Point::x, x, cugl::Point::y, y, cugl::Point::z, and z.

cugl::Vector::Vector ( const Quaternion q  )  [inline]

Construct a vector from a quaternion by ignoring the scalar component of the quaternion. Vector(q) constructs the vector returned by q.vector().

Parameters:
q is the Quaternion whose vector component is to be used.

Definition at line 2575 of file cugl.h.

References cugl::Quaternion::v, x, y, and z.


Member Function Documentation

Vector cugl::Vector::operator+= ( const Vector v  )  [inline]

Add vector v to this vector.

Definition at line 2584 of file cugl.h.

References x, y, and z.

Vector cugl::Vector::operator-= ( const Vector v  )  [inline]

Subtract vector v from this vector.

Definition at line 2592 of file cugl.h.

References x, y, and z.

Vector cugl::Vector::operator- (  )  const [inline]

Return Vector (-x,-y,-z).

Definition at line 2600 of file cugl.h.

References Vector(), x, y, and z.

Vector cugl::Vector::operator *= ( GLfloat  scale  )  [inline]

Multiply each component of the vector by scale.

Definition at line 2605 of file cugl.h.

References x, y, and z.

Vector cugl::Vector::operator/ ( GLfloat  scale  )  const

Return the vector (x/scale,y/scale,z/scale). Error ZERO_DIVISOR reported if scale is zero.

Returns:
the Vector (x/scale,y/scale,z/scale).

Vector cugl::Vector::operator/= ( GLfloat  scale  ) 

Divide each component of this vector by scale and return the new value. Error ZERO_DIVISOR reported if scale is zero.

void cugl::Vector::normalize (  ) 

Normalize this vector. See also Vector::unit(). Reports error ZERO_NORM if the vector is zero.

Note:
The value of this vector is changed by this operation.

Vector cugl::Vector::unit (  )  const

Return a unit vector with the same direction as this vector. See also Vector::normalize(). Reports error ZERO_NORM if the vector is zero.

Note:
The value of this vector is not changed by this operation.

Referenced by cugl::Quaternion::axis(), and cugl::Plane::normal().

GLfloat cugl::Vector::norm (  )  const [inline]

Return the norm of this vector. The norm of a vector is the sum of its squared components and is also the square of the length.

Returns:
the norm of this vector.

Definition at line 2613 of file cugl.h.

References x, y, and z.

Referenced by length(), and cugl::Quaternion::norm().

GLfloat cugl::Vector::length (  )  const [inline]

Return the length of this vector. The length of a vector is the square root of its norm.

Returns:
the length of this vector.

Definition at line 2618 of file cugl.h.

References norm().

void cugl::Vector::translate (  )  const [inline]

Use this vector to translate an object. This is implemented by passing the vector to glTranslate().

Definition at line 2623 of file cugl.h.

References x, y, and z.

void cugl::Vector::drawNormal (  )  const [inline]

Use this vector as a normal vector when drawing a surface. This is implemented by passing the vector to glNormal().

Definition at line 2628 of file cugl.h.

References x, y, and z.

void cugl::Vector::draw ( const Point p  )  const [inline]

Draw this vector as a line in the graphics window. The line joins P and P+V, where P is the point provided.

Parameters:
p is the start point for the vector.

Definition at line 2633 of file cugl.h.

References cugl::Point::draw().

GLfloat& cugl::Vector::operator[] ( int  i  ) 

Get or set a reference to a component of this vector. v[0] is the x component; v[1] is the y component; v[2] is the z component. Error BAD_INDEX reported if i is not one of 0, 1, 2.

const GLfloat& cugl::Vector::operator[] ( int  i  )  const

Get a reference to a component of this vector. This form is used for const instances (v[i] cannot appear on the left of =). v[0] is the x component; v[1] is the y component; v[2] is the z component. Error BAD_INDEX reported if i is not one of 0, 1, 2.


Friends And Related Function Documentation

Vector cross ( const Vector u,
const Vector v 
) [friend]

Return cross product of vectors u and v.

Definition at line 2671 of file cugl.h.

Vector operator * ( const Vector u,
const Vector v 
) [friend]

Return cross product of vectors u and v.

Definition at line 2679 of file cugl.h.

GLfloat dot ( const Vector u,
const Vector v 
) [friend]

Return dot product of vectors u and v.

Definition at line 2687 of file cugl.h.

Vector operator * ( const Vector v,
GLfloat  s 
) [friend]

Return Vector s*v.

Definition at line 2661 of file cugl.h.

Vector operator * ( GLfloat  s,
const Vector v 
) [friend]

Return Vector s*v.

Definition at line 2666 of file cugl.h.

Vector operator+ ( const Vector u,
const Vector v 
) [friend]

Return Vector u+v.

Definition at line 2651 of file cugl.h.

Vector operator- ( const Vector u,
const Vector v 
) [friend]

Return Vector u-v.

Definition at line 2656 of file cugl.h.

Point operator+ ( const Vector v,
const Point p 
) [friend]

Displace a Point with a Vector.

Returns:
Point at (p.x+p.w*v.x, p.y+p.w*v.y, p.z+p.w*v.z, p.w).

Definition at line 2469 of file cugl.h.

Point operator+ ( const Point p,
const Vector v 
) [friend]

Displace a Point with a Vector.

Returns:
Point at (p.x+p.w*v.x, p.y+p.w*v.y, p.z+p.w*v.z, p.w).

Definition at line 2464 of file cugl.h.

bool operator== ( const Vector x,
const Vector y 
) [friend]

Compare two vectors. This function returns true only if corresponding components are exactly equal. Values that are theoretically equal but computed in different ways are likely to be unequal according to this function.

Definition at line 2692 of file cugl.h.

bool operator!= ( const Vector x,
const Vector y 
) [friend]

Compare two vectors. This function returns false only if corresponding components are exactly equal. Values that are theoretically equal but computed in different ways are likely to be unequal according to this function.

Definition at line 2697 of file cugl.h.

std::ostream& operator<< ( std::ostream &  os,
Vector v 
) [friend]

Write vector to output stream as (x,y,z). Inserts the components of the vector into the output stream os in the format (x,y,z). The current settings of the stream formatting parameters are used. If a width is specified with setw(), it is applied to each coordinate, not to the vector as a whole.


Member Data Documentation

GLfloat cugl::Vector::x [private]

X component of vector.

Definition at line 792 of file cugl.h.

Referenced by cugl::cross(), cugl::dot(), drawNormal(), norm(), cugl::operator *(), operator *=(), cugl::operator+(), operator+=(), cugl::Point::operator+=(), cugl::operator-(), operator-(), operator-=(), cugl::Point::operator-=(), cugl::operator==(), translate(), and Vector().

GLfloat cugl::Vector::y [private]

Y component of vector.

Definition at line 795 of file cugl.h.

Referenced by cugl::cross(), cugl::dot(), drawNormal(), norm(), cugl::operator *(), operator *=(), cugl::operator+(), operator+=(), cugl::Point::operator+=(), cugl::operator-(), operator-(), operator-=(), cugl::Point::operator-=(), cugl::operator==(), translate(), and Vector().

GLfloat cugl::Vector::z [private]

Z component of vector.

Definition at line 798 of file cugl.h.

Referenced by cugl::cross(), cugl::dot(), drawNormal(), norm(), cugl::operator *(), operator *=(), cugl::operator+(), operator+=(), cugl::Point::operator+=(), cugl::operator-(), operator-(), operator-=(), cugl::Point::operator-=(), cugl::operator==(), translate(), and Vector().


The documentation for this class was generated from the following file:
Generated on Wed Sep 12 14:31:42 2007 for CUGL by  doxygen 1.5.2