<< Chapter < Page Chapter >> Page >

Summary

In this module, you learned how to create column matrices using values obtained from sliders.You learned how to create additional column matrices by adding and subtracting the original matrices.

You learned how to display text information about the matrices including whether or not they are equal.

You learned how to display the matrices in a graphical format where each matrix is represented by a displacement vector in a 2D reference frame.

What's next?

In the next module, you will learn:

  • 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 sum of the lengths of vectors.
  • 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.

Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: GAME2302-0120: Visualizing Column Matrices
  • File: Game0120.htm
  • Published: 10/15/12
  • Revised: 02/01/16
Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation :: I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

Complete program listing

A complete listing of the program named ColMatrixVis01 is provided in Listing 8 . The game library named GM2D03 , which is required for compiling and executing this program, wasprovided in the earlier module titled GAME2302-0115: Working with Column Matrices, Points, and Vectors . You can copy it from there.

Listing 8 . Source code for the program named ColMatrixVis01.

/*ColMatrixVis01.java Copyright 2012, R.G.BaldwinThe purpose of this program is to help the student visualize column matrices. Two column matrices are createdusing values obtained from sliders. Two additional column matrices are created by adding and subtracting the original matrices.Mathematical points are created to represent the values in the matrices in a 2D reference frame.Displacement vectors are created for each of the points relative to the origin.The vectors are drawn along with Cartesian coordinate axes in the 2D reference frame.Text output is displayed to show the matrix values as well as whether the two original matrices are equal.Tested using JDK 1.7 under WinXP and Windows 7 *********************************************************/import java.awt.*; import javax.swing.JFrame;import javax.swing.JPanel; import javax.swing.JSlider;import javax.swing.JLabel; import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent; import java.lang.Math;import java.util.*; class ColMatrixVis01{public static void main(String[] args){GUI guiObj = new GUI(); }//end main}//end controlling class ColMatrixVis01 //======================================================//class GUI extends JFrame{ //Specify the horizontal and vertical size of a JFrame// object. int hSize = 450;int vSize = 600; Image osi;//off-screen imageint osiWidth;//off-screen image width int osiHeight;//off-screen image heightMyCanvas myCanvas;//a subclass of Canvas//Panel to contain the sliders and associated labels. private JPanel mainPanel = new JPanel();//Sliders used to produce values for column matrices.private JSlider redSlider0 = new JSlider(); private JSlider redSlider1 = new JSlider();private JSlider greenSlider0 = new JSlider(); private JSlider greenSlider1 = new JSlider();//Storage area for values extracted from sliders. private int red0 = 100;private int red1 = 100; private int green0 = 100;private int green1 = -100; //Object used to erase the off-screen image.private Rectangle rect; GUI(){//constructor//Configure the sliders. redSlider0.setMaximum(100);redSlider0.setMinimum(-100); redSlider0.setMajorTickSpacing(50);redSlider0.setMinorTickSpacing(10); redSlider0.setPaintTicks(true);redSlider0.setPaintLabels(true); redSlider0.setValue(red0);redSlider1.setMaximum(100);redSlider1.setMinimum(-100); redSlider1.setMajorTickSpacing(50);redSlider1.setMinorTickSpacing(10); redSlider1.setPaintTicks(true);redSlider1.setPaintLabels(true); redSlider1.setValue(red1);greenSlider0.setMaximum(100);greenSlider0.setMinimum(-100); greenSlider0.setMajorTickSpacing(50);greenSlider0.setMinorTickSpacing(10); greenSlider0.setPaintTicks(true);greenSlider0.setPaintLabels(true); greenSlider0.setValue(green0);greenSlider1.setMaximum(100);greenSlider1.setMinimum(-100); greenSlider1.setMajorTickSpacing(50);greenSlider1.setMinorTickSpacing(10); greenSlider1.setPaintTicks(true);greenSlider1.setPaintLabels(true); greenSlider1.setValue(green1);//Set the layout manager for the panel that contains// the sliders and the associated labels. mainPanel.setLayout(new GridLayout(2,3));//Add the sliders and associated labels to the panel.mainPanel.add(new JLabel(" Red matrix values")); mainPanel.add(redSlider0);mainPanel.add(redSlider1); mainPanel.add(new JLabel(" Green matrix values"));mainPanel.add(greenSlider0); mainPanel.add(greenSlider1);//Set JFrame size, title, and close operation.setSize(hSize,vSize); setTitle("Copyright 2012, R.G.Baldwin");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create a new drawing canvas and add it to the// center of the JFrame. myCanvas = new MyCanvas();this.getContentPane().add(myCanvas); this.getContentPane().add(mainPanel,BorderLayout.SOUTH); //This object must be visible before you can get an// off-screen image. It must also be visible before // you can compute the size of the canvas.setVisible(true); osiWidth = myCanvas.getWidth();osiHeight = myCanvas.getHeight();//Configure the object that will be used to erase // the off-screen image.rect = new Rectangle( -osiWidth/2,-osiHeight/2,osiWidth,osiHeight);//Create an off-screen image and get a graphics // context on it.osi = createImage(osiWidth,osiHeight); final Graphics2D g2D =(Graphics2D)(osi.getGraphics()); //Translate the origin to the center of the// off-screen image. g2D.translate(osiWidth/2.0,osiHeight/2.0);//Erase the off-screen image.g2D.setColor(Color.WHITE); g2D.fill(rect);//erase the osi//Display the initial values of the column matrices displayColumnMatrices(g2D);//Register a listener on each of the sliders.redSlider0.addChangeListener( new ChangeListener(){public void stateChanged(ChangeEvent e){ //Re-display the column matrices each time the// thumb is moved on the slider. displayColumnMatrices(g2D);}//end stateChanged }//end new ChangeListener);//end addChangeListenerredSlider1.addChangeListener( new ChangeListener(){public void stateChanged(ChangeEvent e){ displayColumnMatrices(g2D);}//end stateChanged }//end new ChangeListener);//end addChangeListener greenSlider0.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent e){displayColumnMatrices(g2D); }//end stateChanged}//end new ChangeListener );//end addChangeListenergreenSlider1.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent e){displayColumnMatrices(g2D); }//end stateChanged}//end new ChangeListener );//end addChangeListener}//end constructor //----------------------------------------------------////The purpose of this method is to // 1. Create two column matrices named redMatrix and// greenMatrix using values obtained from sliders. // 2. Create two more column matrices named blueMatrix// and orangeMatrix by adding and subtracting the red // and green matrices.// 3. Display text information about the matrices // including whether the red and green matrices are// equal. // 4. Create mathematical points in a 2D coordinate// frame that represents the values in the matrices. // 5. Create mathematical displacement vectors that// represent the displacements of each of the points // relative to the origin.// 6. Create and draw graphics objects that represent // each of the mathematical displacement vectors// along with Cartesian coordinate axes for the // 2D reference frame.void displayColumnMatrices(Graphics2D g2D){//Get two values for each matrix from the sliders. red0 = redSlider0.getValue();red1 = redSlider1.getValue(); green0 = greenSlider0.getValue();green1 = greenSlider1.getValue();//Use the slider values to create the two matrices // named redMatrix and greenMatrix.GM2D03.ColMatrix redMatrix = new GM2D03.ColMatrix(red0,red1);GM2D03.ColMatrix greenMatrix = new GM2D03.ColMatrix(green0,green1);//Create two additional matrices by adding and// subtracting the red and green matrices. GM2D03.ColMatrix blueMatrix =redMatrix.add(greenMatrix); GM2D03.ColMatrix orangeMatrix =redMatrix.subtract(greenMatrix);//Display text information about the matrices. System.out.println();//blank lineSystem.out.println("redMatrix = " + redMatrix); System.out.println("greenMatrix = " + greenMatrix);System.out.println("redMatrix equals greenMatrix: " + redMatrix.equals(greenMatrix));System.out.println( "blueMatrix = redMatrix + greenMatrix = " +blueMatrix); System.out.println( "orangeMatrix = redMatrix - greenMatrix = " +orangeMatrix);//Create mathematical points in a 2D coordinate // frame that represent the values in the matrices.// Also create a point that represents the origin. GM2D03.Point origin =new GM2D03.Point(new GM2D03.ColMatrix(0,0)); GM2D03.Point redPoint =new GM2D03.Point(redMatrix); GM2D03.Point greenPoint =new GM2D03.Point(greenMatrix); GM2D03.Point bluePoint = new GM2D03.Point(blueMatrix);GM2D03.Point orangePoint = new GM2D03.Point(orangeMatrix);//Create mathematical displacement vectors that // represent the displacements of each of the points// relative to the origin. GM2D03.Vector redVec =origin.getDisplacementVector(redPoint); GM2D03.Vector greenVec =origin.getDisplacementVector(greenPoint); GM2D03.Vector blueVec =origin.getDisplacementVector(bluePoint); GM2D03.Vector orangeVec =origin.getDisplacementVector(orangePoint);//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 //----------------------------------------------------////The purpose of this method is to draw a pair of // Cartesian coordinate axes onto the// off-screen image. void drawAxes(Graphics2D g2D){//Define four points at the edges of the coordinate // frame and the ends of the axes.GM2D03.Point point0 = new GM2D03.Point( new GM2D03.ColMatrix(-osiWidth/2,0));GM2D03.Point point1 = new GM2D03.Point( new GM2D03.ColMatrix(osiWidth/2,0));GM2D03.Point point2 = new GM2D03.Point( new GM2D03.ColMatrix(0,-osiHeight/2));GM2D03.Point point3 = new GM2D03.Point( new GM2D03.ColMatrix(0,osiHeight/2));//Now define the two lines based on the end points.. GM2D03.Line xAxis = new GM2D03.Line(point0,point1);GM2D03.Line yAxis = new GM2D03.Line(point2,point3); //Now draw a visual manifestation of each line// on g2D. xAxis.draw(g2D);yAxis.draw(g2D);//Repaint the display area myCanvas.repaint();}//end drawAxes //====================================================////This is an inner class of the GUI class. class MyCanvas extends Canvas{//Override the paint() method. This method will be // called when the JFrame and the Canvas appear on the// screen or when the repaint method is called on the // Canvas object.public void paint(Graphics g){ g.drawImage(osi,0,0,this);}//end overridden paint() }//end inner class MyCanvas}//end class GUI //======================================================//

Exercises

Exercise 1

Using Java and the game-math library named GM2D03 , or using a different programming environment of your choice, write a program that usesrandom values to generate two column matrix objects.

Generate two more column matrix objects as the sum and difference of the two original column matrix objects.

Display the two original column matrix objects in red and green and display the sum and difference matrix objects in blue and orange as shown in Figure 5 .

Figure 5 . Graphic output from Exercise 01.

Missing image

-end-

Questions & Answers

what is microbiology
Nyoik Reply
microbiology is the study of micro organisms. this can be multicellular,unicellular & acellular
Janet
what is the difference between DNA/RNA
kanaaLka
DNA is a double stranded molecule while RNA is a single stranded molecule
Lovely
What are antibodies?
Happy Reply
they are immune cells that are released by immune system to fight strangers like microbes
Ahmed
a blood protien produce in response to an counteracting a specific antigen
Pooja
Why salmonella typhi is harmful protozoan?
Saily Reply
because make typhoid that is considered as a food born illness
Ahmed
Name any five modes of transmission.
Happy
what are the scientific names and common names of some microbes
Rich Reply
Staphylococcus aureus - staph Streptococcus pyogenes - strep Botulism - Clostridium botulinum Rocky Mountain spotted fever - Rickettsia rickettsii Diphtheria - Corynebacterium diphtheriae Gonorrhea - Neisseria gonorrhoeae
Tammy
what are the limitations of the Koch's postulate
Naa
how a microorganism growth.
Zubair Reply
Is foetus a parasite to his or her mother? if yes and if no ho
Mashauri Reply
y
Yusri
yes
Yashkin
yes
Zubair
yes it a parasite to the mother because it feeds on the mother for survival
Beatrice
yes
Redwan
no
Elasha
definition of a parasite: an organism that lives in or on an organism of ANOTHER species (its host) and benefits by deriving nutrients at the other's expense
Elasha
no because an organism can inky be a parasite if it causes harm to its HOST. And the fetus does not cause harm to its mother under normal conditions
aliyu
yes
Naa
what is biosensor in microbiology
Raja Reply
What are biosensor
Raja
what's are biosensor
Raja
what is microbiology defination
Rinku Reply
microbiology is the study of small or manuit organisms which cannot be seen with our nacked eyes unless with the aid of the microscope
Brandina
is the study of living organisms which are not directly visible to a direct eye but can only be seen under a microscope
Ipa
ok
Ipa
microbiology is the study of living organisms of microscopic size it is also the study of micro organisms with their form structure reproduction psychology metabolism and classification
Priyanka
ok
Aminu
Microbiology are the study of microorganisms either microscopic or sub microscopic creaters mainly unicellulars, multicellulars and subcellulars. Such as protozoa,bacteria and viruses.
Rana
it is the biological study of viruses, fungi, protozoa, bacteria which in collective name are called micro organisms, unlike microscopic organisms being invisible, that requires a magnifications with the help of a microscope.
Mohamed
what are the importances of Microbiology?
Erick Reply
don't know
SINGLE
we obtained the insulin from the bacteria. and some microorganisms are decomposer in ecosystems.
Zubair
nitrogen in the air is fixed into the soil by microbes example is nitrobactor
Matilda
yes
Zubair
how a weak immune region where microorganisms attack easily?
Zubair Reply
with examples differentiate gram positive from gram negative bacteria
Mary Reply
Differentiate gram positive from gram negative
Mary
I have no idea
Zubair
hello
Kuonain
and example of gram negative is E. coli
Pooja
gram positive stain purple when subjected to gram stain whilst gram positive bacterial has thick wall composed of peptidoglycan
Matilda
ok
Zubair
what is a process of gene expression in eukaryotes ?
Nayyab Reply
pls help us with the answer
Abdussalam
spontaneous generation means
Siddhi Reply
hiii
Siddhi
Hello
eman
So, what's next 😂
eman
I have a problem with Micro
eman
I studying things and see question Some thing else
eman
Can u help me, please
eman
What i havta do
eman
firsfall when you studying understand things...
Siddhi
good afternoon dear Friends
yaya
Greeting to everyone in here.
Manka
There is a problem. I need a diagram of a virus with it functions.
Manka
structure of bacterial
Kuyiba
gghhhh
Zubair
group plz i need help in microbio
Kuonain
it really difficult fr me
Kuonain
kashur cha kah
suhail
sorry now I read in class 8th but I can help u
Zubair
Me too. It's very difficult for me
Angela
rod shape
Priyanka
helical
Priyanka
Hello
esike
spherical
Priyanka
peomorphic
Priyanka
I am ryt or not
Priyanka
hi
suhail
hello
DIPTI
Are we together pls what's the topic for the day?
esike
what is innate
Lizzy
innate means natural
Pooja
the genetic makeup of an individual
Matilda
pls i need the common names for the following parasites..ENTEROBIUS VERMICULARIS,NECATOR AMERICANUS,ASCARIES LUMBRICOIDES,TRICHURIS TRICHIURA,TRICHOMONAS VAGINALIS,GIARDIA LAMBLIA,ENTAMOEBA HISTOLYTICA,SCHISTOSOMA MANSONI,SCHISTOSOMAHEMATOBIUM,STROGYLOIDES STERCORALIS,AND TRAPANOSOMA BRUCI GAMBIENSE
timothy
ENTEROBIUS VERMICULARIS and STROGYLOIDES STERCORALIS have the same common name which is pin worm and thread worm
Chinedu
I didn't find the common names for TRICHOMONAS VAGINALIS, GIARDIA LAMBLIA, ENTAMOEBA HISTOLYTICA, TRYPANOSOMA BRUCEI GAMBIENSE
Chinedu
NECATOR AMERICANUS - New world hookworm ASCARIS LUMBRICOIDES- Ascarid TRICHURIS TRICHIURA- Whip worm
Chinedu
Hi guys
Chinedu
Why are myeloblasts not present in the bloodstream?
Chinedu
thank u
Dasaah
is blood from capillary puncture suitable for hormonal assays
NANCY Reply
Direct this question to a hematologist for a better answer please.
LAFIA
In most cases the blood is necessary but it's limited from my own Analysis
Lee
u can do but it depends on your sampling blood its enev or not
Ali
Control indications of cipro, doxicyclin, setracyclin, cloxacyclin, erythromycin
Oslen Reply
oo
babinthe
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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