NewGamePhysics.Mathematics.VectorN Class Reference

The VectorN class stores "a point in n-dimensional space" - a sequence of real numbers - and defines operators for them. Based on public code from Vit Buchta, June 2007. More...

List of all members.

Public Member Functions

 VectorN (int n)
 A constructor. It defines a number of vector components and creates an real array with n elements.
 VectorN (VectorN a)
 A constructor which copies a given vector into itself.
VectorN Copy ()
 Copies itself into another object of VectorN type.
double Abs ()
 Absolute value. A method calculating the Euclidean norm of the vector.

Static Public Member Functions

static VectorN operator+ (VectorN a, VectorN b)
 Addition of two vectors.
static VectorN operator- (VectorN a, VectorN b)
 VectorN substraction.
static VectorN operator* (double c, VectorN a)
 Multiplication of a vector by a real number from the left side.
static VectorN operator* (VectorN a, double c)
 Multiplication of a vector by a real number from the right side.
static VectorN operator/ (double c, VectorN a)
 Division operator. A real number is divided by a vector.
static VectorN operator/ (VectorN a, double c)
 Division operator. A vector is divided by a real number.

Properties

int N [get]
 Returns a number of vector components.
double this [int i] [get, set]
 An indexer enabling to treat an object of VectorN type as an array.

Detailed Description

The VectorN class stores "a point in n-dimensional space" - a sequence of real numbers - and defines operators for them. Based on public code from Vit Buchta, June 2007.

Definition at line 15 of file VectorN.cs.


Constructor & Destructor Documentation

NewGamePhysics.Mathematics.VectorN.VectorN ( int  n  ) 

A constructor. It defines a number of vector components and creates an real array with n elements.

Parameters:
n Number of vector components

Definition at line 32 of file VectorN.cs.

00033         {
00034             if (n < 0)
00035             {
00036                 throw new ArgumentOutOfRangeException("n","Size must be greater than zero.");
00037             }
00038 
00039             this.n = n;
00040             this.x = new double[n];
00041         }

NewGamePhysics.Mathematics.VectorN.VectorN ( VectorN  a  ) 

A constructor which copies a given vector into itself.

Parameters:
a A variable of VectorN type

Definition at line 47 of file VectorN.cs.

00048         {
00049             this.n = a.n;
00050             this.x = new double[n];
00051             for (int i = 0; i < this.n; i++)
00052             {
00053                 this.x[i] = a.x[i];
00054             }
00055         }


Member Function Documentation

double NewGamePhysics.Mathematics.VectorN.Abs (  ) 

Absolute value. A method calculating the Euclidean norm of the vector.

Returns:
The Eucidean norm of the vector

Definition at line 116 of file VectorN.cs.

00117         {
00118             double r = 0;
00119             for (int i = 0; i < this.n; i++)
00120             {
00121                 double v = this.x[i];
00122                 r += v * v;
00123             }
00124 
00125             r = Math.Sqrt(r);
00126             return r;
00127         }

VectorN NewGamePhysics.Mathematics.VectorN.Copy (  ) 

Copies itself into another object of VectorN type.

Returns:
An object of VectorN type containing the copy of this object

Definition at line 100 of file VectorN.cs.

00101         {            
00102             VectorN r = new VectorN(this.n);
00103             for (int i = 0; i < this.n; i++)
00104             {
00105                 r.x[i] = this.x[i];
00106             }
00107 
00108             return r;
00109         }

static VectorN NewGamePhysics.Mathematics.VectorN.operator* ( VectorN  a,
double  c 
) [static]

Multiplication of a vector by a real number from the right side.

Parameters:
a A vector
c A real number
Returns:
A vector with compoonents a[i] * c

Definition at line 196 of file VectorN.cs.

00197         {
00198             return c * a;
00199         }

static VectorN NewGamePhysics.Mathematics.VectorN.operator* ( double  c,
VectorN  a 
) [static]

Multiplication of a vector by a real number from the left side.

Parameters:
c A real number
a A vector
Returns:
A vector which components c * a[i]

Definition at line 179 of file VectorN.cs.

00180         {
00181             VectorN r = new VectorN(a.n);
00182             for (int i = 0; i < a.n; i++)
00183             {
00184                 r.x[i] = c * a.x[i];
00185             }
00186 
00187             return r;
00188         }

static VectorN NewGamePhysics.Mathematics.VectorN.operator+ ( VectorN  a,
VectorN  b 
) [static]

Addition of two vectors.

Parameters:
a First vector
b Second vector
Returns:
A vector created as an addition of vectors a and b

Definition at line 135 of file VectorN.cs.

00136         {
00137             if (a.n != b.n)
00138             {
00139                 throw new ArgumentException("Vectors must be of same size");
00140             }
00141 
00142             VectorN r = new VectorN(a.n);
00143             for (int i = 0; i < a.n; i++)
00144             {
00145                 r.x[i] = a.x[i] + b.x[i];
00146             }
00147 
00148             return r;
00149         }

static VectorN NewGamePhysics.Mathematics.VectorN.operator- ( VectorN  a,
VectorN  b 
) [static]

VectorN substraction.

Parameters:
a First vector
b Second vector
Returns:
A vector created as vector a minus vector b

Definition at line 157 of file VectorN.cs.

00158         {
00159             if (a.n != b.n)
00160             {
00161                 throw new ArgumentException("Vectors must be of same size");
00162             }
00163 
00164             VectorN r = new VectorN(a.n);
00165             for (int i = 0; i < a.n; i++)
00166             {
00167                 r.x[i] = a.x[i] - b.x[i];
00168             }
00169 
00170             return r;
00171         }

static VectorN NewGamePhysics.Mathematics.VectorN.operator/ ( VectorN  a,
double  c 
) [static]

Division operator. A vector is divided by a real number.

Parameters:
c A real number. Should be different from zero.
a A vector
Returns:

Definition at line 232 of file VectorN.cs.

00233         {
00234             if (c == 0.0)
00235             {
00236                 throw new ArgumentOutOfRangeException("c", "Must be non-zero");
00237             }
00238 
00239             double d = 1.0 / c;
00240             return d * a;
00241         }

static VectorN NewGamePhysics.Mathematics.VectorN.operator/ ( double  c,
VectorN  a 
) [static]

Division operator. A real number is divided by a vector.

Parameters:
a A vector. All components should be different from zero.
c A real number.
Returns:

Definition at line 207 of file VectorN.cs.

00208         {
00209             for (int i = 0; i < a.n; i++)
00210             {
00211                 if (a[i] == 0.0)
00212                 {
00213                     throw new ArgumentOutOfRangeException("a", "All components must be non-zero");
00214                 }
00215             }
00216 
00217             VectorN r = new VectorN(a.n);
00218             for (int i = 0; i < a.n; i++)
00219             {
00220                 r.x[i] = c / a.x[i];
00221             }
00222 
00223             return r;
00224         }


Property Documentation

int NewGamePhysics.Mathematics.VectorN.N [get]

Returns a number of vector components.

Definition at line 61 of file VectorN.cs.

double NewGamePhysics.Mathematics.VectorN.this[int i] [get, set]

An indexer enabling to treat an object of VectorN type as an array.

Parameters:
i Zero based index
Returns:

Definition at line 74 of file VectorN.cs.


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2