void MatingGearConstructor::constructMatingGear() { m_module = 2.0f * m_originalRadius / m_originalToothProfile->getNumberOfTeeth(); m_matingRadius = m_module * m_matingNTeeth / 2.0f; m_distanceOfCenters = m_originalRadius + m_matingRadius; m_originalGearCurve = new BSplineCurve<hpvec2>; m_originalToothProfile->extendToGearCurve(*m_originalGearCurve); m_originalToothCurve = new BSplineCurve<hpvec2>; m_originalToothProfile->getCurve(*m_originalToothCurve); m_originalToothCurve->getParameterRange(m_startKnots, m_stopKnots); m_stepSize = (m_stopKnots - m_startKnots) / (m_samplingRate - 1); for(hpuint i = 0; i < m_originalToothProfile->getNumberOfTeeth(); ++i) { m_angularPitchKnots.push_back(i * (m_stopKnots - m_startKnots)); } hpvec2 originGearStart = getValueAt(m_startKnots); hpvec2 originGearStop = getValueAt(m_stopKnots); bool originGearTurnsClockwise = originGearStart.x * originGearStop.y - originGearStart.y * originGearStop.x < 0; hpreal matingTurnDirection = originGearTurnsClockwise ? 1.0f : -1.0f; //mating gear turns the other way round! m_allMatingPoints = MatingPointSelector(m_matingNTeeth, matingTurnDirection); constructListsOfPossibleMatingPoints(); chooseSuitableMatingPointsForGear(); }
void Widget::on_calcularSumaDeMatricesPushButton_clicked() { const int rowCount = mModelA->rowCount(); const int colCount = mModelA->columnCount(); mModelResultado->setRowCount(rowCount); mModelResultado->setColumnCount(colCount); for (int ix = 0; ix < rowCount; ++ix) { for (int jx = 0; jx < colCount; ++jx) { const double aij = getValueAt(mModelA, ix, jx); const double bij = getValueAt(mModelB, ix, jx); const double rij = aij + bij; mModelResultado->setItem(ix, jx, new QStandardItem(QString::number(rij))); } } }
bool ABSymCurve::getVelocity(double *buff, double time) { for (int i = 0; i < getCard(); i++) { buff[i] = getValueAt(i, time, 1); } return true; }
bool ABSymCurve::getAcceleration(double *buff, double time) { for (int i = 0; i < getCard(); i++) { buff[i] = getValueAt(i, time, 2); } return true; }
/** * METODA TESTOWA. Wyświetla siatkę danych. */ void SDataGrid::__dev__printConsole(int ptr_x, int ptr_y) { ptr_y = 0; std::cout << "dane: "; for(int x = 0; x < max_index + 1; x++) { if (ptr_x == x) std::cout << '<' << getValueAt(x, ptr_y) << '>'; else std::cout << /*'[' <<*/ getValueAt(x, ptr_y) /*<< ']'*/; std::cout << ' '; } if (ptr_x > max_index) { std::cout << "<?>"; } }
/**************************************************************************** * Print the values of matrix in a table form. You must use "getValueAt" * * function to retrieve matrix elements. * ***************************************************************************/ void print(Matrix *m) { for (int i = 0; i < m->rows; i++) { for (int j = 0; j < m->columns; j++) { printf("%d ", getValueAt(m,i,j)); } printf("\n"); } }
float Octave::getValueAt(float x, float y) { float f_dimension = (float)dimension; int x_i = (int)(f_dimension*x); int y_i = (int)(f_dimension*y); float x_r = x*dimension -(float)x_i; float y_r = y*dimension - (float)y_i; float x0y0 = getValueAt(x_i, y_i); float x1y1 = getValueAt(x_i+1, y_i+1); float x0y1 = getValueAt(x_i, y_i+1); float x1y0 = getValueAt(x_i+1, y_i); return ( (1-x_r)*interpolation(x0y0, x0y1, y_r) + x_r*interpolation(x1y0, x1y1, y_r) + (1-y_r)*interpolation(x0y0, x1y0, x_r) + y_r*interpolation(x0y1, x1y1, x_r) )*0.5; }
int X3DFIAttributes::getSFInt32(int index) const { std::vector<int> result; getIntArray(getValueAt(index), result); if (result.size() == 1) { return result[0]; } else throw X3DParseException("Wrong size for SFInt32"); }
void X3DFIAttributes::getSFImage(int index, SFImage& value) const { MFInt32 signedVector; SFImage result; getIntArray(getValueAt(index), signedVector); for(MFInt32::const_iterator I = signedVector.begin(); I != signedVector.end(); I++) { result.push_back(static_cast<unsigned int>(*I)); } std::swap(result, value); }
void X3DFIAttributes::getSFVec2f(int index, SFVec2f &value) const { std::vector<float> result; getFloatArray(getValueAt(index), result); if (result.size() == 2) { value.x = result[0]; value.y = result[1]; } else throw X3DParseException("Wrong size for SFVec2f"); }
bool CTdata::getMinMaxForCell(int x, int y, int z, float *maxV, float *minV) { if ((x+1)>=dimX || (y+1)>=dimY || (z+1)>=dimZ){ // bad index... return false; } *minV = FLT_MAX; *maxV = -FLT_MAX; int i,j,k; for (k=0; k<2; k++){ for (j=0; j<2; j++){ for (i=0; i<2; i++){ *minV = min(*minV, getValueAt(x+i, y+j, z+k)); *maxV = max(*maxV, getValueAt(x+i, y+j, z+k)); } } } return true; }
// Single fields bool X3DFIAttributes::getSFBool(int index) const{ FI::NonIdentifyingStringOrIndex value = getValueAt(index); if(value._stringIndex == X3DParserVocabulary::ATTRIBUT_VALUE_TRUE_INDEX) return true; if(value._stringIndex == X3DParserVocabulary::ATTRIBUT_VALUE_FALSE_INDEX) return false; if(value._stringIndex == FI::INDEX_NOT_SET) return X3DDataTypeFactory::getSFBoolFromString(_impl->_vocab->resolveAttributeValue(value)); throw X3DParseException("Unknown SFBool encoding"); }
/**************************************************************************** * If the input matrices are compatible, then multiplies the input matrices * * and returns a pointer to the result matrix. Use create(), getValueAt(), * * and setValueAt() functions to implement this function. * * * * * If the input matrices are not compatible, return NULL. * * DO NOT modify the input matrices. * * ***************************************************************************/ Matrix *multiply(Matrix *m1, Matrix *m2) { Matrix *result = NULL; if(m1->rows == m2->rows && m1->columns == m2->columns) { result = create(m1->rows, m1->columns); for(int row = 0; row < m1->rows; row++) { for(int col = 0; col < m1->columns; col++) { //printf("1. Row: %d Col: %d\n", row, col); int value = (getValueAt(m1, row,col) * getValueAt(m2,row,col)); //printf("2. Row: %d Col: %d\n", row, col); setValueAt(result, row, col, value); } } } return result; }
/**************************************************************************** * If the input matrices are compatible, then performs matrix subtraction * * and returns a pointer to the result matrix. * * Use create(), getValueAt(), and setValueAt() functions to implement this * * function. If the input matrices are not compatible, return NULL. * * DO NOT modify the input matrices. * ***************************************************************************/ Matrix *subtract(Matrix *m1, Matrix *m2) { Matrix *result = NULL; // TO DO if(m1->rows == m2->rows && m1->columns == m2->columns) { result = create(m1->rows, m1->columns); for(int row = 0; row < m1->rows; row++) { for(int col = 0; col < m1->columns; col++) { setValueAt(result, row, col, (getValueAt(m1, row,col) - getValueAt(m2,row,col))); } } } return result; }
void X3DFIAttributes::getSFColor(int index, SFColor &value) const { std::vector<float> result; getFloatArray(getValueAt(index), result); if (result.size() == 3) { value.r = result[0]; value.g = result[1]; value.b = result[2]; } else throw X3DParseException("Wrong size for SFColor"); }
void X3DFIAttributes::getSFRotation(int index, SFRotation &value) const { std::vector<float> result; getFloatArray(getValueAt(index), result); if (result.size() == 4) { value.x = result[0]; value.y = result[1]; value.z = result[2]; value.angle = result[3]; } else throw X3DParseException("Wrong size for SFRotation"); }
void CJHTreeNode::dump() { for (unsigned int i=0; i<getNumKeys(); i++) { unsigned char *dst = (unsigned char *) alloca(keyLen+50); getValueAt(i,(char *) dst); offset_t pos = getFPosAt(i); StringBuffer nodeval; for (unsigned j = 0; j < keyLen; j++) nodeval.appendf("%02x", dst[j] & 0xff); DBGLOG("keyVal %d [%" I64F "d] = %s", i, pos, nodeval.str()); } DBGLOG("=========="); }
int main(){ // Ver http://www.webcid.com.br/?pg=calendario&ano=1999 Element * setembro1999 = makeArray(31); Dia diaNormal; diaNormal.feriado = false; diaNormal.lua = 0; for(int i=1; i<=30; i++){ setValueAt(setembro1999, i, diaNormal); } Dia diaDaIndependencia; diaNormal.feriado = true; setValueAt(setembro1999, 7, diaDaIndependencia); Dia diaDeLua; diaDeLua.lua = 3; // 2/7 lua crescente setValueAt(setembro1999, 2, diaDeLua); diaDeLua.lua = 3; // 10/7 lua cheia setValueAt(setembro1999, 10, diaDeLua); diaDeLua.lua = 4; // 17/7 lua minguante setValueAt(setembro1999, 17, diaDeLua); diaDeLua.lua = 1; // 24/7 lua nova setValueAt(setembro1999, 24, diaDeLua); Dia dia = getValueAt(setembro1999, 7); assert(dia.feriado); dia = getValueAt(setembro1999, 10); assert(dia.lua == 3); Dia dia9_9_99 = getValueAt(setembro1999, 9); assert(!dia9_9_99.feriado); }
/**************************************************************************** * Creates the transpose matrix of the input matrix and returns a pointer * * to the result matrix. Use create(), getValueAt(), and setValueAt() * * functions to implement this function. * * DO NOT modify the input matrix. * ***************************************************************************/ Matrix *transpose(Matrix *m) { Matrix *result = NULL; // TO DO result = create(m->columns, m->rows); for(int row = 0; row < m->rows; row++) { for(int col = 0; col < m->columns; col++) { setValueAt(result,col,row,getValueAt(m, row, col)); } } return result; }
/**************************************************************************** * Creates a matrix that is the product of the given scalar value and * * the input matrix and returns a pointer to the result matrix. * * Use create(), getValueAt(), and setValueAt() functions to implement * * this function. * * DO NOT modify the input matrix. * ***************************************************************************/ Matrix *scalarMultiply(Matrix *m, int scalar) { Matrix *result = NULL; // TO DO result = create(m->rows, m->columns); for(int row = 0; row < m->rows; row++) { for(int col = 0; col < m->columns; col++) { setValueAt(result,row,col,scalar*getValueAt(m,row,col)); } } return result; }
void X3DFIAttributes::getMFColorRGBA(int index, MFColorRGBA &value) const { std::vector<float> fArray; getFloatArray(getValueAt(index), fArray); if (fArray.size() % 4 == 0) { float* pPos = &fArray.front(); MFColorRGBA result; for(size_t i = 0; i < fArray.size() / 4; i++, pPos+=4) { SFColorRGBA c(pPos); result.push_back(c); } std::swap(result, value); } else throw X3DParseException("Wrong size for MFColorRGBA"); }
void Game::printBoardState(bool printTetramino) { for (int row = 0; row < 22; row++) { for (int col = 0; col < 10; col++) { char current = getValueAt(row, col); current = printTetramino ? getMovingTetra(row, col, current) : current; std::cout << current << ' '; } std::cout << std::endl; } if (gameOver) { std::cout << "Game Over" << std::endl; } }
// // Returns the trilinear interpolated identifier-specified value // float Grid::getValueAt( float x, float y, float z, std::string valueIdentifier ) { // find the valueIndex from identifier ----------------------- // we assume that all cells have the same value layout so we can take the valueindex from any // cells and it is valid for all other cells too // if there is no cell if( grid.empty() ) // then we can skip everything return 0.0f; // we have at least one cell - this cell will be used to find the valueIndex from the valueidentifier size_t valueIndex = grid.front().getValueIndex( valueIdentifier ); // redirect to getGridValueAt with valueindex return getValueAt( x, y, z, valueIndex ); }
void CJHVarTreeNode::dump() { for (unsigned int i=0; i<getNumKeys(); i++) { const void * p = recArray[i]; unsigned reclen = ((KEYRECSIZE_T *) p)[-1]; _WINREV(reclen); unsigned char *dst = (unsigned char *) alloca(reclen); getValueAt(i,(char *) dst); offset_t pos = getFPosAt(i); StringBuffer nodeval; for (unsigned j = 0; j < reclen; j++) nodeval.appendf("%02x", dst[j] & 0xff); DBGLOG("keyVal %d [%" I64F "d] = %s", i, pos, nodeval.str()); } DBGLOG("=========="); }
/** * @brief Update channel to specified time. */ void updateTarget(Milliseconds time, Channel::Target target) override { auto it = _keyFrames.begin(); auto itPrevious = it; while (it != _keyFrames.end() && it->getTime() < time) { itPrevious = it; ++it; } float t = 1; if (it == _keyFrames.end()) { it = itPrevious; } else { auto dt = time - itPrevious->getTime(); auto duration = it->getTime() - itPrevious->getTime(); t = static_cast<float>(dt.count()) / static_cast<float>(duration.count()); t = std::max(0.0f, std::min(1.0f, t)); } Update(itPrevious->getValueAt(*it, t), _propertyPath, target); }
void * sendMoyenneCoordinateur(void * pData) { MySocket sock = *((MySocket *)pData); // Recuperation de la socket while(1) { MySleep(1000); // reduit la consomation CPU // printf("Calcul des moyennes ! \n"); int nbSondes = LengthListe(ListeSondes); int i = 0; while(i < nbSondes) { TypeSondeR * Sonde = getValueAt(ListeSondes,i); if(Sonde->cptVal > 0) // Si on à reçu une nouvelle mesure { float MoyenneSonde = Sonde->tempSonde / Sonde->cptVal; Sonde->tempSonde = 0; Sonde->cptVal = 0; printf("Moyenne pour la sonde %i : %f | Envoi -> ",Sonde->idSonde,MoyenneSonde); char buffer[80]; sprintf(buffer,"M,%i,%i,%f,E",g_Config.idRouteur,Sonde->idSonde,MoyenneSonde); int ret = sendUdpMessageTo(sock , buffer , g_Config.ipCoordinateur , g_Config.portCoordinateur ); if(ret == -1) { printf(" Erreur lors de l'envoi du message ! (%i)\n",ret); } else { printf(" OK \n"); } } i++; } } return NULL; }
Vertex& CTdata::getVertexAt(int x, int y, int z) { Position3i p; p.x = x; p.y = y; p.z = z; // is Vetrex allready precomputed in vertexMap? Vertex& v = vertexMap[p]; if (!v.isValid){ // not precomputed... compute now... //printf("vertex not precomputed...\n"); // position v.position = v3(x*scX, y*scY, z*scZ)-center; //printf("POS[ %f , %f , %f ]\n", v.position.x, v.position.y, v.position.z); // normal int i; float nx, ny, nz; for (i=1; v.normal.length()<=100.0; i++){ nx = getValueAt2(x-i, y, z) - getValueAt2(x+i, y, z); ny = getValueAt2(x, y-i, z) - getValueAt2(x, y+i, z); nz = getValueAt2(x, y, z-i) - getValueAt2(x, y, z+i); v.normal = v3(nx, ny, nz); } //v.normal.normalize(); // value v.value = getValueAt(x,y,z); // validate v.isValid = true; } else { //printf("Vertex PRECOMP!!\n"); } return v; }
bool MrgSorter::sort ( // No params ) { int index; DateType check; sortGood = true; for( index = 0; index < this->getSize(); index++ ) { getValueAt( index, check ); if( !isDateValid( check ) ) { sortGood = false; return sortGood; } } mergeSort( 0, this->getSize() - 1 ); return sortGood; }
void MatingGearConstructor::constructListsOfPossibleMatingPoints() { hpvec2 nextPoint = getValueAt(m_startKnots); hpvec2 nextNormal = getNormalAt(m_startKnots); hpreal radToDegree = 180.0f / M_PI; for(hpuint sampleStep = 1; sampleStep < m_samplingRate; ++sampleStep) { hpvec2 point = nextPoint; hpvec2 normal = nextNormal; nextPoint = getValueAt(m_startKnots + sampleStep * m_stepSize); nextNormal = getNormalAt(m_startKnots + sampleStep * m_stepSize); MatingPoint matingPoint = getMatingPointOf(point, normal); m_allMatingPoints.push_back(matingPoint); hpreal normalAngleDiff = std::abs(asin(normal.x * nextNormal.y - normal.y * nextNormal.x)); hpreal direction = (normal.x * nextNormal.y > normal.y * nextNormal.x) ? 1.0f : -1.0f; if(normalAngleDiff > m_maxDiffAngle) { hpuint nPartitions = static_cast<hpuint>(normalAngleDiff / m_maxDiffAngle); hpvec2 pointDiff = nextPoint - point; for(hpuint partition = 1; partition <= nPartitions; ++partition) { hpvec2 partitionPoint = point + pointDiff * static_cast<hpreal> (partition / nPartitions); hpvec2 partitionNormal = glm::rotate(normal, m_maxDiffAngle * direction * partition * radToDegree); MatingPoint matingPoint = getMatingPointOf(partitionPoint, partitionNormal); m_allMatingPoints.push_back(matingPoint); } } } //Go again through all collected points and look at the the intersection point on the reference radius. //If two following points differ too much, insert again mating points to get around this inaccuracy. //Remark: As the relation of the angle in the reference circle and the angle of the normal difference isn't //used here, no guarantee exists, that consecutive mating points have at least an angle of m_maxDiffAngle //viewed in the reference circle. // for(std::list<MatingPoint>::iterator it = m_allMatingPoints.begin(), nextIt = ++(m_allMatingPoints.begin()); nextIt != m_allMatingPoints.end(); ++it, ++nextIt) { // if(it->error == ErrorCode::NO_ERROR) { // hpvec2 point = it->point; // hpvec2 normal = it->normal; // hpvec2 nextPoint = nextIt->point; // hpvec2 nextNormal = nextIt->normal; // hpreal angleDiff = nextIt->intersectionRefRadiusAngle - it->intersectionRefRadiusAngle; // if(angleDiff > m_maxDiffAngle) { // cerr << " refA.>maxAngle" << endl; // hpuint nPartitions = static_cast<hpuint>(std::abs(angleDiff) / m_maxDiffAngle); // hpvec2 pointDiff = nextPoint - point; // hpreal areaBetween = normal.x * nextNormal.y - normal.y * nextNormal.x; // hpreal angleBetweenNormals = asin(areaBetween); //angleA is negative or positive, depending on the normals // hpreal turnAnglePerStep = angleBetweenNormals / nPartitions; // for(hpuint partition = 1; partition <= nPartitions; ++partition) { // hpvec2 partitionPoint = point + pointDiff * static_cast<hpreal>(partition / nPartitions); // hpvec2 partitionNormal = glm::rotate(normal, turnAnglePerStep * partition * radToDegree); // MatingPoint matingPoint = getMatingPointOf(partitionPoint, partitionNormal); // m_allMatingPoints.insert(nextIt, matingPoint); // cerr << "refA.> mating point created" << endl; // ++it; // } // } // } // } }
/* Assuming the 2 stops have been set already. We want to shift the angles to put zero at the Value passed in. */ word Motor::getZeroOffset( word mValueAtZeroDegrees ) { return getValueAt( 0.0 ); }