The task given to us is to implement vectors in 2 weeks for the GPR5204 module at SAE Institute Geneva. Here is a list of what we're going to do for vectors 2, 3 and 4.
Vector 2
Addition
The method returns: (x + rhs.x, y + rhs.y)
Substraction
The method returns: (x - rhs.x, y - rhs.y)
Multiplication
The method returns: (x rhs.x, y rhs.y)
Division
The method returns: (x / rhs.x, y / rhs.y)
Dot product
The method returns: x v2.x + y v2.y
Cross product
The method returns: v1.x v2.y - v1.y v2.y
Magnitude
The method returns: sqrtf(x x + y y)
Sqr Magnitude
The method returns: x x + y y
Angle between
The method returns: acosf(Dot(v1, v2) / (v1.Magnitude() * v2.Magnitude()))
Lerp
We use std::clamp for t with a specific range of [0-1]
Then the method returns: Vec2f(v1.x + (v2.x - v1.x) t, v1.y + (v2.y - v1.y) t)
Slerp
First, we multiply Acos(dot) by t to return the angle between v1 and the result:
float theta = Mathf.Acos(Dot(v1, v2)) t
Vec2f relativeVec = v2 – v1 Dot (v1, v2)
relativeVec.Normalize()
Then the method returns: ((v1 cos(theta)) + relativeVec sin(theta)))
Normalize
The method returns: Vec2f (x / Magnitude(), y / Magnitude())
Rotation
First, we convert the angle from degree to radian with angle = (2 PI) - angle
Then the method returns: Vec2f((v1.x cos(angle)) + (v1.y -sin(angle)), (v1.x sin(angle)) + (v1.y * cos(angle)))
Vector 3
Addition
The method returns: (x + rhs.x, y + rhs.y, z + rhs.z)
Substraction
The method returns: (x - rhs.x, y - rhs.y, z - rhs.z)
Multiplication
The method returns: (x rhs.x, y rhs.y, z * rhs.z)
Division
The method returns: (x / rhs.x, y / rhs.y, z / rhs.z)
Dot product
The method returns: (x rhs.x + y rhs.y + z * rhs.z)
The method returns: acosf(Dot(v1, v2) / (v1.Magnitude() * v2.Magnitude()))
Lerp
We use std::clamp for t with a specific range of [0-1]
Then the method returns: Vec3f (v1 + t * (v2 – v1))
Slerp
First, we multiply Acos(dot) by t to return the angle between v1 and the final result:
float theta = Mathf.Acos(Dot(v1, v2)) t
Vec3f relativeVec = v2 – v1 Dot (v1, v2)
relativeVec.Normalize()
Then the method returns: ((v1 cos(theta)) + relativeVec sin(theta)))
Normalize
The method returns: Vec3f (x / Magnitude(), y / Magnitude(), z / Magnitude())
Rotation
We cannot do the rotation for Vector3 since there isn’t anyone working on quaternions.
Vector 4
Addition
The method returns: (x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w)
Substraction
The method returns: (x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w)
Multiplication
The method returns: (x rhs.x, y rhs.y, z rhs.z, w rhs.w)
Division
The method returns: (x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w)
Dot product
The method returns: (x rhs.x + y rhs.y + z rhs.z + w rhs.w)
Magnitude
The method returns: sqrtf(x x + y y + z z + w w)
Sqr Magnitude
The method returns: x x + y y + z z + w w
Lerp
We use std::clamp for t with a specific range of [0-1]
Then the method returns: Vec4f (v1 + t * (v2 – v1))
Normalize
The method returns: Vec4f (x / Magnitude(), y / Magnitude(), z / Magnitude(), w / Magnitude())
Introduction
The task given to us is to implement vectors in 2 weeks for the GPR5204 module at SAE Institute Geneva. Here is a list of what we're going to do for vectors 2, 3 and 4.
Vector 2
Addition
The method returns: (x + rhs.x, y + rhs.y)
Substraction
The method returns: (x - rhs.x, y - rhs.y)
Multiplication
The method returns: (x rhs.x, y rhs.y)
Division
The method returns: (x / rhs.x, y / rhs.y)
Dot product
The method returns: x v2.x + y v2.y
Cross product
The method returns: v1.x v2.y - v1.y v2.y
Magnitude
The method returns: sqrtf(x x + y y)
Sqr Magnitude
The method returns: x x + y y
Angle between
The method returns: acosf(Dot(v1, v2) / (v1.Magnitude() * v2.Magnitude()))
Lerp
We use std::clamp for t with a specific range of [0-1] Then the method returns: Vec2f(v1.x + (v2.x - v1.x) t, v1.y + (v2.y - v1.y) t)
Slerp
First, we multiply Acos(dot) by t to return the angle between v1 and the result: float theta = Mathf.Acos(Dot(v1, v2)) t Vec2f relativeVec = v2 – v1 Dot (v1, v2) relativeVec.Normalize()
Then the method returns: ((v1 cos(theta)) + relativeVec sin(theta)))
Normalize
The method returns: Vec2f (x / Magnitude(), y / Magnitude())
Rotation
First, we convert the angle from degree to radian with angle = (2 PI) - angle Then the method returns: Vec2f((v1.x cos(angle)) + (v1.y -sin(angle)), (v1.x sin(angle)) + (v1.y * cos(angle)))
Vector 3
Addition
The method returns: (x + rhs.x, y + rhs.y, z + rhs.z)
Substraction
The method returns: (x - rhs.x, y - rhs.y, z - rhs.z)
Multiplication
The method returns: (x rhs.x, y rhs.y, z * rhs.z)
Division
The method returns: (x / rhs.x, y / rhs.y, z / rhs.z)
Dot product
The method returns: (x rhs.x + y rhs.y + z * rhs.z)
Cross product
The method returns: Vec3f (v1.y v2.z – v1.z v2.y, v1.z v2.x – v1.x v2.z, v1.x v2.y - v1.y v2.x)
Magnitude
The method returns: sqrtf(x x + y y + z * z)
Sqr Magnitude
The method returns: x x + y y + z * z
Angle between
The method returns: acosf(Dot(v1, v2) / (v1.Magnitude() * v2.Magnitude()))
Lerp
We use std::clamp for t with a specific range of [0-1] Then the method returns: Vec3f (v1 + t * (v2 – v1))
Slerp
First, we multiply Acos(dot) by t to return the angle between v1 and the final result: float theta = Mathf.Acos(Dot(v1, v2)) t Vec3f relativeVec = v2 – v1 Dot (v1, v2) relativeVec.Normalize()
Then the method returns: ((v1 cos(theta)) + relativeVec sin(theta)))
Normalize
The method returns: Vec3f (x / Magnitude(), y / Magnitude(), z / Magnitude())
Rotation
We cannot do the rotation for Vector3 since there isn’t anyone working on quaternions.
Vector 4
Addition
The method returns: (x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w)
Substraction
The method returns: (x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w)
Multiplication
The method returns: (x rhs.x, y rhs.y, z rhs.z, w rhs.w)
Division
The method returns: (x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w)
Dot product
The method returns: (x rhs.x + y rhs.y + z rhs.z + w rhs.w)
Magnitude
The method returns: sqrtf(x x + y y + z z + w w)
Sqr Magnitude
The method returns: x x + y y + z z + w w
Lerp
We use std::clamp for t with a specific range of [0-1] Then the method returns: Vec4f (v1 + t * (v2 – v1))
Normalize
The method returns: Vec4f (x / Magnitude(), y / Magnitude(), z / Magnitude(), w / Magnitude())