<< Chapter < Page Chapter >> Page >

The source code for the getLength method is shown in Listing 2 . This code computes the length of the vector as the square root of the sum of thesquares of the X and Y components of the vector. Other than that code, there is no code in this program that warrants further explanation.

You can view a complete listing of the program in Listing 23 near the end of the module.

The program named VectorAdd04

This program illustrates the addition of a Vector object to a Point object producing a new Point object. Both points and the vector are drawn on the screen as shown in Figure 7 .

Figure 7 Screen output from the program named VectorAdd04.

Missing image.

The only thing that is new in this program is the call to the new addVectorToPoint method of the GM2D04.Point class to add the vector to the point producing a new point.

The source code for the addVectorToPoint method is shown in Listing 3 . You can view a complete listing of the program in Listing 24 near the end of the module.

A very powerful capability

Don't be fooled by the apparent simplicity of the addVectorToPoint method. The ability to add a vector to a point provides a powerful new capability to the game-math library. As you will see in the next module, thiscapability makes it possible not only to translate geometrical objects from one location in space to another, but also makes it possible to animate geometricalobjects.

Documentation for the GM2D04 library

Click here to download a zip file containing standard javadoc documentation for the library named GM2D04 . Extract the contents of the zip file into an empty folder and open the filenamed index.html in your browser to view the documentation.

Although the documentation doesn't provide much in the way of explanatory text (see Listing 19 and the explanations given above) , the documentation does provide a good overview of the organization and structure of the library. You may find it helpful in that regard.

Homework assignment

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

The homework assignment for the next module is to study the Kjell tutorial through Chapter 5 - Vector Direction .

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 programs

I encourage you to copy the code from Listing 19 through Listing 24 . Compile the code and execute it in conjunction with the game-math library provided in Listing 19 . Experiment with the code, making changes, and observing the results of your changes. Make certain that youcan explain why your changes behave as they do.

Summary

In this module you learned

  • How to add two or more vectors
  • About the head-to-tail rule in vector addition
  • About the vector addition parallelogram
  • About the relationship between the length of the sum of vectors and the lengths of the individual vectors in the sum
  • How to add a vector to a point
  • How to get the length of a vector
  • How to represent an object in different coordinate frames

Questions & Answers

calculate molarity of NaOH solution when 25.0ml of NaOH titrated with 27.2ml of 0.2m H2SO4
Gasin Reply
what's Thermochemistry
rhoda Reply
the study of the heat energy which is associated with chemical reactions
Kaddija
How was CH4 and o2 was able to produce (Co2)and (H2o
Edafe Reply
explain please
Victory
First twenty elements with their valences
Martine Reply
what is chemistry
asue Reply
what is atom
asue
what is the best way to define periodic table for jamb
Damilola Reply
what is the change of matter from one state to another
Elijah Reply
what is isolation of organic compounds
IKyernum Reply
what is atomic radius
ThankGod Reply
Read Chapter 6, section 5
Dr
Read Chapter 6, section 5
Kareem
Atomic radius is the radius of the atom and is also called the orbital radius
Kareem
atomic radius is the distance between the nucleus of an atom and its valence shell
Amos
Read Chapter 6, section 5
paulino
Bohr's model of the theory atom
Ayom Reply
is there a question?
Dr
when a gas is compressed why it becomes hot?
ATOMIC
It has no oxygen then
Goldyei
read the chapter on thermochemistry...the sections on "PV" work and the First Law of Thermodynamics should help..
Dr
Which element react with water
Mukthar Reply
Mgo
Ibeh
an increase in the pressure of a gas results in the decrease of its
Valentina Reply
definition of the periodic table
Cosmos Reply
What is the lkenes
Da Reply
what were atoms composed of?
Moses Reply
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