<< Chapter < Page Chapter >> Page >

The code in Listing 4 produced the text in Figure 2 and Figure 4 .

Displaying information about the matrices

There are many ways to display information about matrices, including the simple text displays shown in Figure 2 and Figure 4 . The problem with text displays is that you have to study the numbers in detail to get a feel for anindividual matrix and a feel for the relationships among two or more matrices.

A graphical display can often convey that sort of information at first glance. Then you are faced with a decision as to how you should construct thegraphical display.

For the case of a column matrix with two elements, a good approach is to let the two matrix values represent the x and y coordinate values of a mathematicalpoint in a 2D reference frame and then to display information about the point. That is the approach taken by this program.

Create mathematical points

Listing 5 creates mathematical points in a 2D coordinate frame that represent the values in the matrices. Listing 5 also creates a point that represents the origin.

Listing 5 . Create mathematical points.
//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);

Displaying the points

Once you have the points, you then need to decide what might be the best format in which to display them. One obvious approach would simply be todraw small symbols in the 2D coordinate frame that represent the locations of the points.

However, in most real-world situations, we tend to evaluate the value of something relative to a value of zero.

(There are, however, exceptions to this rule. For example, when considering the temperature in Celsius, we tend to evaluate the temperaturerelative to zero degrees Celsius, which is the freezing point of water. On a Fahrenheit scale, however, we tend to evaluate temperature relative to32-degrees F, which is the freezing point of water. )

Displacement vectors

A good way to get a feel for the location of a mathematical point in a 2D reference frame is to compare the location of that point with the location of adifferent point through the use of a displacement vector. That is the approach taken by this program with the anchor point being the point at the origin againstwhich all other points are compared.

Listing 6 creates mathematical displacement vectors that represent the displacements of each of the four points created earlier relative to the origin.

Listing 6 . Create mathematical displacement vectors.
//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);

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