Class Point2
See Also: Class IPoint2.
class Point2
Description:
This class describes a 2D point using float x and y coordinates. Methods are provided to add and subtract points, multiply and divide by scalars, normalize and compute the dot product of two Point2s. All methods are implemented by the system.
Data Members:
public:
float x,y;
The x and y components of the point.
static const Point2 Origin;
This data member is available in release 3.0 and later only.
This is equivalent to Point2(0.0f, 0.0f);
static const Point2 XAxis;
This data member is available in release 3.0 and later only.
This is equivalent to Point2(1.0f, 0.0f);
static const Point2 YAxis;
This data member is available in release 3.0 and later only.
This is equivalent to Point2(0.0f, 1.0f);
Methods:
Constructors
Prototype:
Point2()
Remarks:
Constructor. No initialization is performed by this constructor.
Prototype:
Point2(float X, float Y)
Remarks:
Constructor. Data members are initialized to X and Y.
Prototype:
Point2(double X, double Y)
Remarks:
Constructor. Data members are initialized to X and Y cast as floats.
Prototype:
Point2(const Point2& a)
Remarks:
Constructor. Data members are initialized to a.x and a.y.
Prototype:
Point2(float af[2])
Remarks:
Constructor. Data members are initialized as x = af[0] and y = af[1].
Prototype:
Point2& Set(float X, float Y);
Remarks:
This method is available in release 3.0 and later only.
Sets the x and y coordinate to the values passed and returns a reference to this Point2.
Parameters:
float X
The new x value.
float Y
The new y value.
Return Value:
A reference to this Point2.
Prototype:
float DotProd(const Point2&) const
Remarks:
Returns the dot product of two Point2's. This is the sum of both x values multiplied together and both y values multiplied together.
Prototype:
float Length() const;
Remarks:
This method is available in release 3.0 and later only.
Returns the length of the point. This is sqrt(v.x*v.x+v.y*v.y);
Prototype:
int MaxComponent() const;
Remarks:
This method is available in release 3.0 and later only.
This method returns the component with the maximum absolute value.
Return Value:
0 for X, 1 for Y, 2 for Z.
Prototype:
int MinComponent() const;
Remarks:
This method is available in release 3.0 and later only.
This method returns the component with the minimum absolute value.
Return Value:
0 for X, 1 for Y, 2 for Z.
Prototype:
Point2 Normalize() const;
Remarks:
This method is available in release 3.0 and later only.
This method returns a normalized version of this Point2. This method is more accurate than *this/Length() (internal computations are done in double precision).
Prototype:
int Equals(const Point2& p, float epsilon = 1E-6f);
Remarks:
This method is available in release 3.0 and later only.
Compares this Point2 and the specified one to see if the x and y values are within plus or minus the specified tolerance.
Parameters:
const Point2& p
The point to compare.
float epsilon = 1E-6f
The tolerance to use in the comparison.
Return Value:
Nonzero if the points are 'equal'; otherwise zero.
Prototype:
Point2& Unify();
Remarks:
This method is available in release 3.0 and later only.
This method is used to unify (or normalize) this Point2 (in place) and return the result. Internal computations are done in double precision.
Prototype:
float LengthUnify();
Remarks:
This method is available in release 3.0 and later only.
This method is used to unify (or normalize) this Point2 (in place) and return the previous length. Internal computations are done in double precision.
Operators:
Prototype:
float& operator[](int i)
const float& operator[](int i) const
Remarks:
Allows access to x, y using the subscript operator.
Return Value:
A value for i of 0 will return x, 1 will return y.
Prototype:
operator float*()
Remarks:
Returns the address of the Point2.x
Prototype:
Point2 operator-() const
Remarks:
Unary -. Negates both x and y.
Return Value:
A Point2 with -x, -y.
Prototype:
Point2 operator+() const
Remarks:
Unary +. Returns the point unaltered.
Return Value:
Returns the Point2 unaltered.
Prototype:
Point2& operator-=(const Point2&)
Remarks:
Subtracts a Point2 from this Point2.
Return Value:
A Point2 that is the difference between two Point2s.
Prototype:
Point2& operator+=(const Point2&)
Remarks:
Adds a Point2 to this Point2.
Return Value:
A Point2 that is the sum of two Point2's.
Prototype:
Point2& operator*=(float)
Remarks:
Multiplies this Point2 by a floating point value.
Return Value:
A Point2 multiplied by a float.
Prototype:
Point2& operator/=(float)
Remarks:
Divides this Point2 by a floating point value.
Return Value:
A Point2 divided by a float.
Prototype:
Point2 operator-(const Point2&) const
Remarks:
Subtracts a Point2 from a Point2.
Return Value:
A Point2 that is the difference between two Point2's.
Prototype:
Point2 operator+(const Point2&) const
Remarks:
Adds a Point2 to a Point2.
Return Value:
The sum of two Point2's.
Prototype:
float operator*(const Point2&) const
Remarks:
Returns the dot product of two Point2's. This is the sum of both x values multiplied together and both y values multiplied together.
Prototype:
int operator==(const Point2& p) const
Remarks:
Equality operator. Compares two Point2's.
Return Value:
Nonzero if the Point2's are equal; otherwise 0.
The following functions are not methods of class Point2 but are available for use:
Prototype:
Point2 operator*(float, const Point2&)
Point2 operator*(const Point2&, float)
Remarks:
Each returns a Point2 multiplied by a scalar.
Prototype:
Point2 operator/(const Point2&, float)
Remarks:
Returns a Point2 whose x and y members are divided by a scalar.
Prototype:
ostream &operator<<(ostream&, const Point2&)
Remarks:
Formats the Point2 for output as in:
(x, y)
Function:
float Length(const Point2& v)
Remarks:
Returns the length of the Point2, ie:
sqrt(v.x*v.x+v.y*v.y);
Function:
int MaxComponent(const Point2&)
Remarks:
Returns the component with the maximum absolute value. 0=x, 1=y.
Function:
int MinComponent(const Point2&)
Remarks:
Returns the component with the minimum absolute value. 0=x, 1=y.
Function:
Point2 Normalize(const Point2&)
Remarks:
Returns a unit vector. This is a Point2 with each component divided by the point Length().