<< Chapter < Page | Chapter >> Page > |
Listing 12 . Source code for the program named ColMatrixEquals01.
/*ColMatrixEquals01.java
Copyright 2008, R.G.BaldwinRevised 02/08/08
The purpose of this program is to confirm the behavior ofthe equals methods of the GM2D03.ColMatrix, Point, and
Vector classes.Tested using JDK 1.6 under WinXP.
*********************************************************/public class ColMatrixEquals01{
public static void main(String[]args){
GM2D03.ColMatrix matA =new GM2D03.ColMatrix(1.5,-2.6);
GM2D03.ColMatrix matB =new GM2D03.ColMatrix(1.5,-2.6);
GM2D03.ColMatrix matC =new GM2D03.ColMatrix(1.500001,-2.600001);
GM2D03.ColMatrix matD =new GM2D03.ColMatrix(1.50001,-2.60001);
System.out.println(matA.equals(matA));System.out.println(matA.equals(matB));
System.out.println(matA.equals(matC));System.out.println(matA.equals(matD));GM2D03.Point pointA = new GM2D03.Point(
new GM2D03.ColMatrix(15.6,-10.11));GM2D03.Point pointB = new GM2D03.Point(
new GM2D03.ColMatrix(15.6,-10.11));GM2D03.Point pointC = new GM2D03.Point(
new GM2D03.ColMatrix(-15.6,10.11));System.out.println(/*Blank line*/);
System.out.println(pointA.equals(pointA));System.out.println(pointA.equals(pointB));
System.out.println(pointA.equals(pointC));GM2D03.Vector vecA = new GM2D03.Vector(new GM2D03.ColMatrix(15.6,-10.11));
GM2D03.Vector vecB = new GM2D03.Vector(new GM2D03.ColMatrix(15.6,-10.11));
GM2D03.Vector vecC = new GM2D03.Vector(new GM2D03.ColMatrix(-15.6,10.11));
System.out.println(/*Blank line*/);System.out.println(vecA.equals(vecA));
System.out.println(vecA.equals(vecB));System.out.println(vecA.equals(vecC));
}//end main}//end ColMatrixEquals01 class
Listing 13 . Source code for the program named DisplacementVector01. |
---|
/*DisplacementVector01.java
Copyright 2008, R.G.BaldwinRevised 02/08/08
The purpose of this program is to confirm the behavior ofthe getDisplacementVector method of the GM2D03.Point
class.Tested using JDK 1.6 under WinXP.
*********************************************************/public class DisplacementVector01{
public static void main(String[]args){
GM2D03.Point pointA = new GM2D03.Point(new GM2D03.ColMatrix(6.5,-9.7));
GM2D03.Point pointB = new GM2D03.Point(new GM2D03.ColMatrix(-6.0,9.0));System.out.println(pointA.getDisplacementVector(
pointB));System.out.println(pointB.getDisplacementVector(
pointA));}//end main
}//end DisplacementVector01 class |
Listing 14 . Source code for the program named ColMatrixAddSubtract01. |
---|
/*ColMatrixAddSubtract01.java
Copyright 2008, R.G.BaldwinRevised 02/08/08
The purpose of this program is to confirm the behavior ofthe add and subtract methods of the GM2D03.ColMatrix
class.Tested using JDK 1.6 under WinXP.
*********************************************************/public class ColMatrixAddSubtract01{
public static void main(String[]args){GM2D03.ColMatrix matrixA =
new GM2D03.ColMatrix(3.14,-6.01);GM2D03.ColMatrix matrixB =
new GM2D03.ColMatrix(-14.0,-12.2);GM2D03.ColMatrix matrixC = matrixA.add(matrixB);GM2D03.ColMatrix matrixD = matrixC.subtract(matrixA);
GM2D03.ColMatrix matrixE = matrixD.subtract(matrixB);System.out.println(matrixC);System.out.println(matrixD);
System.out.println(matrixE);}//end main
}//end class ColMatrixAddSubtract01 |
Using Java and the game-math library named GM2D03 , or using a different programming environment of your choice, write a program that createsfour column matrix objects using the following names and values:
Then use matrix addition and subtraction to compute and display the values of the following matrices:
Finally, test matE and matF for equality and display the result, replacing the question mark with either true or false..
Cause the program to display your name in some manner.
My version of the program produces the text output shown in Figure 4 , and you should use that as a display template.
Figure 4 Text output from Exercise 1. |
---|
Prof. Baldwin
matE = 3.0,-5.2matF = 3.0,-5.200000000000001
matE equals matF: ? |
Using Java and the game-math library named GM2D03 , or using a different programming environment of your choice, write a program that createsand displays (in text form) three vectors having the names and values shown in Figure 5 .
Cause your program to test vecA for equality, first against vecB , and then against vecC , and display the results of the tests in place of the question marks shown in Figure 5 .
Figure 5 . Text output from Exercise 2. |
---|
Prof. Baldwin
vecA = -1.5,2.6vecB = -1.5,2.6
vecC = 8.5,-13.4vecA equals vecB: ?
vecA equals vecC: ? |
Using Java and the game-math library named GM2D03 , or using a different programming environment of your choice, write a program that createsand displays four column matrices having the names and values shown in Figure 6 .
Use the first two matrices to create a displacement vector named dispVecE and display its value in place of the question marks in Figure 6 .
Use the last two matrices to create another displacement vector named dispVecF and display its value in place of the question marks in Figure 6 .
Test dispVecE and dispVecF for equality and display the result of the test in place of the final question mark in Figure 6 .
Figure 6 . Text output from Exercise 3. |
---|
Prof. Baldwin
matA = 1.5,-2.6matB = -1.5,2.6
dispVecE = ?,?matC = 8.5,-13.4
matD = 5.5,-8.2dispVecF = ?,?
dispVecE equals dispVecF: ? |
-end-
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?