-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathHelp.cpp
43 lines (38 loc) · 1.08 KB
/
MathHelp.cpp
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
43
#include "MathHelp.h"
double MathHelp::RandF()
{return (double)(rand()/(double)RAND_MAX);}
double MathHelp::Distance(cordine a, cordine b)
{return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2));}
cordine MathHelp::LimitPos(cordine pos)
{
if (pos.first > 400)
{ pos.first = 400; }
else if (pos.first < 0)
{ pos.first = 0; }
if (pos.second>400)
{ pos.second = 400; }
else
{
if (pos.second < 0)
{ pos.second = 0; }
}
return pos;
}
cordine MathHelp::MakeNoiseOf(cordine accuratetarget)
{
srand((unsigned)time(NULL));
int x = accuratetarget.first;
int y = accuratetarget.second;
double randr = AINOISERADIUS*RandF();
double theta = RandF() * 2 * XC_PI;
int tx =(int)( x + randr*cos(theta));
int ty =(int) (y + randr*sin(theta));
return cordine(tx, ty);
}
bool MathHelp::NearlyOnline(cordine point, cordine l1, cordine l2)
{
double d1 = Distance(point, l1);
double d2 = Distance(point, l2);
double d3 = Distance(l1, l2);
return (d1 + d2 + ERRORCOMPENSATION - d3) <= ACCEPETABLEOFFSET;
}