//----------------------------- CheckForMine ----------------------------- // // this function checks for collision with its closest mine (calculated // earlier and stored in m_iClosestMine) //----------------------------------------------------------------------- int CMinesweeper::CheckForMine(vector<SVector2D> &mines, double size) { SVector2D DistToObject = m_vPosition - mines[m_iClosestMine]; if (Vec2DLength(DistToObject) < (size + 5)) { return m_iClosestMine; } return -1; }
bool CBobsMap::GetOneValidPath(vector<int> &vecBits,int chromolen) { int testCount=0; int iChromoLength=chromolen; int iCutCount=iChromoLength+1; Coordinate cord(m_spA,m_spB); SPoint spPre=m_spA; int randomY = 0; //divied space SVector2D line(m_spA.x-m_spB.x,m_spA.y-m_spB.y); int diffX = (int) Vec2DLength(line)/iCutCount; for(int i=1;i<=iChromoLength;i++) { randomY = RandInt(-150,150); SPoint spRelative(i*diffX,randomY); SPoint spPathAbsolute=cord.GetCoordinate(spRelative.x,spRelative.y); while(true) { if(!BarrierIntersection(spPre,spPathAbsolute)&&IsValidPoint(spPathAbsolute)) { break; }else { testCount++; if(testCount>100) { return false; } } randomY = RandInt(-150,150); spRelative=SPoint(i*diffX,randomY); spPathAbsolute=cord.GetCoordinate(spRelative.x,spRelative.y); } //save waypoint vecBits.push_back(randomY); spPre=spPathAbsolute; } return true; }
/*! 線分のマスクを作る。 @param[out] mask マスクの出力先 @param[in] setnum 埋める値 @param[in] start 開始位置 @param[in] end 終了位置 */ void LineMask(IplImage *mask, uint8_t setnum, const CvPoint2D64f *start, const CvPoint2D64f *end) { float t=0.0; CvPoint2D64f d; //傾き CvPoint2D64f p; //end-startの傾きを計算 SubVec2D(&d, end, start); float d_length = Vec2DLength(&d); float rev_d_length = 1.0 / d_length; do{ //p = start + t*d ScaleVec2D(&p, t, &d); AddVec2D(&p, &p , start); //位置pにsetnum書き込み SetMaskDataPos(mask, p.x, p.y, setnum); t += rev_d_length/2.0; }while(t <= 1.0); }
vector<WayPoint> CBobsMap::Decode(const vector<int> &ycoodinate) { vector<WayPoint> wayPoint; vector<int>::const_iterator iter = ycoodinate.begin(); SVector2D line(m_spA.x-m_spB.x,m_spA.y-m_spB.y); int diffX = (int) Vec2DLength(line)/(ycoodinate.size()+1); int index=1; while(iter!=ycoodinate.end()) { SPoint relativeXY(index*diffX,*iter); SPoint absoluteXY =TransRelativePointToAbusolutePoint(relativeXY); WayPoint point(absoluteXY,relativeXY); wayPoint.push_back(point); index++; iter++; } return wayPoint; }
//----------------------GetClosestObject()--------------------------------- // // returns the vector from the sweeper to the closest mine // //----------------------------------------------------------------------- SVector2D CMinesweeper::GetClosestMine(vector<SVector2D> &mines) { double closest_so_far = 99999; SVector2D vClosestObject(0, 0); //cycle through mines to find closest for (int i=0; i<mines.size(); i++) { double len_to_object = Vec2DLength(mines[i] - m_vPosition); if (len_to_object < closest_so_far) { closest_so_far = len_to_object; vClosestObject = m_vPosition - mines[i]; m_iClosestMine = i; } } return vClosestObject; }