00001
00002 #include "posregcmu.h"
00003 #include <math.h>
00004 #include "mymath.h"
00005
00006 PosRegCmu::PosRegCmu()
00007 {
00008 }
00009
00010
00011 PosRegCmu::~PosRegCmu()
00012 {
00013 }
00014
00015 int* PosRegCmu::CMUnited(double v, double aktPos[], double nextPos[], double nextPos2[])
00016 {
00017 double thetaD, theta, alfa, d, fi, delta, t, r;
00018 const int c = 5;
00019 double x1, x2, y1, y2;
00020 int rychlosti[4];
00021
00022 x1 = nextPos[0] - aktPos[0];
00023 y1 = nextPos[1] - aktPos[1];
00024
00025 x2 = nextPos2[0] - nextPos[0];
00026 y2 = nextPos2[1] - nextPos[1];
00027
00028 fi = aktPos[2];
00029
00030 d = sqrt(pow(nextPos[0] - aktPos[0], 2) + (pow(nextPos[1] - aktPos[1], 2)));
00031
00032
00033 alfa = acos((x1 * x2 + y1 * y2) / (sqrt(x1 * x1 + y1 * y1) * sqrt(x2 * x2 + y2 * y2)));
00034 if ((x1 > 0) && (y1 < 0)) alfa = 2 * M_PI - alfa;
00035
00036
00037
00038 theta = acos(x1 / (sqrt(x1 * x1 + y1 * y1)));
00039 if ((x1 > 0) && (y1 < 0)) theta = 2 * M_PI - theta;
00040
00041 if ((x1 < 0) && (y1 < 0)) theta = 2 * M_PI - theta;
00042
00043 thetaD = theta + min(alfa, atan(c / d));
00044 delta = thetaD - fi;
00045 t = pow(cos(delta), 2) * signum(cos(delta));
00046 r = pow(sin(delta), 2) * signum(sin(delta));
00047
00048
00049
00050
00051
00052
00053
00054 double a = (1 * (t - r));
00055 double b = (1 * (t + r));
00056
00057 if ((a > 0.5) & (b < -0.5)) v = 50;
00058 if ((a < 0.5) & (b > -0.5)) v = 50;
00059 a *= v;
00060 b *= v;
00061
00062
00063 rychlosti[0] = (int)abs(v * (t - r));
00064 rychlosti[1] = (int)abs(v * (t + r));
00065 if ((v * (t - r)) < 0) rychlosti[2] = 1;
00066 if ((v * (t + r)) < 0) rychlosti[3] = 1;
00067
00068
00069
00070
00071
00072 return rychlosti;
00073 }