This repository was archived by the owner on Nov 15, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_vectors.cpp
More file actions
42 lines (35 loc) · 1.48 KB
/
print_vectors.cpp
File metadata and controls
42 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <math.h>
#include <stdio.h>
#include <Arduino.h>
#include "add_vectors.h"
/**
* Prints out the x and y coordinates for each point in the array of vectors where the would be in a coordinate plane given they are in order
* outputs as (x,y)
* Precondition: vector andlges must be in degrees
* @param v the array of vectors to find the points in
* @param length the length of the array of vectors (can calculate as sizeof(v)/sizeof(v[0]))
*/
void print_vectors(struct Vector v[], int length) {
// print all of the points on the coordinate place from an array of vectors
// create default resultant vector
struct Vector resultant;
resultant.distance = 0;
resultant.angle = 0;
// print out the origin point
Serial.print("(0,0)\n"); // we may decide this is unnecessary if the last point should be 0,0 too due to the robot coming full circle
// get the coordinates at each point by printing the x and y coordinates after each vector in the array is added to a resultant vector
for (int i = 0; i < length; i++) {
// get the current resultant vector
resultant = add_two_vectors(resultant, v[i]);
// get x coord of resultant
int x = (int) lrint(resultant.distance * cos(resultant.angle * TO_RADIANS));
// get y coord of resultant
int y = (int) lrint(resultant.distance * sin(resultant.angle * TO_RADIANS));
// print the coordinates
Serial.print("(");
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(")\n");
}
}