<< Chapter < Page Chapter >> Page >

The actionPerformed method in the program named DotProd2D01

The beginning of the actionPerformed method is shown in Listing 4 . This method is called to respond to a click on the OK button shown in Figure 14 .

Listing 4 . The actionPerformed method in the program named DotProd2D01.
public void actionPerformed(ActionEvent e){ //Create two ColMatrix2D objects.GM02.ColMatrix2D matrixA = new GM02.ColMatrix2D( Double.parseDouble(colMatA0.getText()),Double.parseDouble(colMatA1.getText()));GM02.ColMatrix2D matrixB = new GM02.ColMatrix2D( Double.parseDouble(colMatB0.getText()),Double.parseDouble(colMatB1.getText()));//Compute the dot product. double dotProd = matrixA.dot(matrixB);

Listing 4 begins by instantiating a pair of GM02.ColMatrix2D objects using data provided by the user in the top four fields shown in Figure 14 .

Then Listing 4 calls the dot method on the object referred to by matrixA , passing the object referred to by matrixB as a parameter. The dot method computes the dot product of the two column matrix objects, returning the result as type double .

Format the dot product value for display in the GUI

In some cases, the format of the returned value is not very suitable for display in the lower-left field in Figure 14 . For example, if the value is very small, it is returned in an exponential notation requiring a large numberof digits for display. Similarly, sometimes the dot-product value is returned in a format something like 0.33333333 requiring a large number ofdigits to display.

Listing 5 formats the dot product value to make it suitable for display in the text field in Figure 14 . (There may be an easier way to do this, but I didn't want to take the time to figure out what it is.)

Listing 5 . Format the dot product value for display in the GUI.
//Eliminate exponential notation in the display. if(Math.abs(dotProd)<0.001){ dotProd = 0.0;}//end if//Convert to four decimal digits and display. dotProd =((int)(10000*dotProd))/10000.0;dotProduct.setText("" + dotProd); }//end actionPerformed

Eliminate exponential format and format to four decimal digits

Listing 5 begins by simply setting small values that are less than 0.001 to 0.0 to eliminate the exponential format for very small, non-zero values.

Then Listing 5 executes some code that formats the dot product value to four decimal digits. I will leave it as an exercise for the student to decipherhow this code does what it does.

I recommend that you try it

I recommend that you plug a few values into the input fields, click the OK button, and use your calculator to convince yourself that the program properlyimplements the 2D dot product equation shown earlier .

That concludes the discussion of the program named DotProd2D01 .

The program named DotProd2D02

To understand this program, you need to understand the material in the Kjell tutorial through Chapter 9, The Angle Between Two Vectors .

This program allows the user to experiment with the dot product and the angle between a pair of GM02.Vector2D objects.

A screen shot of the output from this program is shown in Figure 3 . The GUI shown in Figure 3 is provided to allow the user to enter four double values that define each of two GM02.Vector2D objects. The GUI also provides an OK button as well as two text fields used for display of computed results.

Questions & Answers

the diagram of the digestive system
Assiatu Reply
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
what is cell divisoin?
Aron Reply
Diversity of living thing
ISCONT
what is cell division
Aron Reply
Cell division is the process by which a single cell divides into two or more daughter cells. It is a fundamental process in all living organisms and is essential for growth, development, and reproduction. Cell division can occur through either mitosis or meiosis.
AI-Robot
What is life?
Allison Reply
life is defined as any system capable of performing functions such as eating, metabolizing,excreting,breathing,moving,Growing,reproducing,and responding to external stimuli.
Mohamed
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