com.vodafone.v10.util
Class Vector2D

java.lang.Object
  |
  +--com.vodafone.v10.util.Vector2D

public class Vector2D
extends java.lang.Object

Vector2D is a class providing functions for 2D vector operations. A Vector2D instance holds each of the vector elements as FixedPoint instances. The following functions are provided:

When an int parameter is designated with a constructor or method, it is regarded as a fixed-point value with bit 16 as the digit next to the decimal point. Likewise, when a method returns an int value, it is returned as a fixed-point value with bit 16 as the digit next to the decimal point.


Constructor Summary
Vector2D()
           Vector2D constructor.
Vector2D(FixedPoint x, FixedPoint y)
           Vector2D constructor.
Vector2D(int x, int y)
           Vector2D constructor.
 
Method Summary
 void add(int x, int y)
           Performs addition.
 void add(Vector2D vector)
           Performs addition.
 Vector2D clone()
           Clones an object.
 FixedPoint getX()
          Gets a vector value along its x axis.
 FixedPoint getY()
          Gets a vector value along its y axis.
static FixedPoint innerProduct(Vector2D v1, Vector2D v2)
           Calculates an inner product.
 void normalize()
          Normalizes a vector.
static FixedPoint outerProduct(Vector2D v1, Vector2D v2)
           Calculates an outer product.
 void setValue(FixedPoint x, FixedPoint y)
          Sets new vector values.
 void setValue(int x, int y)
          Sets new vector values.
 void subtract(int x, int y)
           Performs subtraction.
 void subtract(Vector2D vector)
           Performs subtraction.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vector2D

public Vector2D(FixedPoint x,
                FixedPoint y)

Vector2D constructor.

Holds as vector elements the coordinates designated in the parameters.

Parameters:
x - X coordinate
y - Y coordinate

Vector2D

public Vector2D(int x,
                int y)

Vector2D constructor.

Holds as vector elements the coordinates designated in the parameters.

Parameters:
x - X coordinate
y - Y coordinate

Vector2D

public Vector2D()

Vector2D constructor.

The x,y coordinates of the held vector are 0,0.

Method Detail

add

public void add(Vector2D vector)

Performs addition.

Adds the vector designated in the parameter.

Parameters:
vector - The vector to be added.
Throws:
NullPointerException - if vector is null.

add

public void add(int x,
                int y)

Performs addition.

Adds the vector designated in the parameters.

Parameters:
x - Value along its x axis of the vector to be added
y - Value along its y axis of the vector to be added

subtract

public void subtract(Vector2D vector)

Performs subtraction.

Subtracts the vector designated in the parameter.

Parameters:
vector - The vector to be subtracted
Throws:
NullPointerException - if vector is null.

subtract

public void subtract(int x,
                     int y)

Performs subtraction.

Subtracts the vector designated in the parameters.

Parameters:
x - Value along its x axis of the vector to be subtracted
y - Value along its y axis of the vector to be subtracted

normalize

public void normalize()
Normalizes a vector.

innerProduct

public static FixedPoint innerProduct(Vector2D v1,
                                      Vector2D v2)

Calculates an inner product.

Calculates and returns the inner product of the two Vector2D objects designated in the parameters.

Parameters:
v1 - Vector 1
v2 - Vector 2
Returns:
FixedPoint - The calculation result
Throws:
NullPointerException - if v1 or v2 is null.

outerProduct

public static FixedPoint outerProduct(Vector2D v1,
                                      Vector2D v2)

Calculates an outer product.

Calculates and returns the outer product of the two Vector2D objects designated in the parameters.

Parameters:
v1 - Vector 1
v2 - Vector 2
Returns:
FixedPoint - The calculation result
Throws:
NullPointerException - if v1 or v2 is null.

setValue

public void setValue(int x,
                     int y)
Sets new vector values.
Parameters:
x - Vector value along its x axis
y - Vector value along its y axis

setValue

public void setValue(FixedPoint x,
                     FixedPoint y)
Sets new vector values.
Parameters:
x - Vector value along its x axis
y - Vector value along its y axis
Throws:
NullPointerException - if x or y is null.

getX

public FixedPoint getX()
Gets a vector value along its x axis.
Returns:
FixedPoint The vector value along its x axis

getY

public FixedPoint getY()
Gets a vector value along its y axis.
Returns:
FixedPoint The vector value along its y axis

clone

public Vector2D clone()

Clones an object.

Creates an object with the same contents.

Returns:
Vector2D A Vector2D object with the same contents


Copyright 2002,2003 Aplix Corporation. All rights reserved. Aplix Confidential and Restricted.