Programming Assignment 1
The goal of this assignment is for you to implement a three dimensional vector class using JavaScript’s built in Class syntax. Your implementation should be immutable, all functions on the class may not modify the vector’s properties and should return a new vector with the computed value. There are many existing three dimensional vector implementations out there on the web; I require that you do not use them as a reference when you implement your own.
Function Descriptions
Vec3.constructor(Number x, Number y, Number z): Vec3
Copyright By PowCoder代写 加微信 powcoder
Creates a new vector with the given properties.
Vec3.copy(): Vec3
Returns a new vector instance with the same property values as this instance.
Vec3.add(Vec3 vec): Vec3
This method must return a new vector equal to the sum of this vector and the given vector. Vec3.sub(Vec3 vec): Vec3
This method must return a new vector equal to the difference between this vector and the given vector.
Vec3.scale(Number scale): Vec3
Scales the properties of this vector by the given number and returns the result as a new vector. Vec3.dot(Vec3 vec): Number
This method must compute the dot product of this vector and the given vector, returning the resulting Number.
Vec3.cross(Vec3 vec): Vec3
This method must compute the cross product of this vector and the given vector. Note: The output will be a vector perpendicular to both vectors.
given two vectors v1 and v2
v1 * v2 = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
Vec3.angle(): Number
Returns the angle between this vector and the x axis.
Vec3.angleBetween(Vec3 vec): Number
Returns the angle in radians between this vector and the given vector.
Vec3.length(): Number
This method must compute the length of this vector.
Vec3.distance(Vec3 vec): Number
Implementation Notes: should be computed by taking the length of the vector found by taking the difference between this vector and the given vector.
Returns the distance between this vector and the given vector.
Vec3.normalize(): Vec3
This method should return a vector in the same direction as this vector but with a length of one.
Vec3.equals(Vec3 vec)
Returns true if all the components of this vector and the given vector are equal, false otherwise.
Vec3.[Symbol.toPrimitive](String hint)
Your implementation should always return a string representation of the vector. The format should match
Vec3[x:1.0,y:1.0,z:1.0]. You do not need to worry about formatting the numbers in the string.
Your program will be graded using an automated test suite. Points will be assigned as follows.
total 70 pts – all function implementations
total 5 pts – each function
1 pts – function documentation 2 pts – passes basic test cases 2 pts – passes hidden test cases
5 pts – the class is exported as a module 5 pts – the class is immutable
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com