bool ConvexPolygon::isConvex() const // Algorithme // effectue le produit vectoriel de tous les cotes // adjacents // si ils ont tous le meme signe retourner true // sinon retourner false { Vect start1(pointList[size-1]); start1 -= pointList[0]; Vect start2(pointList[1]); start2 -= pointList[0]; double firstProd = start1.x*start2.y - start1.y*start2.x; for(int i(1); i<size; i++) { Vect vect1(pointList[i-1]); vect1 -= pointList[i]; Vect vect2(pointList[i+1]); vect2 -= pointList[i]; double prod = vect1.x*vect2.y - vect1.y*vect2.x; if(prod*firstProd < 0) { return false; } } return true; }
//------------------------------------------------------------------------ /// Renders the collide model triangle soup. void TerrainCollisionShape::visualize(Details::OgreOpcodeDebugger* activeDebugger) { mActiveDebugger = activeDebugger; assert(mVertexBuf); // render the triangle soup int i, k; k = 0; for (i = 0; i < mVerticesPerRow * mVerticesPerRow * 3; i += 9) { float v0 = mVertexBuf[i + 0]; float v1 = mVertexBuf[i + 1]; float v2 = mVertexBuf[i + 2]; float v3 = mVertexBuf[i + 3]; float v4 = mVertexBuf[i + 4]; float v5 = mVertexBuf[i + 5]; float v6 = mVertexBuf[i + 6]; float v7 = mVertexBuf[i + 7]; float v8 = mVertexBuf[i + 8]; const Matrix4 &m = getFullTransform(); Vector3 vect0(v0, v1, v2); Vector3 vect1(v3, v4, v5); Vector3 vect2(v6, v7, v8); vect0 = m * vect0; vect1 = m * vect1; vect2 = m * vect2; mActiveDebugger->addShapeLine(vect0.x, vect0.y, vect0.z, vect1.x, vect1.y, vect1.z); mActiveDebugger->addShapeLine(vect1.x, vect1.y, vect1.z, vect2.x, vect2.y, vect2.z); mActiveDebugger->addShapeLine(vect2.x, vect2.y, vect2.z, vect0.x, vect0.y, vect0.z); } }
void llquat_test_object_t::test<12>() { LLVector3d vect(-2.0f, 5.0f, -6.0f); LLQuaternion quat(-3.5f, 4.5f, 3.5f, 6.5f); LLVector3d result = vect * quat; ensure( "1. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed ", (-633.0f == result.mdV[0]) && (-300.0f == result.mdV[1]) && (-36.0f == result.mdV[2])); LLVector3d vect1(5.0f, -4.5f, 8.21f); LLQuaternion quat1(2.0f, 4.5f, -7.2f, 9.5f); result = vect1 * quat1; ensure( "2. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", is_approx_equal_fraction(-120.29f, (F32) result.mdV[0], 8) && is_approx_equal_fraction(-1683.958f, (F32) result.mdV[1], 8) && is_approx_equal_fraction(516.56f, (F32) result.mdV[2], 8)); LLVector3d vect2(2.0f, 3.5f, 1.1f); LLQuaternion quat2(1.0f, 4.0f, 2.0f, 5.0f); result = vect2 * quat2; ensure( "3. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", is_approx_equal_fraction(18.400001f, (F32) result.mdV[0], 8) && is_approx_equal_fraction(188.6f, (F32) result.mdV[1], 8) && is_approx_equal_fraction(32.20f, (F32) result.mdV[2], 8)); }
int main() { QList<int> list; list << 3 << 3 << 6 << 6 << 6 << 8; QList<int>::iterator it; it = qLowerBound(list.begin(), list.end(), 5); list.insert(it, 5); qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8 ) it = qLowerBound(list.begin(), list.end(), 12); list.insert(it, 12); qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8, 12 ) it = qLowerBound(list.begin(), list.end(), 12); list.insert(it, 12); qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8, 12, 12 ) QVector<int> vect; vect << 3 << 3 << 6 << 6 << 6 << 8; QVector<int>::iterator begin6 = qLowerBound(vect.begin(), vect.end(), 6); QVector<int>::iterator end6 = qUpperBound(vect.begin(), vect.end(), 6); QVector<int> vect2(end6-begin6); qCopy(begin6, end6, vect2.begin()); qDebug() << vect2; // output: ( 6, 6, 6 ) int count6 = 0; qCount(vect.begin(), vect.end(), 6, count6); qDebug() << count6; // output: 3 return 0; }
PathPoint Path::update(Vector3<float> refPos, Vector3<float> playerPos) { float D_val; PathPoint current = getCurrent(); PathPoint previous = getPrevious(); float diffX = refPos.x - current.getPosition().x; float diffY = refPos.y - current.getPosition().y; float diffZ = refPos.z - current.getPosition().z; float playerDistFromPlane = 0; float firstDistFromPlane = 0; Vector3<float> vect1 (current.getPosition().x - previous.getPosition().x, current.getPosition().y - previous.getPosition().y, current.getPosition().z - previous.getPosition().z); Vector3<float> vect2 (current.getPosition().x + current.getUp().x, current.getPosition().y + current.getUp().y, current.getPosition().z + current.getUp().z); Vector3<float> normal; float distance = sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); PathPoint firstChoice = getAt(current.getFirstID()); if (distance < RANGE_CHECK) { if (current.getNumberOfIDs() == 1) { setChoice(current.getFirstID()); return getCurrent(); } normal = vect1.Cross(vect2).Normalized(); D_val = (current.getPosition().x * normal.x + current.getPosition().y * normal.y + current.getPosition().z * normal.z) * -1.0f; playerDistFromPlane = (normal.x * playerPos.x) + (normal.y * playerPos.y) + (normal.z * playerPos.z) + D_val; if (abs(playerDistFromPlane) < MID_BUFFER_WIDTH && current.getNumberOfIDs() == 3) { setChoice(current.getThirdID()); return getCurrent(); } firstDistFromPlane = normal.x * firstChoice.getPosition().x + normal.y * firstChoice.getPosition().y + normal.z * firstChoice.getPosition().z + D_val; if (playerDistFromPlane / abs(playerDistFromPlane) == firstDistFromPlane / abs(firstDistFromPlane)) { setChoice(current.getFirstID()); return getCurrent(); } else { setChoice(current.getSecondID()); return getCurrent(); } } return getCurrent(); }
void wordlist::mergeSort(vector<string>& unsortedList) { if (1 < unsortedList.size()) { vector<string> vect1(unsortedList.begin(), unsortedList.begin() + unsortedList.size() / 2); // sorts and merges first half of list mergeSort(vect1); vector<string> vect2(unsortedList.begin() + unsortedList.size() / 2, unsortedList.end()); // sorts and merges second half of list mergeSort(vect2); merge(unsortedList, vect1, vect2); } }
void m3math_test_object_t::test<4>() { LLMatrix3 llmat3_obj; LLVector3 vect1(2, 1, 4); LLVector3 vect2(3, 5, 7); LLVector3 vect3(6, 9, 7); llmat3_obj.setRows(vect1, vect2, vect3); ensure("LLVector3::getFwdRow failed ", vect1 == llmat3_obj.getFwdRow()); ensure("LLVector3::getLeftRow failed ", vect2 == llmat3_obj.getLeftRow()); ensure("LLVector3::getUpRow failed ", vect3 == llmat3_obj.getUpRow()); }
sf::Vector2f Collision::calculateDistance(sf::FloatRect box1, sf::FloatRect box2) { sf::Vector2f vect1(box1.left, box1.top); sf::Vector2f vect2(box2.left, box2.top); sf::Vector2f distance(float(vect1.x - vect2.x), float(vect1.y - vect2.y)); if(distance.y<0) distance.y *= -1; if(distance.x<0) distance.x *= -1; return distance; }
vect2D popPile(pile_struct* p) { p->num--; if(p->first) { pileCell_struct* pc=p->first; vect2D v=pc->data; p->first=pc->next; free(pc); return v; } return vect2(0,0); //not cool }
const float TripleProduct( const Vertex& v0, const Vertex& v1, const Vertex& v2 ) { Vect vect0( v0.x, v0.y, v0.z ); Vect vect1( v1.x, v1.y, v1.z ); Vect vect2( v2.x, v2.y, v2.z ); Vect a = vect2 - vect0; Vect b = vect1 - vect0; Vect normal( v0.nx, v0.ny, v0.nz ); return a.cross( b ).dot( normal ); }
void ShiftVec<T>::shiftRight(int offset){ // Prepare a new vector with the same size of the vector data // member for moving the elements. std::vector<T> vect2(vect.size()); // Move the elements from the data member to new vector, in // their appropriate position, after offset. for(int i=0; i<vect.size(); i++){ vect2.at((i+offset)% vect.size()) = vect.at(i); } // Copy the elements in the new vector back to the data member. vect = vect2; }
void m3math_test_object_t::test<3>() { LLMatrix3 llmat3_obj; LLVector3 vect1(2, 1, 4); LLVector3 vect2(3, 5, 7); LLVector3 vect3(6, 9, 7); llmat3_obj.setRows(vect1, vect2, vect3); ensure("LLVector3::setRows failed ", 2 == llmat3_obj.mMatrix[0][0] && 1 == llmat3_obj.mMatrix[0][1] && 4 == llmat3_obj.mMatrix[0][2] && 3 == llmat3_obj.mMatrix[1][0] && 5 == llmat3_obj.mMatrix[1][1] && 7 == llmat3_obj.mMatrix[1][2] && 6 == llmat3_obj.mMatrix[2][0] && 9 == llmat3_obj.mMatrix[2][1] && 7 == llmat3_obj.mMatrix[2][2]); }
void llquat_test_object_t::test<3>() { LLMatrix3 llmat; LLVector3 vect1(3.4028234660000000f , 234.56f, 4234.442234f); LLVector3 vect2(741.434f, 23.00034f, 6567.223423f); LLVector3 vect3(566.003034f, 12.98705f, 234.764423f); llmat.setRows(vect1, vect2, vect3); ensure("LLMatrix3::setRows fn failed.", 3.4028234660000000f == llmat.mMatrix[0][0] && 234.56f == llmat.mMatrix[0][1] && 4234.442234f == llmat.mMatrix[0][2] && 741.434f == llmat.mMatrix[1][0] && 23.00034f == llmat.mMatrix[1][1] && 6567.223423f == llmat.mMatrix[1][2] && 566.003034f == llmat.mMatrix[2][0] && 12.98705f == llmat.mMatrix[2][1] && 234.764423f == llmat.mMatrix[2][2]); }
void CompareTest::checkContainerEquality() { std::vector< double > vect1(20); std::vector< double > vect2(20); ::fwTools::random::fillContainer(0.0001, 10., vect1); vect2 = vect1; bool isEqual = ::fwMath::isContainerEqual(vect1, vect2); CPPUNIT_ASSERT_EQUAL(true, isEqual); ::boost::uint32_t seedVal = std::time(NULL); ::fwTools::random::fillContainer(0.000001, 0.000009, vect1, seedVal); ::fwTools::random::fillContainer(0.000001, 0.000009, vect2, ++seedVal); isEqual = ::fwMath::isContainerEqual(vect1, vect2); CPPUNIT_ASSERT_EQUAL(true, isEqual); isEqual = ::fwMath::isContainerEqual(vect1, vect2, 0.0000001f); CPPUNIT_ASSERT_EQUAL(false, isEqual); }
int main() { int a = 1; int b = 2; int i; cout << "Should see 1 2 3 4 5\n"; WCValOrderedVector<int> vect( 0 ); vect.exceptions( WCExcept::check_all ); test_except( vect.insert( a ), resize_required, "1" ); vect.exceptions( 0 ); for( i = 0; i < WCDEFAULT_VECTOR_RESIZE_GROW; i++ ){ vect.insert( a ); } vect.exceptions( WCExcept::check_all ); test_except( vect.insert( a ), resize_required, "2" ) WCValOrderedVector<int> vect2( 0, 4 ); vect2.exceptions( WCExcept::check_all ); test_except( vect2.insert( a ), resize_required, "3" ); vect2.exceptions( 0 ); for( i = 0; i < 4; i++ ){ vect2.insert( a ); } vect2.exceptions( WCExcept::check_all ); test_except( vect2.insert( a ), resize_required, "4" ); WCValOrderedVector<int> vect3( 4, 0 ); for( i = 0; i < 4; i++ ){ if( !vect3.insert( a ) ) cout << "insert failed\n"; } if( vect3.insert( a ) ) cout << "insert did not fail\n"; vect3.exceptions( WCExcept::check_all ); test_except( vect3.insert( a ), resize_required, "5" ); vect.clear(); vect2.clear(); vect3.clear(); return 0; }
void getMaxRectangle(u8* data, u8 val, int w, int h, vect2D* pos, vect2D* size) { int x; vect2D originb=vect2(0,0),cornerb=vect2(-1,-1); pile_struct p; initPile(&p); int* c=initCache(h); for(x=w-1;x>=0;x--) { int y, width=0; fillCache(c,data,val,w,h,x); for(y=0;y<=h;y++) { if(c[y]>width) { pushPile(vect2(y,width),&p); width=c[y]; }else if(c[y]<width) { int y0, w0; while(1) { vect2D v=popPile(&p); y0=v.x;w0=v.y; if(width*(y-y0)>area(originb,cornerb)) { originb=vect2(x,y0); cornerb=vect2(x+width-1,y-1); } width=w0; if(c[y]>=width)break; } width=c[y]; if(width)pushPile(vect2(y0,w0),&p); } } } if(c)free(c); *pos=originb; *size=vect2(cornerb.x-originb.x+1,cornerb.y-originb.y+1); }
Rototranslation2D::Rototranslation2D(const Eigen::Vector3d &vect) { Eigen::Vector2d vect2(vect[0], vect[1]); initRototranslation2D(Eigen::Rotation2D<double>(vect[2]),vect2); }
int main(int argc, char **argv) { bool fail = false; // // now create a domain and a modelbuilder // and build the model // FEM_ObjectBroker theBroker; Domain *theDomain = new Domain(); FileDatastore *theDatabase = new FileDatastore("/tmp/database/test1",*theDomain,theBroker); FileDatastore &theDb = *theDatabase; opserr << "TESTING IDs: \n"; ID id1(2); id1(0) = 1; id1(1) = 1; ID id0(2); id0(0) = 0; id0(1) = 0; ID id2(2); id2(0) = 2; id2(1) = 2; ID id3(2); id3(0) = 3; id3(1) = 3; ID id4(2); id4(0) = 4; id4(1) = 4; ID id5(2); id5(0) = 5; id5(1) = 5; ID id6(2); id6(0) = 6; id6(1) = 6; theDb.sendID(1,1,id1); theDb.sendID(1,2,id2); theDb.sendID(2,1,id3); theDb.sendID(2,2,id4); opserr << "RESULTS\n"; ID recvID(2); theDb.recvID(1,1,recvID); opserr << "1: " << recvID; theDb.recvID(1,2,recvID); opserr << "2: " << recvID; theDb.recvID(2,1,recvID); opserr << "3: " << recvID; theDb.recvID(2,2,recvID); opserr << "4: " << recvID; theDb.sendID(1,1,id1); theDb.sendID(3,1,id3); theDb.sendID(2,1,id2); theDb.sendID(0,1,id0); theDb.sendID(1,2,id1); theDb.sendID(2,2,id2); theDb.sendID(3,1,id3); theDb.sendID(5,1,id5); theDb.sendID(4,1,id4); theDb.sendID(1,1,id1); theDb.recvID(3,1,id5); opserr << "3: " << id5; theDb.recvID(1,1,id5); opserr << "1: " << id5; theDb.recvID(2,1,id5); opserr << "2: " << id5; theDb.recvID(1,2,id5); opserr << "1: " << id5; theDb.recvID(2,2,id5); opserr << "3: " << id5; theDb.recvID(3,1,id5); opserr << "3: " << id5; theDb.recvID(4,1,id5); opserr << "4: " << id5; theDb.recvID(5,1,id5); opserr << "5: " << id5; opserr << "FAILURE: " << theDb.recvID(6,1,id5) << " returned\n"; opserr << "FAILURE " << theDb.recvID(6,1,id5) << " returned\n"; theDb.recvID(0,1,id5); opserr << "0: " << id5; theDb.recvID(5,1,id5); opserr << "5: " << id5; ID id64(4); id64(0) = 6; id64(1) = 6; id64(2) = 6; id64(3) = 6; theDb.sendID(6,1,id64); theDb.recvID(6,1,id64); opserr << id64; opserr << "TESTING MATRICES: \n"; Matrix mat1(2,2); mat1(0,0) = 1.1; mat1(0,1) = 11.1; mat1(1,0) = 111.1; mat1(1,1) = 1111.1; Matrix mat2(2,2); mat2(0,0) = 2.2; mat2(0,1) = 22.2; mat2(1,0) = 222.2; mat2(1,1) = 2222.2; theDb.sendMatrix(2,1,mat2); theDb.sendMatrix(1,1,mat1); theDb.sendMatrix(3,2,mat2); theDb.sendMatrix(3,1,mat1); Matrix mat3(2,2); theDb.recvMatrix(1,1,mat3); opserr << mat1 << mat3 << endln; theDb.recvMatrix(2,1,mat3); opserr << mat2 << mat3 << endln; theDb.recvMatrix(3,2,mat3); opserr << mat2 << mat3 << endln; theDb.recvMatrix(3,1,mat3); opserr << mat1 << mat3 << endln; // theDb.sendMatrix(2,1,mat1); theDb.recvMatrix(2,1,mat3); opserr << mat2 << mat3; opserr << "TESTING VECTORS: \n"; Vector vect1(2); vect1(0) = 1.1; vect1(1) = 2.22; Vector vect2(2); vect2(0) = 3; vect2(1) = 4.2; Vector vect3(2); vect3(0) = 5; vect3(1) = 6; Vector vect4(2); vect4(0) = 7; vect4(1) = 8.8e12; theDb.sendVector(1,1,vect1); theDb.sendVector(1,2,vect2); theDb.sendVector(2,1,vect3); theDb.sendVector(2,2,vect4); opserr << "RESULTS\n"; Vector vect5(2); theDb.recvVector(1,1,vect5); opserr << vect1 << vect5 << endln; theDb.recvVector(1,2,vect5); opserr << vect2 << vect5 << endln; theDb.recvVector(2,1,vect5); opserr << vect3 << vect5 << endln; theDb.recvVector(2,2,vect5); opserr << vect4 << vect5 << endln; theDb.sendVector(2,2,vect1); theDb.sendVector(2,1,vect2); theDb.sendVector(1,2,vect3); theDb.sendVector(1,1,vect4); theDb.recvVector(1,1,vect5); opserr << vect4 << vect5 << endln; theDb.recvVector(1,2,vect5); opserr << vect3 << vect5 << endln; theDb.recvVector(2,1,vect5); opserr << vect2 << vect5 << endln; theDb.recvVector(2,2,vect5); opserr << vect1 << vect5 << endln; theDb.sendVector(4,4,vect5); theDb.recvVector(4,4,vect5); opserr << vect5 << vect5 << endln; theDb.recvVector(5,5,vect5); opserr << "FAIL\n"; theDatabase->commitState(0); /* */ /* theDb.sendID(2,2,id1); theDb.sendID(2,1,id2); theDb.sendID(1,2,id3); theDb.sendID(1,1,id4); theDb.recvID(1,1,id5); opserr << id5; theDb.recvID(1,2,id5); opserr << id5; theDb.recvID(2,1,id5); opserr << id5; theDb.recvID(2,2,id5); opserr << id5; theDb.sendID(4,4,id5); theDb.recvID(4,4,id5); opserr << id5; theDb.recvID(5,5,id5); opserr << id5; */ /************************** **************************/ /* */ // theModelBuilder->buildFE_Model(); // theDb.commitState(0); // theDb.restoreState(0); // theDb.restoreElements(0); /* theDb.restoreNode(1,0); theDb.restoreNode(2,0); theDb.restoreNode(3,0); theDb.restoreNode(4,0); theDb.restoreElement(0,0); theDb.restoreElement(1,0); theDb.restoreElement(2,0); */ // opserr << *theDomain; delete theDatabase; exit(0); }
int main () { // Test with integers. int myints[] = { 75, 23, 65, 42, 13 }; MyList<int> lst(myints, (myints + 5)); MyVector<int> vect(myints, (myints + 5)); MyCollection<int>* p1 = &vect; MyCollection<int>* p2 = &lst; cout << "Start of integer vector: " << vect.starting_element() << endl; cout << "End of integer vector: " << vect.last_element() << endl; cout << "Integer vector[3]: " << vect.value_at_position(3) << endl; cout << "Integer vector contains the following elements: " << endl; vect.show_all(); cout << endl; cout << "Start of integer list: " << lst.starting_element() << endl; cout << "End of integer list: " << lst.last_element() << endl; cout << "Integer list(3): " << lst.value_at_position(3) << endl; cout << "Integer list contains the following elements: " << endl; lst.show_all(); cout << endl; cout << "Start of integer (collection) vector: " << p1->starting_element() << endl; cout << "End of integer (collection) vector: " << p1->last_element() << endl; cout << "Integer (collection) vector[3]: " << p1->value_at_position(3) << endl; cout << "Integer (collection) vector contains the following elements: " << endl; p1->show_all(); cout << endl; cout << "Start of integer (collection) list: " << p2->starting_element() << endl; cout << "End of integer (collection) list: " << p2->last_element() << endl; cout << "Integer (collection) list(3): " << p2->value_at_position(3) << endl; cout << "Integer (collection) list contains the following elements: " << endl; p2->show_all(); cout << endl; // Test with doubles. double mydoubles[] = { 7.0, 42.0, 13.0, 1.0, 2.0, 5.0 }; MyVector<double> vect2(mydoubles, (mydoubles + 6)); MyList<double> lst2(mydoubles, (mydoubles + 6)); MyCollection<double>* p3 = &vect2; MyCollection<double>* p4 = &lst2; cout << "Start of double vector: " << p3->starting_element() << endl; cout << "End of double vector: " << p3->last_element() << endl; cout << "Double vector[3]: " << p3->value_at_position(3) << endl; cout << "Double vector contains the following elements: " << endl; p3->show_all(); cout << endl; cout << "Start of double list: " << p4->starting_element() << endl; cout << "End of double list: " << p4->last_element() << endl; cout << "Double list(3): " << p4->value_at_position(3) << endl; cout << "Double list contains the following elements: " << endl; p4->show_all(); cout << endl; // Test with floats. float myfloats[] = { 57.123, 32.567, 56.8, 31.99535 }; MyList<float> lst3(myfloats, myfloats+4); MyVector<float> vect3(myfloats, myfloats+5); MyCollection<float>* p5 = &vect3; MyCollection<float>* p6 = &lst3; cout << "Start of float vector: " << p5->starting_element() << endl; cout << "End of float vector: " << p5->last_element() << endl; cout << "Float vector[3]: " << p5->value_at_position(3) << endl; cout << "Float vector contains the following elements: " << endl; p5->show_all(); cout << endl; cout << "Start of float list: " << p6->starting_element() << endl; cout << "End of float list: " << p6->last_element() << endl; cout << "Float list(3): " << p6->value_at_position(3) << endl; cout << "Float list contains the following elements: " << endl; p6->show_all(); cout << endl; return 0; }