Project Submission (late)
Dependencies: mbed
Vector2Di/Vector2Di.cpp@3:83e79d31930c, 2019-05-10 (annotated)
- Committer:
- el17tc
- Date:
- Fri May 10 14:52:28 2019 +0000
- Revision:
- 3:83e79d31930c
- Parent:
- 0:72f372170a73
final commit, API is added.; I'm not sure if there is a specific statement of academic integrity wanted but- I declare that this work is 100% my own, I have not plagiarised any work or attempted to fabricate any part of it for extra marks.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17tc | 0:72f372170a73 | 1 | #include "Vector2Di.h" |
el17tc | 0:72f372170a73 | 2 | |
el17tc | 0:72f372170a73 | 3 | // Vector manipulation functions |
el17tc | 3:83e79d31930c | 4 | // they are pretty self explanatory (very basic) |
el17tc | 0:72f372170a73 | 5 | Vector2Di Vector2Di::operator -() { |
el17tc | 0:72f372170a73 | 6 | Vector2Di negV = {x*-1, y*-1}; |
el17tc | 0:72f372170a73 | 7 | return negV; |
el17tc | 0:72f372170a73 | 8 | } |
el17tc | 0:72f372170a73 | 9 | |
el17tc | 0:72f372170a73 | 10 | void Vector2Di::addVector(Vector2Di v) { |
el17tc | 0:72f372170a73 | 11 | int newX = x + v.x; |
el17tc | 0:72f372170a73 | 12 | int newY = y + v.y; |
el17tc | 0:72f372170a73 | 13 | x = newX; |
el17tc | 0:72f372170a73 | 14 | y = newY; |
el17tc | 0:72f372170a73 | 15 | } |
el17tc | 0:72f372170a73 | 16 | |
el17tc | 0:72f372170a73 | 17 | void Vector2Di::rotateVector(double angle) { |
el17tc | 0:72f372170a73 | 18 | double newX = (x * cos(angle)) + (y * -sin(angle)); |
el17tc | 0:72f372170a73 | 19 | double newY = (x * sin(angle)) + (y * cos(angle)); |
el17tc | 0:72f372170a73 | 20 | x = static_cast<int>(newX); |
el17tc | 0:72f372170a73 | 21 | y = static_cast<int>(newY); |
el17tc | 0:72f372170a73 | 22 | } |