<< Chapter < Page Chapter >> Page >

Exercises

Exercise 1

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws a horizontalline segment and a vertical line segment representing the x and y axes in a 2D Cartesian coordinate system as shown in Figure 2 .

Cause the origin of your reference frame be at the center of your drawing.

Cause the positive x direction be to the right.

Cause the positive y direction be either up or down according to your choice.

Cause the program to display your name in some manner.

Figure 2 Graphic output from Exercise 1.

Missing image.

Exercise 2

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws x and y axes in a 2DCartesian coordinate system as shown in Figure 3 .

Cause the origin of your reference frame be at the center of your drawing.

Cause the positive x direction be to the right.

Cause the positive y direction be either up or down according to your choice.

Then draw small circles that represent the locations of points at the following coordinates in the reference frame as shown in Figure 3 .

  • x = -30, y = -40
  • x = 30, y = -40
  • x = 30, y = 40

Cause the program to display your name in some manner.

Figure 3 Graphic output from Exercise 2.

Missing image.

Exercise 3

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws xand y axes in a 2D Cartesian coordinate system as shown in Figure 4 .

Cause the origin of your reference frame be at the center of your drawing.

Cause the positive x direction be to the right.

Cause the positive y direction be either up or down according to your choice.

Create six random values in the range from -128 to +127. Use those values as the x and ycoordinates for three points in the 2D reference frame. (The code fragment in Listing 29 shows how to generate random values in the required range in Java.)

Display the six values on a text screen labeled in such a way that it is possible to associate the valueswith the points as shown in Figure 5 .

Draw three small circles that represent the locations of the points.

Draw three line segments that connect the three points in pairs creating the shape of a triangle.

Cause the program to display your name in some manner.

Figure 4 Graphic output from Exercise 3.

Missing image.

Figure 5 . Text output from Exercise 3.
point0X: -55 point0Y: 17point1X: 9 point1Y: -37point2X: 14 point2Y: 62
Listing 29. Code for generating random values in Java.
//Define three randomly located points. Random generator = new Random(new Date().getTime());point0X = (byte)generator.nextInt(); point0Y = (byte)generator.nextInt();point1X = (byte)generator.nextInt(); point1Y = (byte)generator.nextInt();point2X = (byte)generator.nextInt(); point2Y = (byte)generator.nextInt();

Exercise 4

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws three small circles that represent thelocations of points at the following coordinates in a 2D reference frame.

  • point0X = -30
  • point0Y = 0
  • point1X = 30
  • point1Y = 40
  • point2X = 30
  • point2Y = -40

Then draw three line segments that extend from edge-to-edge of your drawing and intersect the threepoints in pairs as shown in Figure 6 .

Cause the origin of your reference frame be at the center of your drawing.

Cause the positive x direction to be to the right.

Cause the positive y direction be either up or down according to your choice.

Cause the program to display your name in some manner.

Figure 6 Graphic output from Exercise 4.

Missing image.

Exercise 5

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws 24 vectors tail-to-tail in alternatingcolors of red, green, and blue as shown in Figure 7 .

The first vector is red.

The length of each vector is 100 pixels.

The direction of the first vector is +7.5 degrees relative to the horizontal.

The direction of each successive vector is increased by 15 degrees.

For example, the directions of the first four vectors are:

  • 7.5
  • 22.5
  • 37.5
  • 52.5

Draw the symbol of your choice to identify the head of each vector.

Draw the axes for a Cartesian coordinate system in the reference frame.

Cause the positive x direction to be to the right.

Cause the positive y direction be either up or down according to your choice.

Cause positive angles to be either clockwise or counter-clockwise according to your choice.

Cause the program to display your name in some manner.

Figure 7 Graphic output from Exercise 5.

Missing image.

Exercise 6

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws24 vectors tail-to-head in alternating colors of red, green, and blue as shown in Figure 8 .

The first vector is red.

The length of each vector is approximately 17 pixels.

Draw the symbol of your choice to identify the head of each vector.

Draw the axes for a Cartesian coordinate system in the reference frame.

Cause the positive x direction to be to the right.

Cause the positive y direction be either up or down according to your choice.

Cause positive angles to be either clockwise or counter-clockwise according to your choice.

Cause the program to display your name in some manner.

Figure 8 Graphic output from Exercise 6.

Missing image.

Exercise 7

Using Java and the game-math library named GM2D02 , or using a different programming environment of your choice, write a program that draws 24 vectors tail-to-head in alternatingcolors of red, green, and blue as shown in Figure 9 .

The first vector is red.

Begin with a length of 24 pixels for the first vector and reduce the length of each successive vector by one pixel.

Draw the symbol of your choice to identify the head of each vector.

Draw the axes for a Cartesian coordinate system in the reference frame.

Cause the positive x direction to be to the right.

Cause the positive y direction be either up or down according to your choice.

Cause positive angles to be either clockwise or counter-clockwise according to your choice.

Cause the program to display your name in some manner.

Figure 9 Graphic output from Exercise 7.

Missing image.

-end-

Questions & Answers

calculate molarity of NaOH solution when 25.0ml of NaOH titrated with 27.2ml of 0.2m H2SO4
Gasin Reply
what's Thermochemistry
rhoda Reply
the study of the heat energy which is associated with chemical reactions
Kaddija
How was CH4 and o2 was able to produce (Co2)and (H2o
Edafe Reply
explain please
Victory
First twenty elements with their valences
Martine Reply
what is chemistry
asue Reply
what is atom
asue
what is the best way to define periodic table for jamb
Damilola Reply
what is the change of matter from one state to another
Elijah Reply
what is isolation of organic compounds
IKyernum Reply
what is atomic radius
ThankGod Reply
Read Chapter 6, section 5
Dr
Read Chapter 6, section 5
Kareem
Atomic radius is the radius of the atom and is also called the orbital radius
Kareem
atomic radius is the distance between the nucleus of an atom and its valence shell
Amos
Read Chapter 6, section 5
paulino
Bohr's model of the theory atom
Ayom Reply
is there a question?
Dr
when a gas is compressed why it becomes hot?
ATOMIC
It has no oxygen then
Goldyei
read the chapter on thermochemistry...the sections on "PV" work and the First Law of Thermodynamics should help..
Dr
Which element react with water
Mukthar Reply
Mgo
Ibeh
an increase in the pressure of a gas results in the decrease of its
Valentina Reply
definition of the periodic table
Cosmos Reply
What is the lkenes
Da Reply
what were atoms composed of?
Moses Reply
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