<< Chapter < Page Chapter >> Page >

Produce a graphical representation of the displacement vectors

Listing 7 produces and displays a graphical representation of each of the four displacement vectors as shown in Figure 1 .

Listing 7 . Produce a graphical representation of the displacement vectors.
//The remaining code is used to create and draw // graphical objects.//Erase the off-screen image g2D.setColor(Color.WHITE);g2D.fill(rect);//Set the line thickness so that the vectors will be // drawn with a heavy line.g2D.setStroke(new BasicStroke(3));//Draw the four vectors with their tails at the // origin.g2D.setColor(Color.BLUE); blueVec.draw(g2D,origin);g2D.setColor(Color.ORANGE);orangeVec.draw(g2D,origin);g2D.setColor(Color.RED); redVec.draw(g2D,origin);g2D.setColor(Color.GREEN);greenVec.draw(g2D,origin); //Draw the axes with thinner lines.g2D.setStroke(new BasicStroke(1)); g2D.setColor(Color.BLACK);drawAxes(g2D);}//end displayColumnMatrices

There is very little new code in Listing 7 , and the new code that is there should be easy to understand.

Analysis of results

The head of the red vector in Figure 1 represents the two values in the column matrix known as redMatrix . The length and direction of that vector shows how it relates to a column vector having two elements, eachwith a value of zero.

Similarly, the head of the green vector in Figure 1 represents the two values in the column matrix known as greenMatrix .

The head of the blue vector represents the two values in the column matrix known as blueMatrix , which was created by adding the red and green matrices. In case you haven't noticed, a line drawn from thehead of the red vector to the head of the blue vector would have the same length and direction as the green vector. This will come up again in afuture module when we discuss the vector addition parallelogram.

The head of the orange vector represents the two values in the column matrix know as orangeMatrix , which was created by subtracting the green matrix from the red matrix. Again, a line drawn from the head of the redvector to the head of the orange vector would have the same length and opposite direction as the green vector.

Homework assignment

The homework assignment for this module was to study the Kjell tutorial through Chapter 3 - Vector Addition . That is also the homework assignment for the next module.

In addition to studying the Kjell material, you should read at least the next two modules in this collection and bring your questions about that material tothe next classroom session.

Finally, you should have begun studying the physics material at the beginning of the semester and you should continue studying one physics moduleper week thereafter. You should also feel free to bring your questions about that material to the classroom for discussion.

Run the program

I encourage you to copy the code from Listing 8 . Compile the code and execute it in conjunction with the game-math library named GM2D03 . The source code for that library was provided in the earlier module titled GAME2302-0115: Working with Column Matrices, Points, and Vectors and you can copy it from there.. Experiment with the code, making changes, and observing the results of your changes. Make certainthat you can explain why your changes behave as they do.

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