Project 81: Bound Vectors

Intro Problem: Suppose your house is at coordinate (-6, 6) on a city grid.  You walk to a store that is at coordinate (-3, 2) on the city grid.

How far did you walk and what is the direction?

We can use something called a bound vector to help us determine this.

The initial point of the vector above is (-6, 6).  The terminal point is (-3, 2).  If the vertex were placed with the initial point at the origin (0, 0) the terminal point would be (3, -4).  We can express the vector above as <3, -4> and we call this a bound vector.  The magnitude would be 5 and the direction would be 306.87 degrees (as an angle from 0 to 360 degrees).


Project 81: Variables 'x1', 'y1', 'x2', 'y2' have been initialized.  These values represent the x and y values of the initial and terminal points of a vector.  There are also working methods called getMagnitude and getDirection.

x1 is -6 in the example above.

y1 is 6 in the example above.

x2 is -3 in the example above.

y2 is 2 in the example above.

getMagnitude(x,y) returns the magnitude of the vector <x,y>

getDirection(x,y) returns the direction of the vector <x,y> expressed as an angle in degrees from 0 to 360.

Task: Appropriately initialize the values for 'x', 'y', 'mag', and 'dir'.

x and y represent the components of the bound vector.

mag and dir represent the magnitude and direction of the vector given.


Note: The following trig methods are available.

cosine(x) 

sine(x) 

tangent(x) 

cosineInverse(x)

sineInverse(x)

tangentInverse(x)

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0