<< 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

Exercises

Exercise 1

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:

  • matA = (1.5,-2.6)
  • matB = (1.5,-2.6)
  • matC = (8.5,-13.4)
  • matD = (5.5,-8.2)

Then use matrix addition and subtraction to compute and display the values of the following matrices:

  • matE = matA + matB
  • matF = matC - matD

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: ?

Exercise 2

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: ?

Exercise 3

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-

Questions & Answers

what are components of cells
ofosola Reply
twugzfisfjxxkvdsifgfuy7 it
Sami
58214993
Sami
what is a salt
John
the difference between male and female reproduction
John
what is computed
IBRAHIM Reply
what is biology
IBRAHIM
what is the full meaning of biology
IBRAHIM
what is biology
Jeneba
what is cell
Kuot
425844168
Sami
what is biology
Inenevwo
what is cytoplasm
Emmanuel Reply
structure of an animal cell
Arrey Reply
what happens when the eustachian tube is blocked
Puseletso Reply
what's atoms
Achol Reply
discuss how the following factors such as predation risk, competition and habitat structure influence animal's foraging behavior in essay form
Burnet Reply
cell?
Kuot
location of cervical vertebra
KENNEDY Reply
What are acid
Sheriff Reply
define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what is vertibrate
Jeneba
what's cornea?
Majak Reply
what are cell
Achol
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask