void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity) { // do the move vec2 Pos = *pInoutPos; vec2 Vel = *pInoutVel; float Distance = length(Vel); int Max = (int)Distance; if(Distance > 0.00001f) { //vec2 old_pos = pos; float Fraction = 1.0f/(float)(Max+1); for(int i = 0; i <= Max; i++) { //float amount = i/(float)max; //if(max == 0) //amount = 0; vec2 NewPos = Pos + Vel*Fraction; // TODO: this row is not nice if(TestBox(vec2(NewPos.x, NewPos.y), Size)) { int Hits = 0; if(TestBox(vec2(Pos.x, NewPos.y), Size)) { NewPos.y = Pos.y; Vel.y *= -Elasticity; Hits++; } if(TestBox(vec2(NewPos.x, Pos.y), Size)) { NewPos.x = Pos.x; Vel.x *= -Elasticity; Hits++; } // neither of the tests got a collision. // this is a real _corner case_! if(Hits == 0) { NewPos.y = Pos.y; Vel.y *= -Elasticity; NewPos.x = Pos.x; Vel.x *= -Elasticity; } } Pos = NewPos; } } *pInoutPos = Pos; *pInoutVel = Vel; }
/*------------------------------------------------------- 학습하는 함수 nClass(입력) : 학습 데이터의 클래스 pInput(입력) : 하나의 학습 입력 벡터 x, 길이는 m_nInput(=n)과 같아야 한다. * 사실은 n개 이상이어도 된다. 하지만 n개보다 적으면 문제가 생긴다. -------------------------------------------------------*/ void CFMMNN::Training(int nClass, float* pInput) { if(pInput == NULL) return; m_pInput = pInput; int nBox = FindMaxMembershipBox(nClass); if(nBox < 0) // 확장할 수 있는 게 없으면 AddBox(nClass); // 박스를 하나 새로 만든다. else // 확장할 수 있으면 { register MINMAX* pBox = &m_pBox[nClass][nBox]; ExpandBox(pBox); // 확장한다. TestBox(pBox, nClass); // overlap 테스트해서 축소한다. } }
int main( int argc, char **argv ) { int num_sample=100000; int t0=clock(); InitRandom(100000); int t1=clock(); ///Initialization performance printf("** Time elapsed for initialization of %d sample is %d\n \n",num_sample,t1-t0); Hash2D.Set(Allocated.begin(),Allocated.end()); ///Box Query performance t0=clock(); MyScalarType avg_test=TestBox(num_sample); t1=clock(); printf("** Time elapsed for %d BOX queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_test); ///Intersecting segment performance t0=clock(); MyScalarType avg_int=TestIntersection(num_sample); t1=clock(); printf("** Time elapsed for %d INTERSECTION queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_int); ///closest test t0=clock(); MyScalarType avg_clos=TestClosest(num_sample); t1=clock(); printf("** Time elapsed for %d CLOSEST queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_clos); ///reinitialize structure MyMark.mark=0; Hash2D.Clear(); int n_test=1000; InitRandom(n_test,100,0.1); Hash2D.Set(Allocated.begin(),Allocated.end()); int tested_int=TestCorrectIntersect(n_test); printf("** Correct Intersect on %d test are %d \n",n_test,tested_int); int tested_clos=TestCorrectClosest(n_test); printf("** Correct Closest on %d test are %d \n",n_test,tested_clos); return 0; }
int main( int argc, char **argv ) { (void) argc; (void) argv; int num_sample=20000; int t0=clock(); printf("** Random Initialization ** \n"); fflush(stdout); InitRandom(num_sample,100,0.3); int t1=clock(); ///Initialization performance printf("** Time elapsed for initialization of %d sample is %d\n \n",num_sample,t1-t0); Grid2D.Set(AllocatedSeg.begin(),AllocatedSeg.end()); fflush(stdout); //Box Query correctness TestBox(num_sample); TestClosest(num_sample); TestRay(num_sample); return 0; }