蜂窝最短距离

时间:2021-01-01 00:28:45
【文件属性】:
文件名称:蜂窝最短距离
文件大小:890B
文件格式:SLN
更新时间:2021-01-01 00:28:45
蜂窝 /************************************************************************ Description : 初始化蜂窝小区信息 Prototype : void InitCellularDistrict(int iMaxSeqValue) Input Param : iMaxSeqValue 蜂窝小区的最大值编号,注:编号从1开始 Output Param : 无 Return Value : 成功返回0,失败返回-1 /************************************************************************/ int InitCellularDistrict(int iMaxSeqValue) { if(iMaxSeqValue < 1 || iMaxSeqValue > 100000) { return -1; } g_maxvalue = iMaxSeqValue; return 0; } /************************************************************************ Description : 计算出蜂窝小区指定两点(编号值)之间的最短距离 Prototype : int GetShortestPathLength(int iFirstValue, int iSecondValue) Input Param : iFirstValue 起点编号值, iSecondValue 终点编号值 Output Param : 无 Return Value : 计算成功返回最短距离,失败返回-1 /************************************************************************/ int GetShortestPathLength(int iFirstValue, int iSecondValue) { if(iFirstValue > g_maxvalue || iFirstValue < 1 || iSecondValue > g_maxvalue || iSecondValue < 1) { return -1; } int x_1 = 0; int y_1 = 0; int z_1 = 0; int x_2 = 0; int y_2 = 0; int z_2 = 0; GetCoordinate(iFirstValue,&x_1,&y_1,&z_1); //获取坐标 GetCoordinate(iSecondValue,&x_2,&y_2,&z_2); int distance_x = (x_1 > x_2)? (x_1 - x_2):(x_2 - x_1); int distance_y = (y_1 > y_2)? (y_1 - y_2):(y_2 - y_1); int distance_z = (z_1 > z_2)? (z_1 - z_2):(z_2 - z_1); int shortest_distance = distance_x > distance_y? distance_x:distance_y; shortest_distance = shortest_distance > distance_z? shortest_distance:distance_z; return shortest_distance; } /************************************************************************ Description : 清空相关信息 Prototype : void Clear() Input Param : 无 Output Param : 无 Return Value : 无 /************************************************************************/ void Clear() { g_maxvalue = 0; }

网友评论