📄 manhattan.h
字号:
#ifndef MANHATTAN_H_
#define MANHATTAN_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
//key parameters
int NODE_NUM;
float VMAX;
float VMIN;
float ACCELERATION;
//defination
#define PI 3.1415926
#define INFINITY 100000.0
#define SIMULATION_TIME 900
#define SIMULATION_STEP 1
#define OPENFIELD_MAP 0
#define OBSTACLE_MAP 1
#define FREEWAY_MAP 2
#define MANHATTAN_MAP 3
#define HORIZONTAL 0
#define VERTICAL 1
#define HEIGHT 1000
#define WIDTH 1000
#define LANE_PER_STREET 2
//return a random double number at interval [0,1]
double new_random1()
{ return (double) (rand()*0.8/(double)RAND_MAX) + 0.1; }
//return a random double number at the interval [-1,1]
double new_random2()
{ return (double) ((rand()*1.0/(double)RAND_MAX-0.5)*2); }
//return the min number
float max(float a, float b)
{
if(a>=b)
return a;
else
return b;
}
//return the max number
float min(float a, float b)
{
if(a<=b)
return a;
else
return b;
}
//tell the odd and even, 1 if odd, 0 if even
int oddeven(int i)
{
int j;
j= (int) (i/2);
if(j*2 == i)
return 0;
else
return 1;
}
//normal func: calculate the distance between (x0,y0) and (x1,y1)
float getmy_distance(float a0,float b0,float a1,float b1)
{
float distx,disty;
distx = a1-a0;
disty = b1-b0;
return (float)sqrt(distx*distx+disty*disty);
}
//normal func: calculate the angle between (x0,y0) and (x1,y1)
float getmy_angle(float a0,float b0,float a1,float b1)
{
float distx,disty;
float angle;
distx = a1-a0;
disty = b1-b0;
if(disty==0 && distx==0)
angle = 0 ;
else if(distx==0 && disty>0)
angle = (float)PI/2;
else if(distx==0 && disty<0)
angle =-(float)PI/2;
else if (disty>=0 && distx>0) //1
angle=(float)atan((disty)/(distx));
else if (disty<=0 && distx>0) //4
angle=(float)atan((disty)/(distx));
else if (disty>=0 && distx<0) //2
angle=(float)atan((disty)/(distx))+(float)PI;
else if (disty<=0 && distx<0) //3
angle=(float)atan((disty)/(distx))-(float)PI;
return angle;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -