<< Chapter < Page Chapter >> Page >
Listing 9 . Draw vecB in GREEN head-to-tail with vecA.
g2D.setColor(Color.GREEN); vecB.draw(g2D,new GM2D04.Point(new GM2D04.ColMatrix(vecA.getData(0),vecA.getData(1))));

Draw sumOf2 in MAGENTA with its tail at the origin

Listing 10 creates a visual manifestation of the sumOf2 object with its tail at the origin as shown by the magenta vector in Figure 1 .

(In case you don't recognize the name of the color magenta, it looks similar to violetor purple. As mentioned earlier, it is somewhat longer than the red vector)

More correctly, Listing 10 draws the sumOf2 object with its tail coinciding with the tail of vecA . I elected to position the tails of the two vectors at the origin to keep the code a little simpler.

Listing 10 . Draw sumOf2 in MAGENTA with its tail at the origin.
g2D.setColor(Color.MAGENTA); sumOf2.draw(g2D,new GM2D04.Point(new GM2D04.ColMatrix(0.0,0.0)));

The head-to-tail rule

We have just illustrated a very important rule that can make it much easier to visualize the results of vector addition. It is often called the head-to-tail rule.

If you add two or more vectors to produce a sum vector, and then draw the vectors that were included in the sum with the tail of one vector coincidingwith the head of another vector, (as illustrated by the red and green vectors in Figure 1 ) , the head of the last vector that you draw will be positioned at some particular point in space.

If you then draw the vector that represents the sum vector with its tail coinciding with the tail of the first vector that you drew, its head willcoincide with the head of the last vector that you drew as shown by the magenta vector in Figure 1 .

The tail of the magenta vector coincides with the tail of the red vector, and the head of the magenta vector coincides with the head ofthe green vector.

(It doesn't matter whether or not the coinciding tails are drawn at the origin.)

Furthermore, this rule will hold regardless of the number of vectors included in the sum.

Extending the example to three vectors

Listing 11 extends this example to three vectors.

Listing 11 . Extending the example to three vectors.
//Now define another vector and add it to vecA and // vecB.GM2D04.Vector vecC = new GM2D04.Vector( new GM2D04.ColMatrix(30,-150));//Draw vecD in BLUE with its tail positioned at the// sum of vecA and vecB g2D.setColor(Color.BLUE);vecC.draw(g2D,new GM2D04.Point(new GM2D04.ColMatrix( sumOf2.getData(0),sumOf2.getData(1))));//Define a vector as the sum of vecA, vecB, and vecCGM2D04.Vector sumOf3 = (vecA.add(vecB)).add(vecC); //Draw sumOf3 in BLACK with its tail at the origin.g2D.setColor(Color.BLACK); sumOf3.draw(g2D,new GM2D04.Point(new GM2D04.ColMatrix(0.0,0.0))); }//end drawOffScreen

You should understand this code

By now, you should have no difficulty understanding the code in Listing 11 . The only tricky thing that I would call your attention to is the syntax of thecode that adds the three vectors shown below for emphasis.

GM2D04.Vector sumOf3 = (vecA.add(vecB)).add(vecC);

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
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