This section gives a description of the methods in Point3, Vec3, Triangle and Matrix classes. The static relationships between the classes are shown in Fig. A.1.
Fig. A.1 Relationships between geometry classes
Point3 Class
Description:
The data members of the class store the coordinates of a point. For programming convenience, the coordinates are declared as public, so that they can be directly accessed without the need for getter methods. The fourth component _h is initialized to 1 for points and 0 for vectors. This component is not used for computing the norm, scalar product, and other operations such as addition, subtraction and negation.
The static field EPS is a threshold used for checking if a floating point value is close enough to zero. Its value is set to 1.E-6.
Description:
The first constructor sets the values of x, y, z coordinates using its arguments. The h value is initialized separately to a default value 1.0. The second no-argument constructor initializes a point to the origin.
Description:
This method computes the distance to a point from the origin or the length of a vector.
Description:
The add method adds the x, y, z coordinates of the current point with the corresponding coordinate values of p, and produces a new point. The h coordinate values are not added. The resulting point is assigned an h value 1.0. This method is overridden in the subclass Vec3 which sets the h value to 0. The subtract method similarly subtracts the coordinates of p from that of the current point and produces a vector originating at p.
Description:
This method negates the x, y, z coordinates of the current point. The h coordinate value is not negated.
Description:
This method scales the x, y, z coordinates of the current point by the constant factor c, and produces a new point. The resulting point is assigned an h value 1.0.
Description:
This method converts the current point to standard form by applying the transformation: (x, y, z, h) ) (x/h, y/h, z/h, 1), provided h ^ 0.
Description:
This method prints the x, y, z, h coordinates of the current point or vector.
Vec3 Class
The Vec3 class is a subclass of Point3.
Description:
The static field RADTODEG stores the multiplication factor (= n/180) for conversion from radians to degrees.
The static fields X_AXIS, Y_AXIS, Z_AXIS store respectively the orthogonal basis vectors (1, 0, 0), (0, 1, 0) and (0, 0, 1).
Description:
The constructors invoke the base class constructors and additionally set the value of _h to 0.
Description:
The dot method returns the dot product of the current vector and v. The cross method returns a vector as the result of the cross product between the current vector and v.
Description:
The method converts the current vector to a unit vector by dividing its components by the length of the vector.
Description:
The method computes the reflection of the current vector with respect to n using the formula in Eq. 2.5.
Description:
The method angle first converts the current vector and the input vector v to unit vectors, and then computes the angle between them using the inverse cosine of the dot product of the two vectors. The value is returned in degrees in the range [0,180]. The method angle2 uses both dot and cross products to compute the angle using the formula 6 = tan_1(|u x v|, u • v). The singedAngle method uses Eq. 2.6. to compute the signed angle between the current vector and v with respect to a given view direction w.
Triangle Class
Description:
The data members of the class store references to the three vertices of a triangle.
Description:
The non-default constructor requires three references to objects of the Point3 class. Methods of the class use these points as vertices of the triangle.
Description:
The method area computes the area of the current triangle using the cross product of vectors along two edges as given in Eq. 2.3. The method signedArea2D returns the area of the triangle which has a negative sign if the angle between the normal direction and the z-axis is greater than 90°. The function signedArea3D uses a similar approach by using a user specified vector w instead of the z-axis (Eq. 2.8).
Description:
This method computes the barycentric coordinates of the point p with respect to the current triangle using area ratios as given in Eq. 2.48.
Description:
A point p and a triangle t containing p are given. This method computes the image of p in the current triangle as shown in Fig. 2.12.
Description:
This function uses barycentric coordinates to determine if a point p lies within and on the plane of the current triangle.
Description:
This method returns a point computed using the bilinear interpolation formula in Eq. 2.45. The arguments k1 and k2 must satisfy the condition that k1, k2, and k1 C k2, all have values in the range [0, 1].
Description:
This method draws the current triangle using OpenGL functions.
Matrix Class
Description:
The Matrix class represents the data structure for a 4 x 4 matrix, with its values stored in the two-dimensional array _v.
Description:
The default constructor initializes the matrix with the identity matrix. The second constructor initializes the matrix using a two-dimensional array of values. The values are stored in row-major order. The third constructor forms the matrix using three vectors u, v, w as the first three columns of the matrix. The last column has values 0, 0, 0, 1.
Description:
This method resets the current matrix to the identity matrix.
Description:
This is a getter method that returns the value of _v[i][j].
Description:
This is a setter method that replaces the value of _v[i][j] with value.
Description:
The method transpose modifies the current matrix by replacing it with its transpose. Similarly inverse replaces the current matrix with its inverse, provided the matrix is invertible. If the determinant of the current matrix is 0, it is not changed.
Description:
This method returns a new point computed by pre-multiplying the point p by the current matrix.
Description:
Often it is required to keep a copy of the current matrix before computing its transpose or inverse. This method returns a reference to a new matrix object that contains the same values as the current matrix.
Description:
This method prints the values of the current matrix in 4 x 4 format.