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.
EuclidPoint.cpp@0:ded79d89abdf, 2015-05-01 (annotated)
- Committer:
- tyleralt
- Date:
- Fri May 01 05:33:50 2015 +0000
- Revision:
- 0:ded79d89abdf
- Child:
- 1:bb1507f0bb64
geting Frist crossing and second not working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tyleralt | 0:ded79d89abdf | 1 | //#include "Point.h" |
tyleralt | 0:ded79d89abdf | 2 | #include "EuclidPoint.h" |
tyleralt | 0:ded79d89abdf | 3 | #include <math.h> |
tyleralt | 0:ded79d89abdf | 4 | |
tyleralt | 0:ded79d89abdf | 5 | int EuclidPoint:: getFirstCrossingDegree (int xl, int yl){ // returns the degree of the first cross |
tyleralt | 0:ded79d89abdf | 6 | |
tyleralt | 0:ded79d89abdf | 7 | double dradius = sqrt((double)(xl * xl ) + (yl * yl)); |
tyleralt | 0:ded79d89abdf | 8 | int radius = rint(dradius); |
tyleralt | 0:ded79d89abdf | 9 | |
tyleralt | 0:ded79d89abdf | 10 | int oneCross = (int)(asin ((double)yl / radius)) * 57.295; |
tyleralt | 0:ded79d89abdf | 11 | if (xl < 0 && oneCross > 0){ |
tyleralt | 0:ded79d89abdf | 12 | oneCross = 180 - oneCross; |
tyleralt | 0:ded79d89abdf | 13 | } else if (xl < 0 && oneCross < 0){ |
tyleralt | 0:ded79d89abdf | 14 | oneCross = 180 - oneCross; |
tyleralt | 0:ded79d89abdf | 15 | } else if (xl < 0){ |
tyleralt | 0:ded79d89abdf | 16 | oneCross = 360 + oneCross; |
tyleralt | 0:ded79d89abdf | 17 | } |
tyleralt | 0:ded79d89abdf | 18 | |
tyleralt | 0:ded79d89abdf | 19 | int twoCross = (int) (acos ((double)xl / radius)) * 57.295; |
tyleralt | 0:ded79d89abdf | 20 | if (yl < 0){ |
tyleralt | 0:ded79d89abdf | 21 | twoCross = 360 - twoCross; |
tyleralt | 0:ded79d89abdf | 22 | } |
tyleralt | 0:ded79d89abdf | 23 | if (oneCross < twoCross){ |
tyleralt | 0:ded79d89abdf | 24 | return twoCross; |
tyleralt | 0:ded79d89abdf | 25 | } else { |
tyleralt | 0:ded79d89abdf | 26 | return oneCross; |
tyleralt | 0:ded79d89abdf | 27 | } |
tyleralt | 0:ded79d89abdf | 28 | return 1; |
tyleralt | 0:ded79d89abdf | 29 | } |
tyleralt | 0:ded79d89abdf | 30 | |
tyleralt | 0:ded79d89abdf | 31 | int EuclidPoint :: getSecondCrossingDegree (int xl, int yl){ // returns the degree of the first cross |
tyleralt | 0:ded79d89abdf | 32 | double dradius = (sqrt((double)(xl * xl ) + (yl * yl))); |
tyleralt | 0:ded79d89abdf | 33 | int radius = rint(dradius); |
tyleralt | 0:ded79d89abdf | 34 | |
tyleralt | 0:ded79d89abdf | 35 | int oneCross = (int)(asin ((double)yl / radius)) * 57.295; |
tyleralt | 0:ded79d89abdf | 36 | if (xl < 0 && oneCross > 0){ |
tyleralt | 0:ded79d89abdf | 37 | oneCross = 180 - oneCross; |
tyleralt | 0:ded79d89abdf | 38 | } else if (xl < 0 && oneCross < 0){ |
tyleralt | 0:ded79d89abdf | 39 | oneCross = 180 - oneCross; |
tyleralt | 0:ded79d89abdf | 40 | } else if (xl < 0){ |
tyleralt | 0:ded79d89abdf | 41 | oneCross = 360 + oneCross; |
tyleralt | 0:ded79d89abdf | 42 | } |
tyleralt | 0:ded79d89abdf | 43 | int twoCross = (int) (acos ((double)xl / radius)) * 57.295; |
tyleralt | 0:ded79d89abdf | 44 | if (yl < 0){ |
tyleralt | 0:ded79d89abdf | 45 | twoCross = 360 - twoCross; |
tyleralt | 0:ded79d89abdf | 46 | } |
tyleralt | 0:ded79d89abdf | 47 | |
tyleralt | 0:ded79d89abdf | 48 | if (oneCross < twoCross){ |
tyleralt | 0:ded79d89abdf | 49 | return oneCross; |
tyleralt | 0:ded79d89abdf | 50 | } else { |
tyleralt | 0:ded79d89abdf | 51 | return twoCross; |
tyleralt | 0:ded79d89abdf | 52 | } |
tyleralt | 0:ded79d89abdf | 53 | return 1; |
tyleralt | 0:ded79d89abdf | 54 | } |
tyleralt | 0:ded79d89abdf | 55 | |
tyleralt | 0:ded79d89abdf | 56 | |
tyleralt | 0:ded79d89abdf | 57 | EuclidPoint :: EuclidPoint(void){ |
tyleralt | 0:ded79d89abdf | 58 | x = 0; |
tyleralt | 0:ded79d89abdf | 59 | y = 3; |
tyleralt | 0:ded79d89abdf | 60 | z = 4; |
tyleralt | 0:ded79d89abdf | 61 | } |
tyleralt | 0:ded79d89abdf | 62 | EuclidPoint :: EuclidPoint(int xi, int yi, int zi){ |
tyleralt | 0:ded79d89abdf | 63 | x = xi; |
tyleralt | 0:ded79d89abdf | 64 | y = yi; |
tyleralt | 0:ded79d89abdf | 65 | z = zi; |
tyleralt | 0:ded79d89abdf | 66 | } |
tyleralt | 0:ded79d89abdf | 67 | |
tyleralt | 0:ded79d89abdf | 68 | Point EuclidPoint :: getStartPoint(void){ |
tyleralt | 0:ded79d89abdf | 69 | int degree; |
tyleralt | 0:ded79d89abdf | 70 | if (x >= 0 && y >= 0){ //1 |
tyleralt | 0:ded79d89abdf | 71 | degree = getFirstCrossingDegree(x + 1, y); |
tyleralt | 0:ded79d89abdf | 72 | } else if (x < 0 && y >= 0){ //2 |
tyleralt | 0:ded79d89abdf | 73 | degree = getFirstCrossingDegree(x + 1, y + 1); |
tyleralt | 0:ded79d89abdf | 74 | }else if (x < 0 && y < 0){ //3 |
tyleralt | 0:ded79d89abdf | 75 | degree = getFirstCrossingDegree(x,y+1); |
tyleralt | 0:ded79d89abdf | 76 | }else{ //4 |
tyleralt | 0:ded79d89abdf | 77 | degree = getFirstCrossingDegree(x,y); |
tyleralt | 0:ded79d89abdf | 78 | } |
tyleralt | 0:ded79d89abdf | 79 | int radius = (int) sqrt((double)(x * x ) + (y * y)); |
tyleralt | 0:ded79d89abdf | 80 | return Point( degree, z, radius); |
tyleralt | 0:ded79d89abdf | 81 | } |
tyleralt | 0:ded79d89abdf | 82 | Point EuclidPoint :: getEndPoint(void){ |
tyleralt | 0:ded79d89abdf | 83 | int degree; |
tyleralt | 0:ded79d89abdf | 84 | if (x >= 0 && y >= 0){ //1 |
tyleralt | 0:ded79d89abdf | 85 | degree = getFirstCrossingDegree(x, y + 1); |
tyleralt | 0:ded79d89abdf | 86 | } else if (x < 0 && y >= 0){ //2 |
tyleralt | 0:ded79d89abdf | 87 | degree = getFirstCrossingDegree(x , y ); |
tyleralt | 0:ded79d89abdf | 88 | }else if (x < 0 && y < 0){ //3 |
tyleralt | 0:ded79d89abdf | 89 | degree = getFirstCrossingDegree(x + 1,y); |
tyleralt | 0:ded79d89abdf | 90 | }else{ //4 |
tyleralt | 0:ded79d89abdf | 91 | degree = getFirstCrossingDegree(x+ 1,y + 1); |
tyleralt | 0:ded79d89abdf | 92 | } |
tyleralt | 0:ded79d89abdf | 93 | int radius = (int) sqrt((double)(x * x ) + (y * y)); |
tyleralt | 0:ded79d89abdf | 94 | return Point( degree, z, radius); |
tyleralt | 0:ded79d89abdf | 95 | } |
tyleralt | 0:ded79d89abdf | 96 | void EuclidPoint :: moveUp(void){ |
tyleralt | 0:ded79d89abdf | 97 | z++; |
tyleralt | 0:ded79d89abdf | 98 | } |
tyleralt | 0:ded79d89abdf | 99 | void EuclidPoint :: moveDown(void){ |
tyleralt | 0:ded79d89abdf | 100 | z--; |
tyleralt | 0:ded79d89abdf | 101 | } |
tyleralt | 0:ded79d89abdf | 102 | void EuclidPoint :: moveTowards(void){ |
tyleralt | 0:ded79d89abdf | 103 | y--; |
tyleralt | 0:ded79d89abdf | 104 | } |
tyleralt | 0:ded79d89abdf | 105 | void EuclidPoint :: moveAway(void){ |
tyleralt | 0:ded79d89abdf | 106 | y++; |
tyleralt | 0:ded79d89abdf | 107 | } |
tyleralt | 0:ded79d89abdf | 108 | void EuclidPoint :: moveRight(void){ |
tyleralt | 0:ded79d89abdf | 109 | x++; |
tyleralt | 0:ded79d89abdf | 110 | } |
tyleralt | 0:ded79d89abdf | 111 | void EuclidPoint :: moveLeft(void){ |
tyleralt | 0:ded79d89abdf | 112 | x--; |
tyleralt | 0:ded79d89abdf | 113 | } |