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.
Revision 1:1d2eb2143108, committed 2010-10-19
- Comitter:
- erikkallen
- Date:
- Tue Oct 19 10:07:15 2010 +0000
- Parent:
- 0:886002922b6a
- Commit message:
Changed in this revision
Point.c | Show annotated file Show diff for this revision Revisions of this file |
Point.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Point.c Tue Oct 19 10:07:15 2010 +0000 @@ -0,0 +1,52 @@ +#include "Point.h" +#include "math.h" + +Point::Point(float x, float y) { + _x = x; + _y = y; +} + +Point::Point() { + _x = 0; + _y = 0; +} + +float Point::getX() { + return _x; +} + + +float Point::getY() { + return _y; +} + +void Point::setX(float x) { + _x = x; +} + +void Point::setY(float y) { + _y = y; +} + + +Point Point::DegreesToXY(float degrees, float radius, Point origin) +{ + Point xy = Point(); + double radians = degrees * PI / 180.0; + + xy.setX( (float)cos(radians) * radius + origin.getX()); + xy.setY( (float)sin(-radians) * radius + origin.getY()); + + return xy; +} + + float Point::XYToDegrees(Point xy, Point origin) +{ + int deltaX = origin.getX() - xy.getX(); + int deltaY = origin.getY() - xy.getY(); + + double radAngle = atan2((long double)deltaY, (long double)deltaX); + double degreeAngle = radAngle * 180.0 / PI; + + return (float)(180.0 - degreeAngle); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Point.h Tue Oct 19 10:07:15 2010 +0000 @@ -0,0 +1,22 @@ +#ifndef MOTOR_POINT_H +#define MOTOR_POINT_H +#include "mbed.h" +#define PI 3.14159265359 +class Point { + public: + Point(float x, float y); + Point(); + float getX(); + float getY(); + void setX(float x); + void setY(float y); + static Point DegreesToXY(float degrees, float radius, Point origin); + static float XYToDegrees(Point xy, Point origin); + private: + float _x; + float _y; +}; + + + +#endif \ No newline at end of file