Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of BeaconDemo_RobotCode by
vector.cpp
- Committer:
- jah128
- Date:
- 2015-10-27
- Revision:
- 12:daa53285b6e4
File content as of revision 12:daa53285b6e4:
#include "main.h"
#include <math.h>
struct FloatVector addVector(struct FloatVector in_vector, int angle, int distance){
struct FloatVector out_vector;
float sin_component_old = sin(in_vector.angle * TO_RAD) * in_vector.distance;
float cos_component_old = cos(in_vector.angle * TO_RAD) * in_vector.distance;
float sin_component_new = sin(angle * TO_RAD) * distance;
float cos_component_new = cos(angle * TO_RAD) * distance;
float sin_component_sum = sin_component_old + sin_component_new;
float cos_component_sum = cos_component_old + cos_component_new;
out_vector.distance = sqrt((sin_component_sum * sin_component_sum) + (cos_component_sum * cos_component_sum));
out_vector.angle = atan2(sin_component_sum ,cos_component_sum) * TO_DEG;
//out("Angle:%f Distance:%f\n",out_vector.angle,out_vector.distance);
return out_vector;
}
