You can also get the files using the command:
cp /home/cheung/teaching/web/170/Projects/hw6/Handouts/* ~/cs170/hw6
In the remainder of the homework description, I will assume that you have saved these file in your ~/cs170/hw6 directory.
Graphically, it can be represented by an arrow:
| 4 + | | 3 + + (2, 3) | / | / 2 + / | / | / 1 + / | / |/ 0 +----+----+----+----+----+---- 0 1 2 3 4 5 The point (0,0) is called the "origin" |
The length of this vector can be computed as (using Pythagoras' formula):
__________ _____ \ / \ / \/ 2*2 + 3*3 = \/ 13 = approximately 3.605551275
This is very difficult to draw - conceptually, this is an arrow whose tail end point is on the origin and the tip ends at: 2 units to the east, 4 units to the north and 6 unit up (above the ground)
double[] A; A = new double[3]; A[0] = 2; A[1] = 4; A[2] = 6; |
In this assignment, we will write a Vector class that you can use to represent three-dimensional vectors (i.e., a vector has 3 indices).
The representation must use a one-dimensional array of doubles - and the size of the array is 3. (Look inside the file Vector.java - I have already defined the array variable; you need to initialize it !).
The norm of a vector (x, y, z) is:
Math.sqrt( x*x + y*y + z*z )
For example: if the vector is (2, 4, 6), then its norm is:
Math.sqrt( 2*2 + 4*4 + 6*6 ) = Math.sqrt(56) = 7.483314774
/home/cs170001/turnin ~/cs170/hw6/Vector.java hw6