本文整理汇总了C++中SparseMat::get方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMat::get方法的具体用法?C++ SparseMat::get怎么用?C++ SparseMat::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMat
的用法示例。
在下文中一共展示了SparseMat::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
{ // Test lower_bound and min_max
using jcui::algorithm::lower_bound;
using jcui::algorithm::min_max;
{
int xa[] = {};
int ya[] = {};
vector<int> x(xa, xa + ARRAYSIZE(xa)), y(ya, ya + ARRAYSIZE(ya));
int index = lower_bound(x.begin(), x.end(), y.begin(), y.end(), less<int>()) - x.begin();
eq(0, index, 0);
eq(0, min_max(x.begin(), x.end(), y.begin(), y.end(), 0), 0);
}
{
int xa[] = {3, 4, 5, 6};
int ya[] = {5, 4, 3, 1};
vector<int> x(xa, xa + ARRAYSIZE(xa)), y(ya, ya + ARRAYSIZE(ya));
int index = lower_bound(x.begin(), x.end(), y.begin(), y.end(), less<int>()) - x.begin();
eq(1, index, 1);
eq(1, min_max(x.begin(), x.end(), y.begin(), y.end(), 0), 4);
}
{
int xa[] = {3, 3, 5, 6};
int ya[] = {5, 4, 3, 1};
vector<int> x(xa, xa + ARRAYSIZE(xa)), y(ya, ya + ARRAYSIZE(ya));
int index = lower_bound(x.begin(), x.end(), y.begin(), y.end(), less<int>()) - x.begin();
eq(2, index, 2);
eq(2, min_max(x.begin(), x.end(), y.begin(), y.end(), 0), 4);
}
{
int xa[] = {13, 14, 15, 16};
int ya[] = {5, 4, 3, 1};
vector<int> x(xa, xa + ARRAYSIZE(xa)), y(ya, ya + ARRAYSIZE(ya));
int index = lower_bound(x.begin(), x.end(), y.begin(), y.end(), less<int>()) - x.begin();
eq(3, index, 0);
eq(3, min_max(x.begin(), x.end(), y.begin(), y.end(), 0), 13);
}
{
int xa[] = {3, 4, 5, 6};
int ya[] = {15, 14, 13, 11};
vector<int> x(xa, xa + ARRAYSIZE(xa)), y(ya, ya + ARRAYSIZE(ya));
int index = lower_bound(x.begin(), x.end(), y.begin(), y.end(), less<int>()) - x.begin();
eq(4, index, 4);
eq(4, min_max(x.begin(), x.end(), y.begin(), y.end(), 0), 11);
}
}
{ // For SparseMat
using jcui::algorithm::SparseMat;
{
SparseMat<int> a(100, 100), b(100, 100);
SparseMat<int> c = a * b;
eq(c.get(3, 10), 0);
eq(c.get(0, 0), 0);
}
{
// a = [1, 2; 3, 0], b = [6, 0, 0; 0, 1, 4], a * b = [6, 2, 8; 18, 0, 0]
SparseMat<int> a(100, 100), b(100, 100);
a.set(0, 0, 1);
a.set(0, 1, 2);
a.set(1, 0, 3);
b.set(0, 0, 6);
b.set(1, 1, 1);
b.set(1, 2, 4);
SparseMat<int> c = a * b;
eq(c.get(0, 0), 6);
eq(c.get(0, 1), 2);
eq(c.get(0, 2), 8);
eq(c.get(1, 0), 18);
eq(c.get(1, 1), 0);
eq(c.get(1, 2), 0);
}
{
// a = [1, 2; 3, 0]
SparseMat<long> a(100, 100);
a.set(0, 0, 1);
a.set(0, 1, 2);
a.set(1, 0, 3);
SparseMat<long> c = pow(a, 17);
eq(c.get(0, 0), 77431669L);
eq(c.get(0, 1), 51708494L);
eq(c.get(1, 0), 77562741L);
eq(c.get(1, 1), 51577422L);
}
{
// a = [1, 2; 3, 0]
int N = 10;
SparseMat<float> a(N, N);
for (int i = 0; i < N; ++i) {
a.set(i, i, 0.9f);
a.set(i, (i + 1) % N, 0.05f);
a.set(i, (i + N - 1) % N, 0.05f);
}
SparseMat<float> c = pow(a, 20000);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
eq(fabs(c.get(i, j) - 0.1f) < 1e-3f, true);
}
}
}
{
//.........这里部分代码省略.........
示例2: computeConstraintsANDJacobian
void IterativeImpulseBasedConstraintSolverStrategy::computeConstraintsANDJacobian(std::vector<std::unique_ptr<IConstraint> >& c, const Mat<float>& q, const Mat<float>& qdot, const SparseMat<float>& invM)
{
//-------------------------------------
//-------------------------------------
//-------------------------------------
size_t size = c.size();
int n = sim->simulatedObjects.size();
float baumgarteBAS = 0.0f;//1e-1f;
float baumgarteC = -2e0f;
float baumgarteH = 0.0f;//1e-1f;
//---------------
// RESETTING :
constraintsC.clear();
constraintsJacobians.clear();
constraintsOffsets.clear();
constraintsIndexes.clear();
constraintsInvM.clear();
constraintsV.clear();
//----------------------
if( size > 0)
{
for(int k=0;k<size;k++)
{
int idA = ( c[k]->rbA.getID() );
int idB = ( c[k]->rbB.getID() );
std::vector<int> indexes(2);
//indexes are set during the creation of the simulation and they begin at 0.
indexes[0] = idA;
indexes[1] = idB;
constraintsIndexes.push_back( indexes );
//---------------------------
//Constraint :
c[k]->computeJacobians();
Mat<float> tJA(c[k]->getJacobianA());
Mat<float> tJB(c[k]->getJacobianB());
Mat<float> tC(c[k]->getConstraint());
constraintsC.push_back( tC );
int nbrlineJ = tJA.getLine();
Mat<float> JacobianAB( operatorL(tJA, tJB) );
constraintsJacobians.push_back( JacobianAB );
//----------------------------------------
//BAUMGARTE STABILIZATION
//----------------------------------------
//Contact offset :
if( c[k]->getType() == CTContactConstraint)
{
//----------------------------------------
//SLOP METHOD :
/*
float slop = 1e0f;
float pdepth = ((ContactConstraint*)(c[k].get()))->penetrationDepth;
std::cout << " ITERATIVE SOLVER :: CONTACT : pDepth = " << pdepth << std::endl;
tC *= baumgarteC/this->dt * fabs_(fabs_(pdepth)-slop);
*/
//----------------------------------------
//----------------------------------------
//DEFAULT METHOD :
tC *= baumgarteC/this->dt;
//----------------------------------------
//----------------------------------------
//METHOD 2 :
/*
float restitFactor = ( (ContactConstraint*) (c[k].get()) )->getRestitutionFactor();
std::cout << " ITERATIVE SOLVER :: CONTACT : restitFactor = " << restitFactor << std::endl;
Mat<float> Vrel( ( (ContactConstraint*) (c[k].get()) )->getRelativeVelocity() );
Mat<float> normal( ( (ContactConstraint*) (c[k].get()) )->getNormalVector() );
std::cout << " ITERATIVE SOLVER :: CONTACT : Normal vector : " << std::endl;
transpose(normal).afficher();
tC += restitFactor * transpose(Vrel)*normal;
*/
//----------------------------------------
std::cout << " ITERATIVE SOLVER :: CONTACT : Contact Constraint : " << std::endl;
transpose(tC).afficher();
std::cout << " ITERATIVE SOLVER :: CONTACT : Relative Velocity vector : " << std::endl;
transpose(( (ContactConstraint*) (c[k].get()) )->getRelativeVelocity()).afficher();
//std::cout << " ITERATIVE SOLVER :: CONTACT : First derivative of Contact Constraint : " << std::endl;
//(transpose(tJA)*).afficher();
}
//BAS JOINT :
if( c[k]->getType() == CTBallAndSocketJoint)
{
tC *= baumgarteBAS/this->dt;
}
//.........这里部分代码省略.........