# cugl::Point Class Reference

`#include <cugl.h>`

List of all members.

## Public Member Functions

Point (GLfloat x=0, GLfloat y=0, GLfloat z=0, GLfloat w=1)
Point (GLfloat coordinates[])
Point (const Quaternion &q)
GLfloat & operator[] (int i)
const GLfloat & operator[] (int i) const
void normalize ()
Point unit () const
void draw () const
void light (GLenum lightNum) const
void translate () const
Point operator/ (GLfloat s) const
Point operator+= (const Vector &v)
Point operator-= (const Vector &v)

GLfloat x
GLfloat y
GLfloat z
GLfloat w

## Friends

class Line
class Vector
class Matrix
class Plane
Point operator+ (const Vector &v, const Point &p)
Point operator+ (const Point &p, const Vector &v)
Point operator * (const Point &p, GLfloat s)
Point operator * (GLfloat s, const Point &p)
Vector operator- (const Point &p, const Point &q)
Point meet (Line &k, Plane &p)
bool operator== (const Point &p, const Point &q)
bool operator!= (const Point &p, const Point &q)
std::ostream & operator<< (std::ostream &os, Point &p)
GLfloat dist (const Point &p, const Plane &s)
GLfloat dist (const Plane &s, const Point &p)
double dist (const Point &p, const Point &q)

## Detailed Description

An instance is a point represented by four homogeneous coordinates. A point is represented by (x,y,z,w) in which each component is a `GLfloat`. If w=0, the point is `at infinity'. Points at infinity may be used like other points, but a few operations do not work for them. CUGL functions do not issue an error message when this happens: they simply return a default result.

A Point is in normal form if w=1. A Point may be normalized if w!=0.

Definition at line 145 of file cugl.h.

## Constructor & Destructor Documentation

 cugl::Point::Point ( GLfloat x = `0`, GLfloat y = `0`, GLfloat z = `0`, GLfloat w = `1` )

Construct a point with coordinates (x, y, z, w). Default parameter values: (0,0,0,1).

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

 cugl::Point::Point ( GLfloat coordinates[] ) ` [inline]`

Construct a point from the array `coordinates`.

Precondition:
The array must have at least four components.

Definition at line 2411 of file cugl.h.

References w, x, y, and z.

 cugl::Point::Point ( const Quaternion & q )

Convert a Quaternion to a Point.

Note:
This is a rather peculiar operation and should not normally be used. It is intended for experiments with non-linear transformations.

## Member Function Documentation

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

Access coordinates: p[0] = x, p[1] = y, p[2] = z, p[3] = w. Error BAD_INDEX reported if `i` is not one of {0,1,2, 3}.

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

Access coordinates: p[0] = x, p[1] = y, p[2] = z, p[3] = w. This form is used with `const` instances (`p`[i] cannot appear on the left of `=`). Error BAD_INDEX reported if `i` is not one of {0,1,2, 3}.

 void cugl::Point::normalize ( )

Normalize this point. A Point is in normal form if w=1. Error ZERO_DIVISOR reported if w=0.

Note:
The value of this Point is changed by this function.

 Point cugl::Point::unit ( ) const

Return this Point in normalized form. A Point is in normal form if w=1. Error ZERO_DIVISOR reported if w=0.

 void cugl::Point::draw ( ) const` [inline]`

Draw the point using `glVertex4f()`.

Definition at line 2440 of file cugl.h.

References w, x, y, and z.

Referenced by cugl::Vector::draw().

 void cugl::Point::light ( GLenum lightNum ) const` [inline]`

Use this point as a light position. If w = 0, the light is directional, otherwise it is positional.

Parameters:
 lightNum specifies which light to use: it must be one of GL_LIGHT0, GL_LIGHT1, ...

Definition at line 2447 of file cugl.h.

References w, x, y, and z.

 void cugl::Point::translate ( ) const` [inline]`

Translate to the point using `glTranslatef()`.

Note:
If the point is at infinity (w = 0), this function has no effect.

Definition at line 2457 of file cugl.h.

References w, x, y, and z.

 Point cugl::Point::operator/ ( GLfloat s ) const` [inline]`

Scale a Point. Scale the coordinates of a Point by dividing by the scalar s. This is implemented by multiplying the w component of the Point by s. If s=0, the result is a Point at infinity.

Returns:
the Point at (x,y,z,s*w).

Definition at line 2435 of file cugl.h.

References Point(), w, x, y, and z.

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

Displace a Point with a Vector

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

Definition at line 2419 of file cugl.h.

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

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

Displace a Point with a Vector

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

Definition at line 2427 of file cugl.h.

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

## Friends And Related Function Documentation

 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.

 Point operator * ( const Point & p, GLfloat s ) ` [friend]`

Scale a point.

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

Definition at line 2474 of file cugl.h.

 Point operator * ( GLfloat s, const Point & p ) ` [friend]`

Scale a point.

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

Definition at line 2479 of file cugl.h.

 Vector operator- ( const Point & p, const Point & q ) ` [friend]`

Return the vector corresponding to the displacement between the two points. This is the vector (`p.x/p`.w - `q.x/q`.w, `p.y/p`.w - `q.y/q`.w, `p.z/p`.w - `q.z/q`.w). If `p` or `q` is a point at infinity, return the zero vector.

Returns:
the Vector corresponding to the displacement between the two points.

Definition at line 2643 of file cugl.h.

 Point meet ( Line & k, Plane & p ) ` [friend]`

Find the point where this line meets the plane p. Sets error BAD_LINE if the line lies within the plane.

Returns:
the Point at which Line `k` meets Plane `p`.

 bool operator== ( const Point & p, const Point & q ) ` [friend]`

Compare two points. 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 2484 of file cugl.h.

 bool operator!= ( const Point & p, const Point & q ) ` [friend]`

Compare two points. 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 2489 of file cugl.h.

 std::ostream& operator<< ( std::ostream & os, Point & p ) ` [friend]`

Write "(x,y,z,w)" to output stream. Inserts the coordinates of the point into the output stream `os` in the format "(x,y,z,w)". 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 point as a whole.

 GLfloat dist ( const Point & p, const Plane & s ) ` [friend]`

Return the distance between a Point and a Plane. The result has the correct magnitude only if the Point and the Plane are both in normal form. In particular, the result is incorrect if the Point is at infinity. However, the sign of the result is correct in all cases, and so it is not necessary to provide normalized arguments if only the sign is important.

Definition at line 2494 of file cugl.h.

 GLfloat dist ( const Plane & s, const Point & p ) ` [friend]`

Return the distance between a Point and a Plane. The result has the correct magnitude only if the Point and the Plane are both in normal form. In particular, the result is incorrect if the Point is at infinity. However, the sign of the result is correct in all cases, and so it is not necessary to provide normalized arguments if only the sign is important.

Definition at line 2499 of file cugl.h.

 double dist ( const Point & p, const Point & q ) ` [friend]`

Return the disgtance bewteen two points.

Note:
Does not check that the points are normalized.

Definition at line 328 of file cugl.h.

## Member Data Documentation

 GLfloat cugl::Point::x` [private]`

X coordinate of point.

Definition at line 336 of file cugl.h.

 GLfloat cugl::Point::y` [private]`

Y coordinate of point.

Definition at line 339 of file cugl.h.

 GLfloat cugl::Point::z` [private]`

Z coordinate of point.

Definition at line 342 of file cugl.h.

 GLfloat cugl::Point::w` [private]`

W coordinate of point.

Definition at line 345 of file cugl.h.

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