# 1.9 Game 2302-0125: vector addition  (Page 2/18)

 Page 2 / 18

## Preview

In this module, I will present and explain several updates to the game-math library. In addition, I will present and explain five sampleprograms that illustrate the use of the new features of the library.

I will also provide exercises for you to complete on your own at the end of the module. The exercises will concentrate on the material that you have learnedin this module and previous modules.

## Discussion and sample code

The game-math library was updated and the name was changed to GM2D04 in preparation for this module. Much of the code in the updated library remains unchanged. I explained that code in the previousmodules and I won't repeat that explanation in this module. I will concentrate on explaining the modifications that I made to the library inthis module.

## The game-math library named GM2D04

A complete listing of the library program is provided in Listing 19 near the end of the module.

This update added the following new capabilities to the library:

• GM2D04.Vector.add - Adds this Vector object to a Vector object received as an incoming parameter and returns the sum as a new Vector object.
• GM2D04.Vector.getLength - Returns the length of a Vector as type double .
• GM2D04.Point.addVectorToPoint - Adds a Vector object to a Point object returning a new Point object.

These three new methods are presented in Listing 1 , Listing 2 , and Listing 3 below. These methods are so simple that no explanation should be required foryou to understand them.

Listing 1 . The add method of the GM2D04.Vector class.
```//Adds this vector to a vector received as an incoming // parameter and returns the sum as a vector.public GM2D04.Vector add(GM2D04.Vector vec){ return new GM2D04.Vector(new ColMatrix(vec.getData(0)+vector.getData(0), vec.getData(1)+vector.getData(1)));}//end add```
Listing 2 . The getLength method of the GM2D04.Vector class.
```//Returns the length of a Vector object. public double getLength(){return Math.sqrt( getData(0)*getData(0) + getData(1)*getData(1));}//end getLength```
Listing 3 . The addVectorToPoint method of the GM2D04 class.
```//Adds a Vector to a Point producing a new Point. public GM2D04.Point addVectorToPoint(GM2D04.Vector vec){ return new GM2D04.Point(new GM2D04.ColMatrix(getData(0) + vec.getData(0), getData(1) + vec.getData(1)));}//end addVectorToPoint```

Simple but powerful

Although these new methods are individually very simple, when combined with the other methods in the library, they significantly increase the power of thelibrary. For example, in the next module I will show you that the library in its current form supports translation and animation.

I will illustrate the use of these new methods in the sample programs that follow.

This program illustrates the addition of two and then three vectors. It also illustrates the head-to-tail rule described by Kjell. A complete listing of the program is provided in Listing 20 near the end of the module.

Screen output from the program named VectorAdd01

how can chip be made from sand
is this allso about nanoscale material
Almas
are nano particles real
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
no can't
Lohitha
where is the latest information on a no technology how can I find it
William
currently
William
where we get a research paper on Nano chemistry....?
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
has a lot of application modern world
Kamaluddeen
yes
narayan
what is variations in raman spectra for nanomaterials
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
what about nanotechnology for water purification
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Got questions? Join the online conversation and get instant answers!