示例#1
0
文件: ring.cpp 项目: tfursten/IBD-2N
void Ring::length(double x1, double x2, double y1, double y2){
    double L = arclen(x1,x2,y1,y2);
    int x = getBin(x2);
    int y = getBin(y1);
    probMap[make_pair(x,y)]+= L;
    probMap[make_pair(y,x)]+= L;
}
示例#2
0
/**
 * @brief geodist 计算2个经纬度表示的地球上的两个地点之间的距离
 * @param lat1
 * @param lon1
 * @param lat2
 * @param lon2
 * @param d  返回的距离, 海里单位
 * @return
 */
int geodist(double lat1,
            double lon1,
            double lat2,
            double lon2,
            double *d) {
                
    if (lat1 < -90.0 || lat1 > 90.0 || lat2 < -90.0 || lat2 > 90.0 ) {
        return -1;
    }
    if (lon1 < -180.0 || lon1 > 180.0 || lon2 < -180.0 || lon2 > 180.0 ) {
        return -1;
    }

    SPoint p1, p2;

    //将经纬度转成球座标点
    getSPointFromLatLon (lat1, lon1, &p1);
    getSPointFromLatLon (lat2, lon2, &p2);

    arclen (&p1, &p2, d);
    return 0;
}
int geodist(double lat1, double lon1, double lat2, double lon2, double *d)
{

	SPoint p1, p2;

/*****************************************************************************
*  Validate the coordinates.                                                 *
*****************************************************************************/

	if (lat1 < -90.0 || lat1 > 90.0 || lat2 < -90.0 || lat2 > 90.0)
		return -1;

	if (lon1 < -180.0 || lon1 > 180.0 || lon2 < -180.0 || lon2 > 180.0)
		return -1;

/*****************************************************************************
*  Convert each latitude and longitude to spherical coordinates in radians   *
*  using the earth's radius for rho.                                         *
*****************************************************************************/

	p1.rho = EARTH_RADIUS;
	p1.theta = -1.0 * DEGTORAD(lon1);
	p1.phi = (DEGTORAD(-1.0 * lat1)) + DEGTORAD(90.0);

	p2.rho = EARTH_RADIUS;
	p2.theta = -1.0 * DEGTORAD(lon2);
	p2.phi = (DEGTORAD(-1.0 * lat2)) + DEGTORAD(90.0);

/*****************************************************************************
*  Compute the distance between the points.                                  *
*****************************************************************************/

	arclen(p1, p2, d);

	return 0;

}
示例#4
0
    //       sin(lat) ]
    //
    // |v0 x v1| ~ sqrt( cos(lat0)^2 cos(lat1)^2 dlon^2 + dlat^2 )

    float cos_lat1_sq = cosf(lat1_rad);
    cos_lat1_sq *= cos_lat1_sq;

    float dlat = lat1_rad - lat0_rad;
    float dlon = lon1_rad - lon0_rad;

    return Rearth * sqrtf( dlon*dlon * cos_lat0_sq * cos_lat1_sq +
                           dlat*dlat );
  }


  float len = arclen( pois[ipoi].lat_rad, pois[ipoi].lon_rad );
  return MIN_MARKER_DIST < len && len < MAX_MARKER_DIST;
}

static void addToActive( int ipoi )
{
  active_pois[N_active_pois++] = ipoi;
}

void initPOIs( float lat_rad, float lon_rad )
{
  // alloc an upper-bound amount of memory. It's probably too much, but I know
  // we'll never run out
  int Npois = sizeof(pois) / sizeof(pois[0]);

  if( active_pois == NULL )