GWU Making a 2D Vector Class Phyton Program File You should make sure that the code is running correct and include commentsRubric – Code runs, is fully tes
GWU Making a 2D Vector Class Phyton Program File You should make sure that the code is running correct and include commentsRubric – Code runs, is fully tested, and includes sufficient comments and supporting documentationI will attach you the assignment instruction below. Assignment 3
We are going to experiment with making our own class. We are going to make a 2D vector
Here is a little background on two-dimensional vectors. A vector is basically an arrow that has a
magnitude (a length) and a direction (an angle with respect to typically the x axis). It usually is
represented as an x,y pair, where the origin of the vector is a 0,0 and the end of the vector is at
the listed pair.
Here are some of the operations you can perform on a vector.
Vector Addition: If V1 is (x,y) and V2 is (a,b), the V+W is (x+a,y+b), a vector
Vector Multiplication by a scalar. if V1 is (x,y), the V*n is (x*n,y*n), a vector
Vector Subtraction V-W is the same as V+(W*-1), a vector (note that this definition
uses addition and multiplication).
Vector Multiplication with another vector. There are two possibilities, dot product or
cross product. Well do dot product. If V=(x,y) and W=(a,b), then V*W = x*a + y*b, a
scalar. Thus, the dot product yields a scalar, not a vector
Vector Magnitude. The magnitude based on the Pythagorean theorem for a V=(x,y)
says that the magnitude is !?? # + ?? # . You might look at math.hypot for this.
Make a vector class. Provide the operators
# constructor, takes 3 args: self,x,y . No return
# for printing, takes 1 arg self. Returns a string
# vector + vector. Takes 2 args, self and vector. Returns a new vector
# vector vector. Takes 2 args, self and vector. Returns a new vector
# two possibilities. vector*integer or vector*vector (dot product). Get it to do
just one of # the two at first, then see if you can use introspection to do both
magnitude() # magnitude of the vector. One arg, self. Returns a float
Purchase answer to see full